rbutil: Add option to langstat to pass git hash.

Don't always operate on the remote head, instead default to the local
HEAD, and allow passing a hash to use for calculating statistics.

Change-Id: I420308e66769689c1dfac56e19058b097a0533a2
This commit is contained in:
Dominik Riebeling 2020-12-15 20:49:18 +01:00
parent eaf86a22d3
commit 65d0867a25
2 changed files with 7 additions and 6 deletions

View file

@ -65,18 +65,20 @@ def main():
description='Print translation statistics for pasting in the wiki.') description='Print translation statistics for pasting in the wiki.')
parser.add_argument('-p', '--pretty', action='store_true', parser.add_argument('-p', '--pretty', action='store_true',
help='Display pretty output instead of wiki-style') help='Display pretty output instead of wiki-style')
parser.add_argument('-c', '--commit', nargs='?', help='Git commit hash')
args = parser.parse_args() args = parser.parse_args()
langstat(args.pretty) langstat(args.pretty, args.commit)
def langstat(pretty=True): def langstat(pretty=True, tree=None):
'''Get translation stats and print to stdout.''' '''Get translation stats and print to stdout.'''
# get gitpaths to temporary folder # get gitpaths to temporary folder
workfolder = tempfile.mkdtemp() + "/" workfolder = tempfile.mkdtemp() + "/"
repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
tree = gitscraper.get_refs(repo)['refs/remotes/origin/master'] if tree is None:
tree = gitscraper.get_refs(repo)['HEAD']
filesprops = gitscraper.scrape_files( filesprops = gitscraper.scrape_files(
repo, tree, GITPATHS, dest=workfolder, repo, tree, GITPATHS, dest=workfolder,
timestamp_files=["rbutil/rbutilqt/lang"]) timestamp_files=["rbutil/rbutilqt/lang"])
@ -130,8 +132,7 @@ def langstat(pretty=True):
"| *Done* |") "| *Done* |")
# scan output # scan output
for i in range(len(lines)): for i, line in enumerate(lines):
line = lines[i]
if re_updating.search(line): if re_updating.search(line):
lang = re_qmlang.findall(line) lang = re_qmlang.findall(line)
tsfile = "rbutil/rbutilqt/lang/%s.ts" % re_qmbase.findall(line)[0] tsfile = "rbutil/rbutilqt/lang/%s.ts" % re_qmbase.findall(line)[0]

View file

@ -43,7 +43,7 @@ def get_refs(repo):
''' '''
print("Getting list of refs") print("Getting list of refs")
output = subprocess.Popen( output = subprocess.Popen(
["git", "show-ref", "--abbrev"], ["git", "show-ref", "--abbrev", "--head"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=repo) stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=repo)
cmdout = output.communicate() cmdout = output.communicate()
refs = dict() refs = dict()