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 = [ ["", "---"] ] 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'([^<]*)', 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("%s" % version, "%s" % 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)