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]
def __init__(self, conf): self.conf = conf logger.debug("parser: self.conf=" + str(self.conf)) if("files" in self.conf): if(type(self.conf["files"]) is list or type(self.conf["files"]) is tuple): for f in self.conf["files"]: if(not os.path.exists(f)): raise IOError("Could not access file %s. Please check path and/or your rights ont that file." % f) elif(os.path.isdir(f)): raise NotImplementedError("%s is a directory!" % f) self.conf["files"] = list(self.conf["files"]) elif(type(self.conf["files"]) is str or type(self.conf["files"]) is unicode): f = self.conf["files"] if(os.path.isdir(f)): raise NotImplementedError("%s is a directory!" % f) elif(not os.path.exists(f)): raise IOError("Could not access file %s. Please check path and/or your rights ont that file." % f) self.conf["files"] = [f, ] else: raise RuntimeError("Could not determine type of given data") else: raise ValueError("You have not given any file to parse!") if("style" not in self.conf): raise ValueError("No style given") if("current_version" in self.conf): if(type(self.conf["current_version"]) is not str and type(self.conf["current_version"]) is not unicode): raise RuntimeError("current_version is not a string!") else: raise ValueError("Could not find current version. This may lead to serious things. I would personnaly prefere that you use a correct self.configuration file.")
def __init__(self, current_version): logger.debug("style = " + str(current_version)) self.regex = re.compile(self.__format__) self.current_version = current_version if self.regex.match(self.current_version) is None: raise ValueError( "The current version you provided does not correspond to the chosen version style. Please review your configuration file and/or your cli args." )
def get_pure_version_string(style_class, string): """ Returns only the part matching the version string, so we can isolate it in a string """ match = re.search(style_class.__format__, string) logger.debug("regex: %s, string %s, match object: %s" % (style_class.__format__, string, str(match))) if match: return string[match.start() : match.end()] return None
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])
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.")
def get_status(self): self._update_index() if(self.status is None): logger.debug("Self.status is None. Updating... result:" + self._get_describe()) logger.debug("self.status is %d long" % len(self.status)) if(len(self.status) >= 3): logger.debug(self.status[1:]) return "-pre%s-%s" % (self.status[1], self.status[2]) else: return ""
def _get_describe(self, increment=True): s = str(check_output(["git", "describe", "--tags", "--dirty"])) logger.debug(str(type(s)) + " " + s) self.status = [str(s) for s in s.strip('\n').split('-')] # check_output returns bytes logger.debug("self.status = " + str(self.status)) if(len(self.status) > 1 and self.status[1] != "dirty" and increment): logger.debug(self.status[0]) self.status[0] = self.style( self.style.get_pure_version_string( self.style, self.status[0] ) ).increment() else: self.status[0] = self.style.get_pure_version_string( self.style, self.status[0] ) return self.status