示例#1
0
    void ExecuteCommand(string command)
    {
        if (input.wasCanceled)
        {
            input.ActivateInputField();
            return;
        }
        input.text = "";
        input.ActivateInputField();
        if (command.Length != 0)
        {
            m_previousCommands.Insert(0, command);
        }
        m_previousCommandSelected = -1;

        bool exception = false;

        try{
            PythonUtils.GetEngine().Execute(command, m_scope);
        }catch (Exception e) {
            exception = true;
//			Debug.LogException (e);
            write(e.Message);
        }

        text.text += "\n<b>" + (exception ? "<color=#d22>" : "") + command + (exception ?"</color=#f66>" : "") + "</b> ";
        text.text += log;
        log        = "";

        scroll.verticalNormalizedPosition = 0f;
    }
        public override object GetData(JsonParameter[] paramList)
        {
            string             pythonCode    = "";
            string             pythonFunc    = "Main";
            string             pythonFuncArg = "";
            List <PythonParam> pyParams      = new List <PythonParam>();

            foreach (var param in paramList)
            {
                switch (param.Key)
                {
                case "_py_code":
                    pythonCode = param.Value;
                    break;

                case "_py_func":
                    pythonFunc = param.Value;
                    break;

                case "_py_func_arg":
                    pythonFuncArg = param.Value;
                    break;

                default:
                    if (!string.IsNullOrEmpty(param.Key))
                    {
                        pyParams.Add(new PythonParam(param.Key, param.Value));
                    }
                    break;
                }
            }
            return(PythonUtils.CallFunc(pythonFunc, "", pyParams, pythonCode));
        }
    void RecreateScope()
    {
        m_scope = PythonUtils.GetEngine().CreateScope();
        m_scope.SetVariable("console", this);
        var fullScript = PythonUtils.defaultPythonConsoleHeader + GlobalAssemblyImport();

        PythonUtils.GetEngine().Execute(fullScript, m_scope);
    }
示例#4
0
 void InitScope()
 {
     if (m_scope == null)
     {
         m_scope = PythonUtils.GetEngine().CreateScope();
     }
     m_scope.SetVariable("owner", this);
     m_scope.SetVariable("gameObject", gameObject);
     m_scope.SetVariable("transform", transform);
     scopeInitializedWithScript = false;
 }
示例#5
0
		/*
		 # runs blobroot/monitor.py
		 # pull 48 hours of diagnostics from odata feed into a file
		 # run logparser queries against the file
		 # output charts (gifs) and/or tables (htmls) to charts container in azure storage
		 # calls blobroot/dashboard.py to update pages that include charts and tables  
		*/
		public static void MonitorAdmin(object o, ElapsedEventArgs args)
		{
			GenUtils.LogMsg("status", "MonitorAdmin", null);
			try
			{
				PythonUtils.RunIronPython(local_storage_path, CalendarAggregator.Configurator.monitor_script_url, new List<string>() { "", "", "" });
			}
			catch (Exception e)
			{
				GenUtils.LogMsg("exception", "MonitorAdmin", e.Message + e.StackTrace);
			}
		}
示例#6
0
		// runs _admin.py from blobroot/admin, most duties have migrated out of python and into c#
		public static void IronPythonAdmin(object o, ElapsedEventArgs e)
		{
			try
			{
				GenUtils.LogMsg("status", "IronPythonAdmin", null);
				PythonUtils.RunIronPython(local_storage_path, CalendarAggregator.Configurator.iron_python_admin_script_url, new List<string>() { "", "", "" });

			}
			catch (Exception ex)
			{
				GenUtils.LogMsg("exception", "IronPythonAdmin", ex.Message + ex.StackTrace);
			}
		}
