コード例 #1
0
    def init_with_cmd(self, listOfCmd, loginfo=None):
        """Get the environment from a command
        """
        # sys.stderr.write("list of command %s" % "X".join(listOfCmd))
        assert isinstance(listOfCmd, list)
        self.reset()
        rev = ""
        timeString = ""
        if loginfo:
            rev = loginfo.name
            # build a temp area to check out config
            timeString = "%s%s%s" % (loginfo.day, MiniEnv._sepDateTime,
                                     loginfo.time)

        allE = list()
        for cmdList in listOfCmd:
            e = MiniEnv()
            allE.insert(0, e)
            if timeString != "":
                # add the revision and the time
                e.parse_cmd(cmdList + " -r %s -t %s" % (rev, timeString))
            else:
                e.parse_cmd(cmdList)

            self._configFound.update(e.get_config_found())
            self.add_command(cmdList)

        inAllready = dict()
        for e in allE:
            #  loading the pack, and build the environment
            for k, v in reversed(list(e.get_pack_found().items())):
                rc = PackInfo(k, v)
                if rc.base not in inAllready:
                    self.packsObject.insert(0, rc)
                    inAllready[rc.base] = None

        self.set_init_pack_name_list([x.name for x in self.packsObject])
        self._commands = listOfCmd
        self.configsObject = [
            ConfigInfo(x, self._configFound[x]) for x in self._configFound
        ]

        return True
コード例 #2
0
ファイル: mini_env.py プロジェクト: erictexier/dskenvi
    def parse_cmd(self, argListOrStr):
        # to support 2.6 and 2.7

        if sys.version_info.major > 2 or sys.version_info.minor >= 7:
            args = self.parse_cmd_base(argListOrStr)
        else:
            args = self.parse_cmd_base26(argListOrStr)

        # args = self.parse_cmd_base(argListOrStr)
        opt = args[0]

        clip_time = -1

        if opt.date != "":
            res = opt.date.split("%s" % MiniEnv._sepDateTime)  # separator /
            if len(res) == 2:
                clip_time = EnviUtils.convert_date_and_time_to_float_time(
                                                                res[0], res[1])
            else:
                clip_time = EnviUtils.convert_date_and_time_to_float_time(
                                                                opt.date)
        configDir = ""

        for c in opt.configs:
            # check if the file has been check out
            a = ConfigInfo(BaseEnv.clean(c), None)
            if configDir != "":
                rc = a.real_version_file(ConfigInfo, None)
            else:
                rc = a.real_version_file(ConfigInfo, self._searchPath)
            if rc is None or rc.is_valid() is False:
                if configDir != "":
                    comment.error("no config %r found in %s" % (c, configDir))
                    self.logfile("parse_cmd: no config %r found %s" % (
                                                        c, configDir))
                else:
                    comment.error("no config %r found in %s" % (
                                                        c, self._searchPath))
                    self.logfile("no config %r found in %s" % (
                                                        c, self._searchPath))
            else:
                if self.load_config_or_pack(rc.get_fullname()) is False:
                    comment.error("couldn't load successfully  %s" % (
                                                        rc.get_fullname()))
                    self.logfile("couldn't load successfully  %s" % (
                                                        rc.get_fullname()))
                else:
                    self._configFound[rc.name] = rc.path

        for p in opt.packs:
            # comment.error("----> pack %r" % p)
            self.addPack(BaseEnv.clean(p))

        for pc in self._packListName:
            # comment.error("----> pack %r %r" % (pc,self._searchPath))
            pf = PackInfo(pc, None)
            rc = pf.real_version_file(PackInfo,
                                      self._searchPath,
                                      clip_time)
            if rc is None or rc.is_valid() is False:
                # pc maybe with the all name
                try:
                    # comment.error("pc = %s" % (pc))
                    xx = BaseEnv.pack_info(replaceMain=False)
                    search = ""
                    for x in xx:
                        if x[0].startswith(pc):
                            search = os.path.dirname(x[1])
                            break
                    if search != "":
                        rc = PackInfo(pc, search)
                        if rc is None or rc.is_valid() is False:
                            comment.error("===>no pack %r found in %s" % (
                                                            pf, [search]))
                            self.logfile("===>no pack %r found in %s" % (
                                                            pf, [search]))
                        else:
                            self._packFound[rc.name] = rc.path
                    else:
                        comment.error("no pack1 %r found in %s" % (
                                                        pc, self._searchPath))
                        self.logfile("no pack %r found in %s" % (
                                                        pc, self._searchPath))
                except Exception as e:
                    comment.error("no pack2 %r found in %s" % (
                                                        pc, self._searchPath))
                    comment.error(str(e))
                    self.logfile("no pack %r found in %s" % (
                                                        pc, self._searchPath))
                    self.logfile(str(e))
            else:
                self._packFound[rc.name] = rc.path
