[r56]: / trunk / cforge / cforge / Package / CFORGE / Scripts / build.py  Maximize  Restore  History

Download this file

79 lines (67 with data), 2.9 kB

 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
import sys, os
import re
import zipfile
import cds_script


# This is a cforge command (script file)
# this will be run as ironpython script.
# the filename of this script is automatically the corresponding cforge command 
# with some magic functions you can easily integrate it nicely into cforge tool

# cforge_usage: 
# here you can return an array of all possible arguments and options that can 
# be passed to this command script
def cforge_usage():
    help = [ 
        ["<path to local repository>", "---"]
    ]

    return help


if len(sys.argv) <= 1:
    print("Oh, there are no arguments. Perhaps you forgot something?")
    sys.exit()

folder = sys.argv[1]
scriptpath = os.path.abspath(os.path.dirname(sys.argv[0]))

def zipdir(path, ziph):
    # ziph is zipfile handle
    for root, dirs, files in os.walk(path):
        for file in files:
            filename=os.path.join(root, file)
            archname=filename[len(path)+1:]
            print("Adding file: %s -> %s" % (filename, archname))
            ziph.write(filename, arcname=archname)


# Build all packages
xFoundProject = False
for root, dirs, files in os.walk(folder):
    for file in files:
        # btw, check if some libs or projects are to be built
        if file.endswith(".library") or file.endswith(".project"):
            xFoundProject = True
        if file == "package.manifest":
            # Increase Package Version
            packageManifest = os.path.join(root, file)
            f = open(packageManifest, 'r')
            if f:
                manifest = f.read()
                version = re.findall(r'<Version>([^<]*)</Version>', manifest)
                if len(version) == 1:
                    version = version[0]
                    version_tuple = version.split('.')
                    version_tuple[-1] = str(int(version_tuple[-1]) + 1)
                    new_version = ".".join(version_tuple)
                    print("Increasing package version number from %s to %s\n" % (version, new_version))
                    manifest = manifest.replace("<Version>%s</Version>" % version, "<Version>%s</Version>" % new_version)
                    f.close()
                    f = open(packageManifest, 'w')
                    if f:
                        f.write(manifest)
                        f.close()
            # ZIP package
            packageDir = root
            packageName = root + ".package"
            print("Creating package: '%s' -> '%s'" % (packageDir, packageName))
            zipf = zipfile.ZipFile(packageName, 'w', zipfile.ZIP_DEFLATED)
            zipdir(packageDir, zipf)
            zipf.close()

# Export documentation as markdown
if xFoundProject:
    scriptname = os.path.join(scriptpath, "action.markdown.py")
    scriptargs = folder
    cds_script.RunCodesysWithScript(scriptname, scriptargs, False)