示例#7
0
 public static void MakeTablesAndCharts(Object o, ElapsedEventArgs e)
 {
     GenUtils.LogMsg("status", "MakeTablesAndCharts", null);
     try
     {
         PythonUtils.RunIronPython(WebRole.local_storage_path, CalendarAggregator.Configurator.charts_and_tables_script_url, new List <string>()
         {
             "", "", ""
         });
     }
     catch (Exception ex)
     {
         GenUtils.PriorityLogMsg("exception", "MakeTablesAndCharts", ex.Message + ex.StackTrace);
     }
 }
    void Compile()
    {
        var engine = PythonUtils.GetEngine();
        var source = engine.CreateScriptSourceFromString(PythonUtils.defaultPythonBehaviourHeader + text);

        try {
            m_compiled = source.Compile();
        } catch (System.Exception ex) {
            compiledWithError = true;
            m_updateCount++;
            m_dirty = false;
            throw ex;
        }
        m_updateCount++;
        m_dirty = false;
    }
示例#9
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        var allChangedAssets = movedAssets.Concat(movedFromAssetPaths).Concat(importedAssets);

        PythonScriptsDatabase.AssetsStartUpdating();
        foreach (string assetPath in allChangedAssets)
        {
            bool isPythonScript = PythonUtils.IsPythonFile(assetPath);
            if (!isPythonScript)
            {
                continue;
            }
            PythonScriptsDatabase.UpdateScript(assetPath);
        }
        PythonScriptsDatabase.AssetsFinishedUpdating();
    }
示例#10
0
            public override void ExecuteResult(ControllerContext context)
            {
                // this one calls out to python, can take a while
                context.HttpContext.Server.ScriptTimeout = CalendarAggregator.Configurator.webrole_script_timeout_seconds;
                var args = new List <string>()
                {
                    this.fusecal_url, this.filter, this.tz_source, this.tz_dest
                };
                var ics = PythonUtils.RunIronPython(WebRole.local_storage_path, CalendarAggregator.Configurator.fusecal_dispatcher, args);

                new ContentResult
                {
                    ContentType     = "text/calendar",
                    Content         = ics,
                    ContentEncoding = UTF8
                }.ExecuteResult(context);
            }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var scriptAssetProperty = property.FindPropertyRelative("m_scriptAsset");

        var scriptAsset = scriptAssetProperty.objectReferenceValue;

        var newAsset = EditorGUI.ObjectField(position, "script", scriptAsset, typeof(Object), false);

        if (newAsset != null && !PythonUtils.IsPythonFile(newAsset))
        {
            newAsset = scriptAsset;
        }

        if (newAsset != scriptAsset)
        {
            scriptAssetProperty.objectReferenceValue = newAsset;
        }
    }
示例#12
0
    private void Awake()
    {
        if (script == null)
        {
            Debug.LogError("There is no script on this object: " + gameObject.name);
            return;
        }
        if (scope == null)
        {
            ScriptEngine scriptEngine = PythonUtils.GetEngine();
            scope = scriptEngine.CreateScope();
            scope.SetVariable("owner", this);
            scope.SetVariable("gameObject", gameObject);
            scope.SetVariable("transform", transform);

            source = scriptEngine.CreateScriptSourceFromString(script.text);
            source.Compile();
            source.Execute(scope);
            CallMethod("Awake");
        }
    }
    void ExecuteCommand(string command)
    {
        if (input.wasCanceled)
        {
            input.ActivateInputField();
            return;
        }
        input.text = "";
        input.ActivateInputField();
        if (command.Length != 0)
        {
            m_previousCommands.Insert(0, command);
        }
        m_previousCommandSelected = -1;

        m_commandExecutionInProgress = true;
        bool exception = false;

        try{
            PythonUtils.GetEngine().Execute(command, m_scope);
        }catch (Exception e) {
            exception = true;
            write(e.Message);
        }
        m_commandExecutionInProgress = false;

        var commandLog = "<b>" + (exception ? "<color=#d22>" : "") + command + (exception ? "</color=#f66>" : "") + "</b>";

        if (string.IsNullOrEmpty(m_log))
        {
            m_log = commandLog;
        }
        else
        {
            m_log = commandLog + "\n" + m_log;
        }

        FlushLog();
        scroll.verticalNormalizedPosition = 0f;
    }
