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);
 }
 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;
     }
 }
Example #3
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);

                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();
            }
        }
Example #4
0
 /// <summary>
 /// Adds a new postprocessor to this project
 /// </summary>
 /// <param name="postProcessDefinition">Post processor type and parameters</param>
 public void AddPostProcessor(PostProcessDefinition postProcessDefinition)
 {
     postProcessDefinitions.Add(postProcessDefinition.Name, postProcessDefinition);
 }
Example #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();
            }
        }
 public PythonScriptedPostProcessor CreatePythonScriptedPostProcessor(IPostProcessorScript script, IPostProcessorsHolder target,
     PostProcessDefinition definition, IEnumerable<IBuilder> dependencies)
 {
     return store.Add(baseImpl.CreatePythonScriptedPostProcessor(script, target, definition, dependencies));
 }