def parse_git_log_line(cls, a_string): """Scan a_string and parse out the tags and comment :param str a_string: Result from 'git log' after removing the version# """ data_dict = {"tags": [], "comment": a_string} if "(" not in a_string or ")" not in a_string: return data_dict start = indices(a_string, "(")[0] end = indices(a_string, ")")[0] if end < start: return data_dict data_dict["tags"] = a_string[start + 1:end].split(",") data_dict["comment"] = a_string[end + 1:].strip() return data_dict
def parse_git_log_line(cls, a_string): """Scan a_string and parse out the tags and comment :param str a_string: Result from 'git log' after removing the version # """ data_dict = {'tags': [], 'comment': a_string} if '(' not in a_string or ')' not in a_string: return data_dict start = indices(a_string, '(')[0] end = indices(a_string, ')')[0] if end < start: return data_dict data_dict['tags'] = a_string[start + 1:end].split(',') data_dict['comment'] = a_string[end + 1:].strip() return data_dict
def get_git_revision(cls, a_path): """Returns a populated data structure holding git version data. :param str a_path: Project base folder :return: Data structure holding git data :rtype: dict """ status_cmd = "git log --oneline -n1 --decorate " version_info, cmd_output = cls.get_scm_data("git", a_path, status_cmd, a_cwd=a_path) if version_info["error_msg"]: return version_info # Only process first line line = cmd_output.split("\n")[0] spaces = indices(line, " ") if not spaces: version_info["error_msg"] = "Command error: %s" % cmd_output version_info["version"] = line[:spaces[0]] parsed_data = cls.parse_git_log_line(line[spaces[0] + 1:]) version_info.update(parsed_data) version_info["status"] = True # get origin URL cmd_output, valid = SysUtils.get_command_output( "git remote get-url origin", arg_cwd=a_path) if not valid: version_info["error_msg"] = "Command error: %s" % cmd_output elif not cmd_output: version_info["error_msg"] = "Revision origin URL not found" else: version_info["url"] = cmd_output return version_info