Diff of /branches/13-jobs/cforge/cforge/Package/CFORGE/Scripts/build.py [r63] .. [r64]  Maximize  Restore

Switch to unified view

a/branches/13-jobs/cforge/cforge/Package/CFORGE/Scripts/build.py b/branches/13-jobs/cforge/cforge/Package/CFORGE/Scripts/build.py
1
import sys, os
1
import sys, os
2
import re
2
import re
3
import zipfile
3
import zipfile
4
import cds_script
4
import cds_script
5
import ntpath
5
import ui
6
import ui
6
7
scriptpath = os.path.abspath(os.path.dirname(sys.argv[0]))
7
8
8
# This is a cforge command (script file)
9
# This is a cforge command (script file)
9
# this will be run as ironpython script.
10
# this will be run as ironpython script.
10
# the filename of this script is automatically the corresponding cforge command 
11
# the filename of this script is automatically the corresponding cforge command 
11
# with some magic functions you can easily integrate it nicely into cforge tool
12
# with some magic functions you can easily integrate it nicely into cforge tool
...
...
18
        ["<path to local repository>", "---"]
19
        ["<path to local repository>", "---"]
19
    ]
20
    ]
20
21
21
    return help
22
    return help
22
23
23
24
def zipdir(path, ziph):
24
if len(sys.argv) <= 1:
25
    # ziph is zipfile handle
25
    print("Oh, there are no arguments. Perhaps you forgot something?")
26
    for root, dirs, files in os.walk(path):
26
    sys.exit()
27
        for file in files:
27
28
            filename=os.path.join(root, file)
28
folder = sys.argv[1]
29
            archname=filename[len(path)+1:]
29
scriptpath = os.path.abspath(os.path.dirname(sys.argv[0]))
30
            print("Adding file: %s -> %s" % (filename, archname))
30
31
            ziph.write(filename, arcname=archname)
31
# if folder can't be found, try to interpret it as a repo
32
33
def do(folder):
34
    #folder = sys.argv[1]
35
36
    # if folder can't be found, try to interpret it as a repo
32
# name, relatively to the workspace folder
37
    # name, relatively to the workspace folder
33
if not os.path.isdir(folder):
38
    if not os.path.isdir(folder):
34
    config = ui.GetSettings()
39
        config = ui.GetSettings()
35
    workspace, file = ntpath.split(config['folder'])
40
        workspace, file = ntpath.split(config['folder'])
36
    folder = os.path.join(workspace, folder)
41
        folder = os.path.join(workspace, folder)
37
42
38
print("building folder: %s" % folder)
43
    print("building folder: %s" % folder)
39
44
40
def zipdir(path, ziph):
45
    # Build all packages
41
    # ziph is zipfile handle
46
    xFoundProject = False
42
    for root, dirs, files in os.walk(path):
43
        for file in files:
44
            filename=os.path.join(root, file)
45
            archname=filename[len(path)+1:]
46
            print("Adding file: %s -> %s" % (filename, archname))
47
            ziph.write(filename, arcname=archname)
48
49
50
# Build all packages
51
xFoundProject = False
52
for root, dirs, files in os.walk(folder):
47
    for root, dirs, files in os.walk(folder):
53
    for file in files:
48
        for file in files:
54
        # btw, check if some libs or projects are to be built
49
            # btw, check if some libs or projects are to be built
55
        if file.endswith(".library") or file.endswith(".project"):
50
            if file.endswith(".library") or file.endswith(".project"):
56
            xFoundProject = True
51
                xFoundProject = True
57
        if file == "package.manifest":
52
            if file == "package.manifest":
58
            # Increase Package Version
53
                # Increase Package Version
59
            packageManifest = os.path.join(root, file)
54
                packageManifest = os.path.join(root, file)
60
            f = open(packageManifest, 'r')
55
                f = open(packageManifest, 'r')
61
            if f:
56
                if f:
62
                manifest = f.read()
57
                    manifest = f.read()
63
                version = re.findall(r'<Version>([^<]*)</Version>', manifest)
58
                    version = re.findall(r'<Version>([^<]*)</Version>', manifest)
64
                if len(version) == 1:
59
                    if len(version) == 1:
65
                    version = version[0]
60
                        version = version[0]
66
                    version_tuple = version.split('.')
61
                        version_tuple = version.split('.')
67
                    version_tuple[-1] = str(int(version_tuple[-1]) + 1)
62
                        version_tuple[-1] = str(int(version_tuple[-1]) + 1)
68
                    new_version = ".".join(version_tuple)
63
                        new_version = ".".join(version_tuple)
69
                    print("Increasing package version number from %s to %s\n" % (version, new_version))
64
                        print("Increasing package version number from %s to %s\n" % (version, new_version))
70
                    manifest = manifest.replace("<Version>%s</Version>" % version, "<Version>%s</Version>" % new_version)
65
                        manifest = manifest.replace("<Version>%s</Version>" % version, "<Version>%s</Version>" % new_version)
71
                    f.close()
66
                        f.close()
72
                    f = open(packageManifest, 'w')
67
                        f = open(packageManifest, 'w')
73
                    if f:
68
                        if f:
74
                        f.write(manifest)
69
                            f.write(manifest)
75
                        f.close()
70
                            f.close()
76
            # ZIP package
71
                # ZIP package
77
            packageDir = root
72
                packageDir = root
78
            packageName = root + ".package"
73
                packageName = root + ".package"
79
            print("Creating package: '%s' -> '%s'" % (packageDir, packageName))
74
                print("Creating package: '%s' -> '%s'" % (packageDir, packageName))
80
            zipf = zipfile.ZipFile(packageName, 'w', zipfile.ZIP_DEFLATED)
75
                zipf = zipfile.ZipFile(packageName, 'w', zipfile.ZIP_DEFLATED)
81
            zipdir(packageDir, zipf)
76
                zipdir(packageDir, zipf)
82
            zipf.close()
77
                zipf.close()
83
78
84
# Export documentation as markdown
79
    # Export documentation as markdown
85
if xFoundProject:
80
    if xFoundProject:
86
    scriptname = os.path.join(scriptpath, "action.markdown.py")
81
        scriptname = os.path.join(scriptpath, "action.markdown.py")
87
    scriptargs = folder
82
        scriptargs = folder
88
    cds_script.RunCodesysWithScript(scriptname, scriptargs, False)
83
        cds_script.RunCodesysWithScript(scriptname, scriptargs, False)
89
84
85
# call main
86
if __name__ == "__main__":
87
    if len(sys.argv) <= 1:
88
        print("Oh, there are no arguments. Perhaps you forgot something?")
89
        sys.exit()
90
    do(sys.argv[1])