From: batt Date: Fri, 30 Apr 2010 18:04:05 +0000 (+0000) Subject: Add preset creationg script. X-Git-Tag: 2.5.0~322 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8ac9d07c26a3bade655fe7650336b846c3a59d30;p=bertos.git Add preset creationg script. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3586 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/wizard/create_preset.py b/wizard/create_preset.py new file mode 100644 index 00000000..e2416c66 --- /dev/null +++ b/wizard/create_preset.py @@ -0,0 +1,100 @@ +import pickle +import sys +import os +import shutil +import pprint +import glob +import re + +def remove(path): + if os.path.isdir(path): + shutil.rmtree(path, ignore_errors=True) + else: + try: + os.remove(path) + except OSError: + pass + +def findPath(start, target): + pa = start + while pa != "/": + pa = os.path.abspath(pa + "/..") + print pa + if os.path.exists(pa + "/" + target): + return os.path.relpath(pa, start) + +if len(sys.argv) < 3: + print "Usage: %s " % sys.argv[0] + exit(0) + +prj_dir = sys.argv[1] +preset_dir = sys.argv[2] + +if not os.path.exists(prj_dir + "/project.bertos"): + print "%s does not seem a Wizard created project." % prj_dir + exit(1) + +p = open(prj_dir + "/project.bertos") +s = pickle.load(p) +if s["WIZARD_VERSION"] < 3: + print "Project version too old." + exit(1) +pname = s["PROJECT_NAME"] +preset_dir += pname + ".test" + +hw_path = findPath(preset_dir, "hw") +if not hw_path: + print "hw/ path not found in parent directories of %s" % preset_dir + exit(1) + +bertos_path = findPath(preset_dir, "bertos") +if not bertos_path: + print "bertos/ path not found in parent directories of %s" % preset_dir + exit(1) + +shutil.copytree(prj_dir, preset_dir) +remove(preset_dir + "/bertos") +remove(preset_dir + "/images") +remove(preset_dir + "/obj") +remove(preset_dir + "/Makefile") +remove(preset_dir + "/buildrev.h") +remove(preset_dir + "/VERSION") +remove(preset_dir + "/" + pname + ".project") +remove(preset_dir + "/" + pname + ".workspace") + +l = glob.glob(preset_dir + "/" + pname + "/*") +for f in l: + shutil.move(f, preset_dir) + +remove(preset_dir + "/" + pname) +remove(preset_dir + "/hw") + +assert(os.path.exists(preset_dir + "/" + hw_path + "/hw")) +assert(os.path.exists(preset_dir + "/" + bertos_path + "/bertos")) + +s["BERTOS_PATH"] = bertos_path +s["PRESET"] = True +s["PROJECT_HW_PATH"] = hw_path +s["PROJECT_SRC_PATH"] = "." +s["PRESET"] = True +pprint.pprint(s) +p = open(preset_dir + "/project.bertos", "w") +pickle.dump(s, p) + +p = open(preset_dir + "/.spec", "w") +p.write("name = '%s preset'" % pname) +p.close() + +bertos_path = os.path.abspath(preset_dir + "/" + bertos_path) +hw_path = os.path.abspath(preset_dir + "/" + hw_path) + +src_path = os.path.relpath(preset_dir, bertos_path) +hw_path = os.path.relpath(hw_path, bertos_path) + +mk = open(preset_dir + "/" + pname + ".mk").read() +mk = re.sub(r"(%s_SRC_PATH\s*=\s*).*" % pname, r"\1%s" % src_path, mk) +mk = re.sub(r"(%s_HW_PATH\s*=\s*).*" % pname, r"\1%s" % hw_path, mk) + +#remove absolute path from toolchain +mk = re.sub(r'(%s_PREFIX\s*=\s*").*?([^/]*")' % pname, r'\1\2', mk) +open(preset_dir + "/" + pname + ".mk", "w").write(mk)