Exemple #1
0
 public PythonScriptedPostProcessor(IPostProcessorScript script, IPostProcessorsHolder target, PostProcessDefinition definition, IEnumerable <IBuilder> dependencies, IPostProcessorScriptRunner scriptRunner)
 {
     this.script       = script;
     this.target       = target;
     this.definition   = definition;
     this.scriptRunner = scriptRunner;
     this.dependencies = new HashSet <IBuilder>(dependencies);
 }
Exemple #2
0
 public IPostProcessor CreatePostProcessorFor(IPostProcessorsHolder holder, PostProcessDefinition definition, IEnumerable <IBuilder> dependencies)
 {
     if (scriptMappings.HasScriptFor(definition.PostProcessorId))
     {
         var script        = scriptMappings.GetScriptFor(definition.PostProcessorId);
         var postProcessor = new PythonScriptedPostProcessor(script, holder, definition, dependencies, scriptRunner);
         return(postProcessor);
     }
     else
     {
         return(null);
     }
 }
        public ISet <TargetRelativePath> Run(IPostProcessorsHolder target, PostProcessDefinition definition, IPostProcessorScript postProcessorScript)
        {
            var engine  = CreateEngine();
            var runtime = engine.Runtime;

            try
            {
                var scope = runtime.CreateScope();
                AddGetToolToScope(scope);

                var targetDir       = TargetRoot.GetChildDirectory(target.RelativeTargetPath, createIfMissing: true);
                var localTargetDir  = targetDir as LocalFileSystemDirectory;
                var localTargetRoot = TargetRoot as LocalFileSystemDirectory;
                if (localTargetDir != null && localTargetRoot != null)
                {
                    scope.SetVariable("targetRoot", localTargetRoot.AbsolutePath);
                    scope.SetVariable("targetDir", localTargetDir.AbsolutePath);
                    var pco = (PythonCompilerOptions)engine.GetCompilerOptions();
                    pco.Module |= ModuleOptions.Optimized;
                    var script = engine.CreateScriptSourceFromString(postProcessorScript.Source, SourceCodeKind.File);
                    script.Compile(pco);
                    script.Execute(scope);

                    return(new HashSet <TargetRelativePath>(
                               scope.GetVariable <IList <object> >("results")
                               .Cast <string>()
                               .Select(t => GetTargetRelativePath(targetDir, t))));
                }
                else
                {
                    throw new NotSupportedException("Only local file system is supported for python scripts!");
                }
            }
            finally
            {
                runtime.Shutdown();
            }
        }
Exemple #4
0
 public PythonScriptedPostProcessor CreatePythonScriptedPostProcessor(IPostProcessorScript script, IPostProcessorsHolder target,
                                                                      PostProcessDefinition definition, IEnumerable <IBuilder> dependencies)
 {
     return(store.Add(baseImpl.CreatePythonScriptedPostProcessor(script, target, definition, dependencies)));
 }
Exemple #5
0
        public ISet <TargetRelativePath> Run(IPostProcessorsHolder target, PostProcessDefinition definition, IPostProcessorScript postProcessorScript)
        {
            var engine  = CreateEngine();
            var runtime = engine.Runtime;

            try
            {
                var scope = runtime.CreateScope();
                AddGetToolToScope(scope);
                scope.SetVariable("is_mono", parameters.UseMono);

                var targetDir       = TargetRoot.GetChildDirectory(target.RelativeTargetPath, createIfMissing: true);
                var localTargetDir  = targetDir as LocalFileSystemDirectory;
                var localTargetRoot = TargetRoot as LocalFileSystemDirectory;
                if (localTargetDir != null && localTargetRoot != null)
                {
                    scope.SetVariable("targetRoot", localTargetRoot.AbsolutePath);
                    scope.SetVariable("targetDir", localTargetDir.AbsolutePath);
                    var pco = (PythonCompilerOptions)engine.GetCompilerOptions();
                    pco.Module |= ModuleOptions.Optimized;

                    try
                    {
                        var script = engine.CreateScriptSourceFromString(postProcessorScript.Source, SourceCodeKind.File);
                        script.Compile(pco);
                        script.Execute(scope);

                        return(new HashSet <TargetRelativePath>(
                                   scope.GetVariable <IList <object> >("results")
                                   .Cast <string>()
                                   .Select(t => GetTargetRelativePath(targetDir, t))));
                    }
                    catch (Exception ex)
                    {
                        var eo = engine.GetService <ExceptionOperations>();

                        string msg, typeName;
                        eo.GetExceptionMessage(ex, out msg, out typeName);

                        foreach (var line in msg.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            output.Error(line);
                        }

                        output.Error("Call stack:");
                        foreach (var frame in eo.GetStackFrames(ex))
                        {
                            var line   = frame.GetFileLineNumber();
                            var method = frame.GetMethodName();

                            output.Error(String.Format("Line {0} in {1}", line, method));
                        }

                        throw new ScriptException(postProcessorScript);
                    }
                }
                else
                {
                    throw new NotSupportedException("Only local file system is supported for python scripts!");
                }
            }
            finally
            {
                runtime.Shutdown();
            }
        }