a | b/trunk/cforge/cforge/Package/CFORGE/Scripts/build.py | ||
---|---|---|---|
1 | import sys, os |
||
2 | import zipfile |
||
3 | |||
4 | |||
5 | |||
6 | # This is a cforge command (script file) |
||
7 | # this will be run as ironpython script. |
||
8 | # the filename of this script is automatically the corresponding cforge command |
||
9 | # with some magic functions you can easily integrate it nicely into cforge tool |
||
10 | |||
11 | # cforge_usage: |
||
12 | # here you can return an array of all possible arguments and options that can |
||
13 | # be passed to this command script |
||
14 | def cforge_usage(): |
||
15 | help = [ |
||
16 | ["<path to local repository>", "---"] |
||
17 | ] |
||
18 | |||
19 | return help |
||
20 | |||
21 | |||
22 | if len(sys.argv) <= 1: |
||
23 | print("Oh, there are no arguments. Perhaps you forgot something?") |
||
24 | sys.exit() |
||
25 | |||
26 | folder = sys.argv[1] |
||
27 | |||
28 | def zipdir(path, ziph): |
||
29 | # ziph is zipfile handle |
||
30 | for root, dirs, files in os.walk(path): |
||
31 | for file in files: |
||
32 | filename=os.path.join(root, file) |
||
33 | archname=filename[len(path)+1:] |
||
34 | print("Adding file: %s -> %s" % (filename, archname)) |
||
35 | ziph.write(filename, arcname=archname) |
||
36 | |||
37 | |||
38 | for root, dirs, files in os.walk(folder): |
||
39 | for file in files: |
||
40 | if file == "package.manifest": |
||
41 | packageDir = root |
||
42 | packageName = root + ".package" |
||
43 | print("Creating package: '%s' -> '%s'" % (packageDir, packageName)) |
||
44 | zipf = zipfile.ZipFile(packageName, 'w', zipfile.ZIP_DEFLATED) |
||
45 | zipdir(packageDir, zipf) |
||
46 | zipf.close() |