-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiGenHelper.py
77 lines (59 loc) · 1.86 KB
/
ApiGenHelper.py
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
import sublime, glob, os, subprocess
settings = None
active = False
def plugin_loaded():
global settings
settings = sublime.load_settings("ApiGen.sublime-settings")
def canRun():
global active
return not active
def activate():
global active
active = True
def deactivate():
global active
active = False
def startLine():
print('\n\n################################ ApiGen Started ################################')
def endLine():
print('################################ ApiGen Finished ###############################')
def getConfigFile(start):
global settings
config = ''
lastPass = start
thisPass = os.path.dirname(start)
filename = settings.get('configFileName', 'apigen.neon')
while lastPass != thisPass :
os.chdir(thisPass)
for file in glob.glob(filename):
config = thisPass + os.sep + file
if config != '':
break
if config != '':
break
lastPass = thisPass
thisPass = os.path.dirname(thisPass)
return config
def runApiGen(args):
global settings
php = settings.get('phpBin', 'php')
phar = settings.get('pharPath', 'apigen.phar')
cmd = [php, phar]
cmd.extend(args)
proc = ''
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, startupinfo=startupinfo)
else:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
while proc.poll() is None:
try:
data = proc.stdout.readline().decode(encoding='UTF-8')
print(data, end="")
except:
endLine()
deactivate()
return
endLine()
deactivate()