Skip to content
Permalink
Browse files

Also port helper add-authors to python 3

Change-Id: I60c256f7c0dac95a9e83093b5496840635e05c85
  • Loading branch information...
LarsMichelsen committed Sep 10, 2019
1 parent afe70fd commit 2a60e1a5e0e7beb928e3651e27cfab7667399f1e
Showing with 22 additions and 22 deletions.
  1. +2 −2 locale/Makefile
  2. +18 −20 locale/add-authors
  3. +1 −0 omd/packages/python3-modules/python3-modules.make
  4. +1 −0 virtual-envs/3.7/Pipfile
@@ -43,9 +43,9 @@ cleanup-%:
sed -i '/"PO-Revision-Date:/d' $$L/LC_MESSAGES/multisite.po ; \
sed -i '/"Last-Translator:/d' $$L/LC_MESSAGES/multisite.po ; \

de:
de: ../virtual-envs/3.7/.venv
$(MAKE) update-$@
./add-authors $@
$(PIPENV) run ./add-authors $@
POEDITOR=$$(which poedit 2>/dev/null || which virtaal 2>/dev/null) ; \
if [ -z "$$POEDITOR" ]; then \
echo "ERROR: Unable to find PO file editor (poedit or virtual)" ; \
@@ -1,22 +1,21 @@
#!/usr/bin/python
#!/usr/bin/env python3

import os
import subprocess
import sys
import time
import polib


def update_po_file(lang):
cmd = ["make", "update-%s" % lang]
p = subprocess.Popen(cmd, stdout=file("/dev/null", "w"))
p = subprocess.Popen(cmd, stdout=open("/dev/null", "w", encoding="utf-8"), encoding="utf-8")
if p.wait() != 0:
raise Exception("Command failed: %s" % " ".join(cmd))


def cleanup_po_file(lang):
cmd = ["make", "cleanup-%s" % lang]
p = subprocess.Popen(cmd, stdout=file("/dev/null", "w"))
p = subprocess.Popen(cmd, stdout=open("/dev/null", "w", encoding="utf-8"), encoding="utf-8")
if p.wait() != 0:
raise Exception("Command failed: %s" % " ".join(cmd))

@@ -25,7 +24,8 @@ def get_localizations_of_type_raw(po_file, ty):
p = subprocess.Popen(
["msgattrib", "--%s" % ty, "--no-obsolete", "--no-wrap", po_file],
stdout=subprocess.PIPE,
stderr=file("/dev/null", "w"))
stderr=open("/dev/null", "w", encoding="utf-8"),
encoding="utf-8")
stdout = p.communicate()[0]
if p.returncode != 0:
raise Exception("Command failed!")
@@ -55,8 +55,8 @@ def update_untranslated_with_last_commits(po_file):

try:
commit = get_last_commit_of(repo_basedir, path, int(line))
except Exception, e:
print "ERROR", po_entry.msgid, po_entry.linenum
except Exception:
print("ERROR", po_entry.msgid, po_entry.linenum)
raise

if not hasattr(po_entry, "commits"):
@@ -75,28 +75,26 @@ def update_untranslated_with_last_commits(po_file):
po.save()


def get_last_commit_of(repo_path, path, line):
def get_last_commit_of(repo_base_path, path, line):
env = os.environ.copy()
env["GIT_DIR"] = repo_path + "/.git"
env["GIT_WORK_TREE"] = repo_path
env["GIT_DIR"] = repo_base_path + "/.git"
env["GIT_WORK_TREE"] = repo_base_path

cmd = ["git", "blame", "-p", "-L%d,+1" % line, path]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env)
stdout = p.communicate()[0].decode("utf-8")
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env, encoding="utf-8")
stdout = p.communicate()[0]
if p.returncode != 0:
raise Exception("Command failed: %s" % " ".join(cmd))

commit_id = stdout.split("\n",)[0].split(" ", 1)[0]

msg, name, mail = None, None, None
for line in stdout.split("\n"):
if line.startswith("summary "):
msg = line.split(" ", 1)[1].strip()
elif line.startswith("author "):
name = line.split(" ", 1)[1].strip()
elif line.startswith("author-mail "):
mail = line.split(" ", 1)[1].strip("<>\n")
msg, name = None, None
for ln in stdout.split("\n"):
if ln.startswith("summary "):
msg = ln.split(" ", 1)[1].strip()
elif ln.startswith("author "):
name = ln.split(" ", 1)[1].strip()

return commit_id, name, msg

@@ -117,6 +117,7 @@ python3-modules-dump-Pipfile:
@echo 'pytest-cov = "*" # used (indirectly) by test/Makefile'"'"'s test-unit-coverage-html target, see comment there'
@echo 'pytest-mock = "*" # used by quite a few unit/integration tests via the mocker fixture'
@echo 'yapf = "*" # used for editor integration and the format-python Makefile target'
@echo 'polib = "*" # used by locale/add-authors for working with .po files'
@echo ''
@echo '[packages]'
@echo $(patsubst %.zip,%,$(patsubst %.tar.gz,%,$(PYTHON3_MODULES_LIST))) | tr ' ' '\n' | sed 's/-\([0-9.]*\)$$/ = "==\1"/'
@@ -23,6 +23,7 @@ pytest = "*" # used by various test/Makefile targets
pytest-cov = "*" # used (indirectly) by test/Makefile's test-unit-coverage-html target, see comment there
pytest-mock = "*" # used by quite a few unit/integration tests via the mocker fixture
yapf = "*" # used for editor integration and the format-python Makefile target
polib = "*" # used by locale/add-authors for working with .po files

[packages]
setuptools_scm = "==3.3.3" # needed by various setup.py

0 comments on commit 2a60e1a

Please sign in to comment.
You can’t perform that action at this time.