示例#14
0
    void OnEnable()
    {
        input.onSubmit.AddListener(ExecuteCommand);

        if (m_scope == null)
        {
            m_scope = PythonUtils.GetEngine().CreateScope();
            //		m_scope.SetVariable ("_pythonConsole", this);
            PythonUtils.GetEngine().Execute(PythonUtils.defaultPythonConsoleHeader + GlobalAssemblyImport() +
                                            @"
import sys
sys.stdout=PythonConsole
Select = PythonConsole.Select

import UnityEngine
Destroy = UnityEngine.Object.Destroy
FindObjectOfType = UnityEngine.Object.FindObjectOfType
FindObjectsOfType = UnityEngine.Object.FindObjectsOfType
Instantiate = UnityEngine.Object.Instantiate

"
                                            , m_scope);
        }
    }
示例#15
0
        void WritePyi(List <PyClass> classes)
        {
            var reqEnumFields = GetRequiredEnumFields(classes);

            var filename = genTypes.Dirs.GetPythonPyFilename("_iced_x86_py.pyi");

            using (var writer = new FileWriter(TargetLanguage.Python, FileUtils.OpenWrite(filename))) {
                writer.WriteFileHeader();
                writer.WriteLine("from collections.abc import Iterator");
                writer.WriteLine("from enum import IntEnum, IntFlag");
                writer.WriteLine("from typing import Any, List, Optional, Union");
                writer.WriteLine();

                var idConverter  = PythonIdentifierConverter.Create();
                var allEnumTypes = exportedPythonTypes.Enums.Select(a => (enumType: a, pythonName: a.Name(idConverter)));
                var toEnumType   = allEnumTypes.ToDictionary(a => a.pythonName, a => a.enumType, StringComparer.Ordinal);
                foreach (var(enumType, pythonName) in allEnumTypes.OrderBy(a => a.pythonName, StringComparer.Ordinal))
                {
                    var baseClass = enumType.IsFlags ? "IntFlag" : "IntEnum";
                    if (reqEnumFields.TryGetValue(enumType, out var fields))
                    {
                        writer.WriteLine($"class {pythonName}({baseClass}):");
                        using (writer.Indent()) {
                            bool uppercaseRawName = PythonUtils.UppercaseEnum(enumType.TypeId.Id1);
                            foreach (var value in enumType.Values)
                            {
                                if (fields.Contains(value))
                                {
                                    fields.Remove(value);
                                    var(valueName, numStr) = PythonUtils.GetEnumNameValue(idConverter, value, uppercaseRawName);
                                    writer.WriteLine($"{valueName} = {numStr}");
                                }
                                if (fields.Count == 0)
                                {
                                    break;
                                }
                            }
                            if (fields.Count != 0)
                            {
                                throw new InvalidOperationException();
                            }
                            writer.WriteLine("...");
                        }
                    }
                    else
                    {
                        writer.WriteLine($"class {pythonName}({baseClass}): ...");
                    }
                }

                var docGen = new PyiDocGen();
                foreach (var pyClass in classes.OrderBy(a => a.Name, StringComparer.Ordinal))
                {
                    writer.WriteLine();
                    writer.WriteLine($"class {idConverter.Type(pyClass.Name)}:");
                    using (writer.Indent()) {
                        WriteDocs(writer, docGen.Convert(pyClass.DocComments));

                        int defCount = 0;
                        foreach (var member in GetMembers(pyClass))
                        {
                            switch (member)
                            {
                            case PyMethod method:
                                var docComments = method.Attributes.Any(AttributeKind.New) ?
                                                  pyClass.DocComments : method.DocComments;
                                Write(writer, docGen, idConverter, pyClass, method, docComments, toEnumType);
                                defCount++;
                                break;

                            case PyProperty property:
                                Write(writer, docGen, idConverter, pyClass, property.Getter, property.Getter.DocComments, toEnumType);
                                defCount++;
                                if (property.Setter is not null)
                                {
                                    Write(writer, docGen, idConverter, pyClass, property.Setter, property.Getter.DocComments, toEnumType);
                                    defCount++;
                                }
                                break;

                            default:
                                throw new InvalidOperationException();
                            }
                        }
                        if (defCount == 0)
                        {
                            throw new InvalidOperationException($"class {pyClass.Name}: No class members");
                        }
                    }
                }
            }
        }