forked from getnamo/UnrealEnginePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupycmd.py
More file actions
120 lines (93 loc) · 2.86 KB
/
upycmd.py
File metadata and controls
120 lines (93 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ue.exec('pip2.py')
import subprocess
import sys
import os
import unreal_engine as ue
import _thread as thread
#ue.log(sys.path)
_problemPaths = ['']
def NormalizePaths():
problemPaths = _problemPaths
#replace '/' to '\\'
for i in range(len(sys.path)):
currentPath = sys.path[i]
sys.path[i] = currentPath.replace('\\','/')
#find additional problem paths such as engine bin
currentPath = sys.path[i]
if('Engine' in currentPath and 'Epic Games' in currentPath):
_problemPaths.append(currentPath)
#cleanup
for path in problemPaths:
if path in sys.path:
sys.path.remove(path)
#define some convenience paths
def PythonHomePath():
for path in sys.path:
normalizedPath = AsAbsPath(path)
if ('UnrealEnginePython' in normalizedPath and
normalizedPath.endswith('Binaries/Win64')):
return path
#return sys.path[1]
return "not found"
def PythonHomeScriptsPath():
return AsAbsPath(PythonHomePath() + "/Scripts")
def PythonPluginScriptPath():
for path in sys.path:
normalizedPath = AsAbsPath(path)
if ('UnrealEnginePython' in normalizedPath and
normalizedPath.endswith('Content/Scripts')):
return path
return "not found"
def PythonProjectScriptPath():
relativePath = PythonPluginScriptPath() + "/../../../../Content/Scripts";
return AsAbsPath(relativePath);
def AsAbsPath(path):
return os.path.abspath(path).replace('\\','/')
_PythonHomePath = PythonHomePath()
def FolderCommand(folder):
#replace backslashes
folder = folder.replace('/','\\')
changefolder = "cd /d \"" + folder + "\" & "
return changefolder
#main public function
def run(process, path=_PythonHomePath, verbose=True):
#todo: change folder
fullcommand = FolderCommand(path) + process
if verbose:
ue.log("Started cmd <" + fullcommand + ">")
stdoutdata = subprocess.getstatusoutput(fullcommand)
if verbose:
ue.log("cmd Result: ")
ue.log(stdoutdata[1])
return stdoutdata[1] #return the data for dependent functions
def runStreaming(process, callback=None, path=_PythonHomePath, verbose=True):
#todo: change folder
fullcommand = FolderCommand(path) + process
if verbose:
print("Started cmd <" + fullcommand + ">")
#streaming version
popenobj = subprocess.Popen(fullcommand, stdout=subprocess.PIPE)
output = ''
for line in iter(process.stdout.readline, ''):
#sys.stdout.write(line)
print(line)
output += line
if verbose:
print("cmd Result: ")
print(output)
return output #return the data for dependent functions
#convenience override
def runLogOutput(process, path=_PythonHomePath):
fullcommand = FolderCommand(path) + process
stdoutdata = subprocess.getstatusoutput(fullcommand)
ue.log(stdoutdata[1])
return stdoutdata[1]
#convenience wrappers
def dir(path=_PythonHomePath):
run('dir', path)
def ls(path=_PythonHomePath):
dir(path)
def md(folder, path=_PythonHomePath):
run('md ' + folder, path)
def mkdir(folder, path=_PythonHomePath):
md(folder, path)