-
Notifications
You must be signed in to change notification settings - Fork 10
/
packagePythonTools.py
81 lines (57 loc) · 2.23 KB
/
packagePythonTools.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
import os
from consoleChroma import Good
from filesystem import Path, removeDupes
from dependencies import generateDepTree, makeScriptPathRelative
_THIS_FILE = Path( os.path.abspath( __file__ ) )
_PYTHON_TOOLS_TO_PACKAGE = _THIS_FILE.up() / 'pythonToolsToPackage.txt'
_PACKAGE_DIR_NAME = 'zooToolboxPy'
_PACKAGE_DIR = _THIS_FILE.up( 2 ) / _PACKAGE_DIR_NAME
def cleanPackageDir():
if _PACKAGE_DIR.exists():
_PACKAGE_DIR.delete()
_PACKAGE_DIR.create()
def buildPackage( dependencyTree=None ):
if not _PYTHON_TOOLS_TO_PACKAGE.exists():
raise ValueError( "Cannot find %s file!" % _PYTHON_TOOLS_TO_PACKAGE.name() )
modulesToPackage = []
for toolName in _PYTHON_TOOLS_TO_PACKAGE.read():
if toolName:
if toolName.startswith( '#' ):
continue
elif toolName.startswith( '//' ):
continue
modulesToPackage.append( toolName )
cleanPackageDir()
if dependencyTree is None:
dependencyTree = generateDepTree()
filesToPackage = []
for moduleName in modulesToPackage:
moduleScriptPath = dependencyTree.moduleNameToScript( moduleName )
filesToPackage += dependencyTree.findDependencies( moduleScriptPath, None, False )
if not filesToPackage:
return None
#remove any duplicate files...
filesToPackage = removeDupes( filesToPackage )
#this is a little hacky - but we don't want to re-distribute wingdbstub so lets check to see if its in the list of files
for f in filesToPackage:
if f.name() == 'wingdbstub':
filesToPackage.remove( f )
break
print >> Good, "Found dependencies - %d files" % len( filesToPackage )
for f in filesToPackage:
relativePath = makeScriptPathRelative( f )
packagedPath = _PACKAGE_DIR / relativePath
if len( relativePath ) > 1:
packagedPath.up().create()
f.copy( packagedPath )
print 'copying ----> %s' % f
#now zip up the files into a package
cmdStr = '7z a -r ..\\%s\\zooToolBoxPy.7z ..\\%s\\' % (_PACKAGE_DIR_NAME, _PACKAGE_DIR_NAME)
os.system( cmdStr )
#now write a simple mel script to load the toolbox UI
cmdStr = """global proc zooToolBox() { return; }"""
bootstrapMelScript = _PACKAGE_DIR / 'zooToolBox.mel'
bootstrapMelScript.write( cmdStr )
if __name__ == '__main__':
buildPackage()
#end