コード例 #3
0
    def info_from_environment(self):
        """Read the environment and find a sequence of cmd to create it
        the result is not unique
        """
        self.reset()

        ################################
        # read from environment
        helper = BaseEnv()
        # read configs from environment variable
        configsEnv = [ConfigInfo(x[0], x[1]) for x in helper.config_info()]
        # packs pack
        packsEnv = [
            PackInfo(x[0], x[1]) for x in helper.pack_info(replaceMain=True)
        ]
        initData = [[
            x,
        ] for x in packsEnv]
        packsDict = OrderedDict(list(zip([x.name for x in packsEnv],
                                         initData)))
        ################################

        # raw config dict
        rawConfig = OrderedDict()

        # loading empty config so we see the type of pack available
        # we also build a list of founded file to get the real version from
        # disk and deal with wild version in pack name -?.?
        for cfg in configsEnv:
            newC = MiniEnv()
            rawConfig[cfg.name] = newC
            fullPathName = cfg.get_file(cfg.path, -1)

            newC.set_dev_name(cfg.owner())
            if fullPathName != "":
                newC.load_config_or_pack(fullPathName)
            else:
                log.error("cannot figure out the path for %r" % cfg.name)

            for pa in newC.get_pack_name_list():
                v = VersionHelper(pa)
                for rv in packsDict:
                    rvp = packsDict[rv][0]
                    if v.is_similar(rvp):
                        pp = v.get_file(rvp.path, -1)
                        if pp != "":
                            p, realname = os.path.split(pp)
                            newC._packFound[realname.replace(".py", "")] = p
                        else:
                            # comment.debug("could not find the file %s" % pa)
                            # we take the name of the file
                            newC._packFound[rvp.name] = rvp.path
                        break

        # we read the config in reversed order and
        # mark the pack with the config that loaded them
        for rcn, conf in reversed(list(rawConfig.items())):
            llp = list()
            for x in conf.get_pack_name_list():
                llp.append(VersionHelper(x))
            for lp in llp:
                for i in packsDict:
                    if lp.is_similar(packsDict[i][0]):
                        packsDict[i].append(rcn)
                        break

        currentConfig = list()
        lateAddPack = list()

        # NOTES: it seems that when configs and pack get loaded at
        # the same time, the config take precedence
        # i don't think it should, but this code consider it
        # by adding extra command

        for keyPack in packsDict:
            theConfigs = packsDict[keyPack][1:]
            for c in theConfigs:
                if c not in currentConfig:
                    currentConfig.append(c)
            if len(theConfigs) == 0:  # no config where adding this
                lateAddPack.append(
                    ('', keyPack, packsDict[keyPack][0].owner()))
            else:
                # here we check the validity to detect late 'addPack'
                # check if the last enter current config is compatible:
                # check ownership
                needExtraPack = False
                curConfName = currentConfig[-1]
                aconf = rawConfig[curConfName]  # -1 for last in
                if keyPack not in aconf._packFound:
                    needExtraPack = True

                owner = packsDict[keyPack][0].owner()
                cowner = conf.dev_name()

                if owner != '':
                    if owner != cowner:
                        if cowner == '' and needExtraPack is False:
                            # we mark the config as needing the -d flag
                            # we don't do this for now, since we have
                            # to split the commandLine
                            # aconf.setDevName(owner)
                            lateAddPack.append((curConfName, keyPack, owner))
                        else:
                            lateAddPack.append((curConfName, keyPack, owner))
                elif needExtraPack:
                    lateAddPack.append((curConfName, keyPack, ''))

        # build the command line
        CmdLine = OrderedDict()

        for rcn, conf in list(rawConfig.items()):
            CmdLine[rcn] = list()
            dv = conf.dev_name()
            if dv != "":
                CmdLine[rcn].append('-D %s' % dv)
            CmdLine[rcn].append('-c %s' % rcn)
            # add the pack into a new command
            self.do_extra_pack(rcn, lateAddPack, CmdLine)

        if len(lateAddPack) > 0:
            # just to keep the orphane pack at the end
            self.do_extra_pack('', lateAddPack, CmdLine, pickup=True)

        CmdLineFinal = OrderedDict()
        for i in CmdLine:
            if len(CmdLine[i]) > 0:
                CmdLineFinal[i] = " ".join(CmdLine[i])

        # init the basic to stay consistent with a state
        self.configsObject = configsEnv
        # remove the dummy pack
        self.packsObject = packsEnv
        self._commands = list(CmdLineFinal.values())

        return True
