-
Notifications
You must be signed in to change notification settings - Fork 41
/
unity_realtime_log.py
103 lines (78 loc) · 3 KB
/
unity_realtime_log.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
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
#coding=utf-8
COMMENT = """
##############################################
## Author ##
## Peilin Kelly Chan ##
## <https://github.com/mr-kelly> ##
## <[email protected]> ##
## ##
## Modify By Lohanry ##
## <https://github.com/yaogunfantuan> ##
## Now Support Custom Unity Command!!! ##
## ##
## a cross-platform build script for ##
## Unity3D console mode realtime log output ##
## ##
## ##
##############################################
"""
import platform
import time
import fileinput
import subprocess
import os
import sys
import thread
import time
import tail
def tail_thread(tail_file):
print "wait for tail file ... %s" % tail_file
while True:
if os.path.exists(tail_file):
print "Start tail file..... %s" % tail_file
break
t = tail.Tail(tail_file)
t.register_callback(unity_log_tail)
t.follow(s=1)
def unity_log_tail(txt):
print(txt)
def build(method, unity_path, project_path, log_path ,otherUnitySetting):
"""
call unity process to build
"""
build_cmd = unity_path+" "+'-batchmode'+" "+'-projectPath'+" "+project_path+" "+'-nographics'+" "+'-executeMethod'+" "+method+" "+'-logFile'+" "+log_path+" "+'-quit'+" "+otherUnitySetting
print build_cmd;
print 'Unity running ....'
if os.path.exists(log_path):
os.remove(log_path)
print 'delete %s' % log_path
# new thread to tail log file
thread.start_new_thread(tail_thread, (log_path, ))
process = subprocess.Popen(
build_cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
while True:
out = process.stdout.read(1)
if out == '' and process.poll() != None:
break
if out != '':
sys.stdout.write("[Unity process console output]: " + out)
sys.stdout.flush()
time.sleep(5)
print 'done!'
def fullpath(path):
return os.path.abspath(os.path.expanduser(path))
if __name__ == '__main__':
print COMMENT
import argparse
parser = argparse.ArgumentParser(description=u'Unity realtime log printing build!')
parser.add_argument('-unity', required=True, help=u'Unity executable file path')
parser.add_argument('-project', required=True, help=u'Unity project path')
parser.add_argument('-method', required=True, help=u'Unity method to call')
parser.add_argument('-logFile',required=True,help=u'Unity Log path')
parser.add_argument('-otherUnitySetting',required=False,help=u'Custom Unity Command')
args = parser.parse_args()
otherUnitySetting = "NoOtherUnitySetting"
if (args.otherUnitySetting != None):
otherUnitySetting = args.otherUnitySetting
build(args.method, args.unity, args.project,args.logFile,otherUnitySetting)