Example #1
0
 def get_current_version(self, with_status=False, increment=True):
     self._update_index()
     logger.debug(self._get_describe(increment=increment))
     if(with_status):
         logger.info("".join((self.status[0], self.get_status())))
         return "".join((self.status[0], self.get_status()))
     return self.status[0]
Example #2
0
    def set_version(self, files, version, prefix=""):
        check_call(["git", "add", "version.conf"])  # This causes a problem, because in the current configuration, we don't save the version.conf file until the end of auto_version.main:main.
        add_cmd = ["git", "add"]
        if(type(files) is list or type(files) is tuple):
            for f in files:
                add_cmd.append(f)
        else:
            add_cmd.append(files)

        logger.debug(str(add_cmd))
        logger.info("Executing command: " + " ".join(add_cmd))
        check_call(add_cmd)
        check_call(["git", "commit", "-m", "auto_version: added files for whom version has changed."])
        check_call(["git", "tag", "-f", prefix + version])
Example #3
0
    def perform(self):
        """
        Performs the actual value replacement, according to the given parameters.

        .. attention::

            This may be quite long on large files!
        """

        self.vcs = detect_vcs()()
        style = self.get_style_class_from_str(self.conf["style"])
        self.vcs.style = style
        logger.info(self.conf["current_version"])
        if(self.conf["current_version"] == ""):
            self.conf["current_version"] = self.vcs.get_current_version(with_status=True, increment=False)
            logger.info("vcs version = " + self.conf["current_version"])
        if(self.conf["action"] == "update"):
            if(self.vcs is not None):
                new_version = self.vcs.get_current_version(with_status=True)  # FIXME
            else:
                raise NotImplementedError("It seems you are trying to do some versioning sync with a non-supported versioning system (Are you really using one on this project?) Please feel free to send an issue at https://github.com/paulollivier/auto_versioning !")
        else:
            try:
                style_instance = style(self.conf["current_version"])
                new_version = style_instance.increment(self.conf["action"])
            except:
                logger.info("Style instance reported error trying to process version number. Trying with SCM info")
                new_version = self.vcs.get_current_version(with_status=False, increment=False)
                style_instance = style(new_version)
                new_version = style_instance.increment(self.conf["action"])
        logger.info("old version:" + self.conf["current_version"] + " new version: " + new_version)
        for f in self.conf["files"]:
            data = ""
            with open(f, 'r') as fd:
                data = fd.read()
            for m in re.finditer(self.conf["current_version"], data):
                data = data.replace(self.conf["current_version"], new_version)
            with open(f, 'w+') as fd:
                fd.write(data)
        if(self.vcs and self.conf["commit"] and self.conf["action"] != "update"):
            logger.info("setting new version %s to SCM" % new_version)
            self.vcs.set_version(files=self.conf["files"], version=new_version, prefix=self.conf["scm_prefix"])

        return new_version
Example #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('action', default=None, help="The action to perform, eg. increment 'build', 'patch', 'rev' ... Please see documentation for full list")
    parser.add_argument('--files', '-f', nargs="+", help="the file[s] to check for version string[s]")
    parser.add_argument('--conf', default="version.conf", help="the configuration file to use")
    parser.add_argument('--current_version', "-cv", default="", help="The version string to use. WARNING: overrides the one provided in configuration file!")
    parser.add_argument('--commit', '-ci', action='store_true', default=False, help="If present, commits back the result of the version change")
    parser.add_argument("--verbose", "-v", action="count", default=0)
    parser.add_argument('--version', action='version', version='auto-version ' + __version__)

    args = vars(parser.parse_args())

    loglvl = args["verbose"]
    if(loglvl == 0):
        logger.setLevel(logging.ERROR)
    elif(loglvl == 1):
        logger.setLevel(logging.WARNING)
    elif(loglvl == 2):
        logger.setLevel(logging.INFO)
    elif(loglvl >= 3):
        logger.setLevel(logging.DEBUG)

    try:
        logger.info("Starting auto-version v" + __version__)
        cf = ConfManager(args)
        conf = cf.get_conf()
        logger.debug(str(conf))
        if("scm_prefix" in conf):
            p = BasicParser(files=conf["files"], style=conf["style"], action=conf["action"], current_version=conf["current_version"], scm_prefix=conf["scm_prefix"])
        else:
            p = BasicParser(files=conf["files"], style=conf["style"], action=conf["action"], current_version=conf["current_version"])
        conf["current_version"] = p.perform()
        del conf["verbosity"]
        del conf["action"]
        del conf["conf"]
        del conf["commit"]
        cf.save_conf(conf)
    except:
        logger.exception("Something went wrong! Please report the following info, go to https://github.com/paulollivier/auto-version, and fill in an issue.")