def test_pack_commit(): from dskenv.base_env import BaseEnv from dskenv.pack_info import PackInfo from dsk.base.lib.base_fileproc import BaseFileProc run_dry = True packname = "dsk" repo_name = "devsoftkit" top_release_path = "/mnt/dev/install" version = "v0.0.8" searchPath1 = [BaseEnv.base()] searchPath2 = [BaseEnv.user_home('eric')] print("SEARCHPATH",searchPath1,searchPath2) pi = PackInfo(packname) rcHome = pi.real_version_file(PackInfo,searchPath2) fromFile = rcHome.get_fullname() rcRelease = pi.real_version_file(PackInfo,searchPath1) assert rcHome.is_versioned() == False import tempfile import uuid import re pat1 = re.compile("base_release\s*=") pat2 = re.compile("version\s*=") tmp = os.path.join(tempfile.gettempdir(), "pack_%s" % uuid.uuid4().hex) with open(fromFile, "rt") as fin: with open(tmp, "wt") as fout: for line in fin: m = pat1.search(line) if m: release_path = os.path.join(top_release_path,repo_name) fout.write('base_release = "%s"\n' % release_path) else: m = pat2.search(line) if m: fout.write('version = "%s"\n' % version) else: fout.write(line) print(tmp) todolist = BaseFileProc() if rcRelease == None: print("first creation") rcHome.version_up_minor() toFile = rcHome.get_fullname() # repath toFile = toFile.replace(searchPath2[0],searchPath1[0]) print("from %s to %s" % (tmp,toFile)) todolist.copy_envifile(tmp, toFile) else: print(rcRelease.get_fullname()) rcRelease.version_up_minor() toFile = rcRelease.get_fullname() todolist.copy_envifile(tmp, toFile) todolist.delete_file(tmp) #todolist.delete_file(fromFile) res_copy = todolist.execute_stop_first_failed(run_dry=run_dry, with_log = True) print(res_copy.success,res_copy.log)
def parse_cmd_base(self, argListOrStr): from argparse import ArgumentParser # parser setup parser = ArgumentParser() parser.add_argument("-c", dest="configs", action="append", default=list(), help="config(s) to load") parser.add_argument("-p", dest="packs", action="append", default=list(), help="pack(s) to load") parser.add_argument("-d", dest="d", action="store_true", default=False, help="first look in current area") parser.add_argument("-D", dest="D", action="store", default="", help="other username") parser.add_argument("-f", dest="fromDir", action="store", default="", help="from a given directory") parser.add_argument("-r", dest="revision", action="store", default="", help="(not supported yet) for config") parser.add_argument("-t", dest="date", action="store", default="", help="use for packs") argList = argListOrStr if type(argListOrStr) in (str,): # split appropriately if argListOrStr.find(" ") == -1: argList = [argListOrStr] else: argList = argListOrStr.split() if type(argList) != list: return False (opt, args) = parser.parse_known_args(argList) # opt.configs.extend(args) # extra arguments # are interpreted as configs baseSearch = BaseEnv.base() if opt.fromDir != "": baseSearch = opt.fromDir if opt.D != "": self._devName = opt.D elif opt.d is True: self._devName = getpass.getuser() if self._devName != "": self._searchPath = [BaseEnv.user_home(self._devName), baseSearch] else: self._searchPath = [baseSearch] opt.configs = [x for x in opt.configs if x != ""] opt.packs = [x for x in opt.packs if x != ""] return (opt, args)
def test_pack_checkout(): from dskenv.base_env import BaseEnv from dskenv.pack_info import PackInfo from dsk.base.lib.base_fileproc import BaseFileProc run_dry = True dev_path = "/mnt/dev/eric/packages" packname = "dsk" repo_name = "devsoftkit" searchPath1 = [BaseEnv.base()] searchPath2 = [BaseEnv.user_home('eric')] print "SEARCHPATH",searchPath1,searchPath2 pi = PackInfo(packname) import tempfile import uuid tmp = os.path.join(tempfile.gettempdir(), "pack_%s" % uuid.uuid4().hex) todolist = BaseFileProc() rcRelease = pi.real_version_file(PackInfo,searchPath1) if rcRelease != None: toFile = os.path.join(searchPath2[0],pi.get_label(),packname+".py") fromFile = rcRelease.get_fullname() import re pat1 = re.compile("base_release\s*=") pat2 = re.compile("version\s*=") with open(fromFile, "rt") as fin: with open(tmp, "wt") as fout: for line in fin: m = pat1.search(line) if m: x = line.split("=")[1] x = x.strip() x = x.split(os.sep)[-1] x = x.replace("'","") x = x.replace('"',"") source_dev_path = os.path.join(dev_path,x) fout.write("base_release = %r\n" % source_dev_path) else: m = pat2.search(line) if m: fout.write('version = ""\n') else: fout.write(line) print(tmp) print("TOHOME",toFile) todolist.copy_envifile(tmp, toFile) todolist.delete_file(tmp) else: # make a blank from dsk.templates.template_envi import repo_pack toFile = os.path.join(searchPath2[0],pi.get_label(),packname+".py") print(tmp) print("TOHOME",toFile) data = repo_pack.DATA_PACK % {'rootname': os.path.join(dev_path,repo_name)} with open(tmp, "wt") as fout: fout.write(data) todolist.copy_envifile(tmp, toFile) todolist.delete_file(tmp) res_copy = todolist.execute_stop_first_failed(run_dry=run_dry, with_log = True) print(res_copy.success,res_copy.log)