--- a/branches/13-jobs/cforge/cforge/Package/CFORGE/Scripts/build.py +++ b/branches/13-jobs/cforge/cforge/Package/CFORGE/Scripts/build.py @@ -2,8 +2,9 @@ import re import zipfile import cds_script -import ntpath import ui + +scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) # This is a cforge command (script file) # this will be run as ironpython script. @@ -20,69 +21,70 @@ return help +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) -if len(sys.argv) <= 1: - print("Oh, there are no arguments. Perhaps you forgot something?") - sys.exit() +def do(folder): + #folder = sys.argv[1] -folder = sys.argv[1] -scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) + # if folder can't be found, try to interpret it as a repo + # name, relatively to the workspace folder + if not os.path.isdir(folder): + config = ui.GetSettings() + workspace, file = ntpath.split(config['folder']) + folder = os.path.join(workspace, folder) -# if folder can't be found, try to interpret it as a repo -# name, relatively to the workspace folder -if not os.path.isdir(folder): - config = ui.GetSettings() - workspace, file = ntpath.split(config['folder']) - folder = os.path.join(workspace, folder) + print("building folder: %s" % folder) -print("building folder: %s" % folder) + # 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() -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) + # Export documentation as markdown + if xFoundProject: + scriptname = os.path.join(scriptpath, "action.markdown.py") + scriptargs = folder + cds_script.RunCodesysWithScript(scriptname, scriptargs, False) - -# 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) +# call main +if __name__ == "__main__": + if len(sys.argv) <= 1: + print("Oh, there are no arguments. Perhaps you forgot something?") + sys.exit() + do(sys.argv[1])