-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakehuman.py
225 lines (183 loc) · 7.39 KB
/
makehuman.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
MakeHuman python entry-point.
**Project Name:** MakeHuman
**Product Home Page:** http://www.makehuman.org/
**Code Home Page:** http://code.google.com/p/makehuman/
**Authors:** Glynn Clements, Joel Palmius
**Copyright(c):** MakeHuman Team 2001-2013
**Licensing:** AGPL3 (see also http://www.makehuman.org/node/318)
**Coding Standards:** See http://www.makehuman.org/node/165
Abstract
--------
This file starts the MakeHuman python application.
"""
from __future__ import absolute_import # Fix 'from . import x' statements on python 2.6
import sys
import os
import string
import re
import subprocess
# print >> sys.stderr, os.getcwd()
def find_mydocuments():
os.environ['MYDOCUMENTS'] = os.path.expanduser('~')
if sys.platform == 'win32':
import winreg
try:
k = winreg.HKEY_CURRENT_USER
for x in ['Software', 'Microsoft', 'Windows', 'CurrentVersion', 'Explorer', 'Shell Folders']:
k = winreg.OpenKey(k, x)
name, type = winreg.QueryValueEx(k, 'Personal')
if type == 1:
os.environ['MYDOCUMENTS'] = name
except Exception as e:
print("fatal error", file=sys.stderr)
def get_revision_svn_info():
# Try getting svn revision by calling svn info (will only work in linux
# and windows where sliksvn is installed)
output = subprocess.Popen(["svn","info","."], stdout=subprocess.PIPE, stderr=sys.stderr).communicate()[0]
for line in output.splitlines():
key, value = line.split(':', 1)
if key.strip().lower() == 'revision':
return value.strip()
raise RuntimeError("revision not found in 'svn info .' output")
def get_revision_entries():
# First fallback: try to parse the entries file manually
scriptdir = os.path.dirname(os.path.abspath(__file__))
svndir = os.path.join(scriptdir,'.svn')
entriesfile = os.path.join(svndir,'entries')
entries = open(entriesfile, 'r').read()
result = re.search(r'dir\n(\d+)\n',entries)
output = result.group(1)
if not output:
raise RuntimeError("revision not found in 'entries' file")
return output
def get_revision_pysvn():
# The following only works if pysvn is installed. We'd prefer not to use this since it's very slow.
# It was taken from this stackoverflow post:
# http://stackoverflow.com/questions/242295/how-does-one-add-a-svn-repository-build-number-to-python-code
import pysvn
repo = "."
rev = pysvn.Revision( pysvn.opt_revision_kind.working )
client = pysvn.Client()
info = client.info2(repo,revision=rev,recurse=False)
output = format(str(info[0][1].rev.number))
return output
def get_revision_file():
# Default fallback to use if we can't figure out SVN revision in any other
# way: Use this file's svn revision.
pattern = re.compile(r'[^0-9]')
return pattern.sub("", "$Revision$")
def get_svn_revision_1():
svnrev = None
try:
svnrev = get_revision_svn_info()
os.environ['SVNREVISION_SOURCE'] = "svn info command"
return svnrev
except Exception as e:
print(sys.stderr, "NOTICE: Failed to get svn version number from command line: " + format(str(e)) + " (This is just a head's up, not a critical error)")
try:
svnrev = get_revision_entries()
os.environ['SVNREVISION_SOURCE'] = "entries file"
return svnrev
except Exception as e:
print(sys.stderr, "NOTICE: Failed to get svn version from file: " + format(str(e)) + " (This is just a head's up, not a critical error)")
try:
svnrev = get_revision_pysvn()
os.environ['SVNREVISION_SOURCE'] = "pysvn"
return svnrev
except Exception as e:
print(sys.stderr, "NOTICE: Failed to get svn version number using pysvn: " + format(str(e)) + " (This is just a head's up, not a critical error)")
print(sys.stderr, "NOTICE: Using SVN rev from file stamp. This is likely outdated, so the number in the title bar might be off by a few commits.")
svnrev = get_revision_file()
os.environ['SVNREVISION_SOURCE'] = "approximated from file stamp"
return svnrev
def get_svn_revision():
#[BAL 07/13/2013] use the VERSION file if it exists. This is created and managed using pyinstaller.
if os.path.exists(os.path.join("core","VERSION")):
version = open(os.path.join("core","VERSION")).read().strip()
print(sys.stderr, "VERSION file detected using value from version file: %s" % version)
os.environ['SVNREVISION'] = version
os.environ['SVNREVISION_SOURCE'] = "core/VERSION static revision data"
else:
print(sys.stderr, "NO VERSION file detected retrieving revision info from SVN")
# Set SVN rev in environment so it can be used elsewhere
svnrev = get_svn_revision_1()
print(sys.stderr, "Detected SVN revision: " + svnrev)
os.environ['SVNREVISION'] = svnrev
def recursiveDirNames(root):
pathlist=[]
#root=os.path.dirname(root)
for filename in os.listdir(root):
path=os.path.join(root,filename)
if not (os.path.isfile(path) or filename=="." or filename==".." or filename==".svn"):
pathlist.append(path)
pathlist = pathlist + recursiveDirNames(path)
return(pathlist)
def set_sys_path():
#[BAL 07/11/2013] make sure we're in the right directory
if sys.platform != 'darwin':
os.chdir(sys.path[0])
syspath = ["./", "./lib", "./apps", "./shared", "./apps/gui","./core"]
syspath.extend(sys.path)
sys.path = syspath
stdout_filename = None
stderr_filename = None
def get_platform_paths():
global stdout_filename, stderr_filename
if sys.platform == 'win32':
find_mydocuments()
home = os.environ['MYDOCUMENTS']
home = os.path.join(home,'makehuman')
if not os.path.exists(home):
os.makedirs(home)
stdout_filename = os.path.join(home, "python_out.txt")
stderr_filename = os.path.join(home, "python_err.txt")
elif sys.platform.startswith("darwin"):
home = os.path.join(os.path.expanduser('~'),"Documents")
home = os.path.join(home,"MakeHuman")
if not os.path.exists(home):
os.makedirs(home)
stdout_filename = os.path.join(home, "makehuman-output.txt")
stderr_filename = os.path.join(home, "makehuman-error.txt")
def redirect_standard_streams():
if stdout_filename:
sys.stdout = open(stdout_filename, "w")
if stderr_filename:
sys.stderr = open(stderr_filename, "w")
def close_standard_streams():
sys.stdout.close()
sys.stderr.close()
def make_user_dir():
import getpath
userDir = getpath.getPath('')
if not os.path.isdir(userDir):
os.makedirs(userDir)
def init_logging():
import log
log.init()
log.message('Initialized logging')
def debug_dump():
try:
import debugdump
debugdump.dump.reset()
except Exception as e:
import log
log.error("Could not create debug dump", exc_info=True)
def main():
get_platform_paths()
redirect_standard_streams()
set_sys_path()
get_svn_revision()
make_user_dir()
init_logging()
debug_dump()
from mhmain import MHApplication
application = MHApplication()
application.run()
#import cProfile
#cProfile.run('application.run()')
close_standard_streams()
if __name__ == '__main__':
main()