コード例 #4
0
    def pack_checkout(self, fromdir, todir, packname, dev_path, repo_name):
        """Create a packname in user area

        :param    fromdir: (str path)  an envi release place ex: BaseEnv.base()
        :param    todir: (str path) an envi user_place ex: BaseEnv.user_home('eric')
        :param    packname: (str) the name of the pack
        :param    dev_path: (str path) top dev user git area
                              ex: /mnt/dev/${USER}/packages
                              (see: $DSKENV/configs_and_packs/envi_info.yml)
        :param    repo_name: (str) dir name of the repo. ex: mgtk-multi-setuptools
        :returns ResultFileProc:

        """
        if not os.path.isdir(todir):
            new_user_pack_area = os.path.join(todir, PackInfo.get_label())

            FileSystemUtils.ensure_folder_exists(
                os.path.dirname(new_user_pack_area), permissions=0o775)

            log.info(
                "create a user pack area in {}".format(new_user_pack_area))

        if not os.path.isdir(todir):
            return ResultFileProc(False, ["Doesn't exist %s" % todir], [],
                                  None)

        searchPath1 = [fromdir]
        searchPath2 = [todir]

        pi = PackInfo(packname)
        tmp = os.path.join(tempfile.gettempdir(), "pack_%s" % uuid.uuid4().hex)

        todolist = BaseFileProc()
        # build up the new pack file
        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()

            foundR = foundV = False

            with open(fromFile, "rt") as fin:
                with open(tmp, "wt") as fout:
                    for line in fin:
                        if foundR and foundV:
                            fout.write(line)
                            continue
                        m = self.__pat_release.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)
                            foundR = True
                        else:
                            m = self.__pat_version.search(line)
                            if m:
                                fout.write('version = ""\n')
                                foundV = True
                            else:
                                m = self.__pat_version_repo.search(line)
                                if m:
                                    fout.write('version_repo = ""\n')
                                    foundV = True
                                else:
                                    fout.write(line)

            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")

            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=False,
                                                      with_log=True)
        return res_copy
コード例 #5
0
    def pack_commit(self,
                    fromdir,
                    todir,
                    packname,
                    top_release_path,
                    repo_name,
                    version,
                    with_version=True):
        """

        :param fromdir: (str path) an envi user_place ex: BaseEnv.user_home('eric')
        :param todir: (str path)  an envi release place ex: BaseEnv.base()
        :param packname: (str) the name of the pack
        :param top_release_path: (str path) the release area of all repo:
                              ex: /mnt/dev/${USER}/packages
        :param repo_name: (str)  dir name of the repo. ex: mgtk-multi-setuptools
        :param version:   (str)  version ex: v0.0.8
        :param with_version=True  NOT DONE
        :return ResultFileProc:

        """

        if not os.path.isdir(todir):
            return ResultFileProc(False, ["Doesn't exist %s" % todir], [],
                                  None)

        searchPath1 = [todir]
        if not isinstance(fromdir, list):
            searchPath2 = [fromdir]
        else:
            searchPath2 = fromdir

        fromFile = toFile = ""

        pi = PackInfo(packname)
        rcHome = pi.real_version_file(PackInfo, searchPath2)
        if rcHome != None:
            fromFile = rcHome.get_fullname()
        else:
            rcRelease = pi.real_version_file(PackInfo, searchPath1)
            if rcRelease == None:
                err = "Cannot find a valid pack {}".format(packname)
                log.error(err)
                return ResultFileProc(False, [err], [], None)
            fromFile = rcRelease.get_fullname()

        # build up the new pack file
        release_path = ""
        tmp = os.path.join(tempfile.gettempdir(), "pack_%s" % uuid.uuid4().hex)
        foundR = foundV = False
        with open(fromFile, "rt") as fin:
            with open(tmp, "wt") as fout:
                for line in fin:
                    if foundR and foundV:
                        fout.write(line)
                        continue
                    m = self.__pat_release.search(line)
                    if m and m.start() == 0:
                        release_path = os.path.join(top_release_path,
                                                    repo_name)
                        fout.write('base_release = "%s"\n' % release_path)
                        foundR = True
                    else:
                        m = self.__pat_version.search(line)
                        if m and m.start() == 0:
                            fout.write('version = "%s"\n' % version)
                            foundV = True
                        else:
                            m = self.__pat_version_repo.search(line)
                            if m and m.start() == 0:
                                fout.write('version_repo = "%s"\n' % version)
                                foundV = True
                            else:
                                fout.write(line)

        todolist = BaseFileProc()
        rcRelease = pi.real_version_file(PackInfo, searchPath1)
        if rcRelease == None:
            rcHome.version_up_minor()
            toFile = rcHome.get_fullname()
            # repath
            toFile = toFile.replace(searchPath2[0], searchPath1[0])
            if not with_version:
                x = VersionHelper(toFile)
                x.unversioned()
                toFile = x.format()
            todolist.copy_envifile(tmp, toFile)

        else:
            rcRelease.version_up_minor()
            toFile = rcRelease.get_fullname()
            if not with_version:
                x = VersionHelper(toFile)
                x.unversioned()
                toFile = x.format()
            todolist.copy_envifile(tmp, toFile)

        log.info("Creating new pack from: {} to: {}".format(fromFile, toFile))

        todolist.delete_file(tmp)
        res_copy = todolist.execute_stop_first_failed(run_dry=False,
                                                      with_log=True)
        return res_copy
コード例 #6
0
ファイル: test_envi.py プロジェクト: erictexier/dsksoftkit
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)
コード例 #7
0
ファイル: test_envi.py プロジェクト: erictexier/dsksoftkit
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)