Commit 2602961b authored by Sandro Knauß's avatar Sandro Knauß Committed by zen

Weblate: Process rename of update_weblate_git

parent b8eac8c7
......@@ -35,7 +35,7 @@ FAIL: remote and master are on the same commit
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/puppet-tails/files/weblate/scripts/tests/test_update_weblate_git.py", line 249, in test_nothing_to_do
uwg.main(self.repopath, "master", "remote-1", "remote-1")
mcc.main(self.repopath, "master", "remote-1", "remote-1")
AssertionError: no logs of level DEBUG or higher triggered on update_weblate_git
----------------------------------------------------------------------
......
......@@ -28,7 +28,7 @@ import pathlib
logger = logging.getLogger(__name__)
parser = None
prog = 'update-weblate-git'
prog = 'merge_canonical_changes'
temporaryDirectory = lambda x: tempfile.TemporaryDirectory()
......@@ -594,7 +594,7 @@ def commandline():
debugPath = pathlib.Path("__debug")
logging.config.fileConfig('/var/lib/weblate/config/updateWeblateGit.conf')
logging.config.fileConfig('/var/lib/weblate/config/mergeCanonicalChanges.conf')
logger = logging.getLogger('')
logger.level = logging.INFO
......
......@@ -22,7 +22,7 @@ import subprocess
import tempfile
import pathlib
import merge_canonical_changes as uwg
import merge_canonical_changes as mcc
logger = logging.getLogger(__name__)
parser = None
......@@ -47,14 +47,14 @@ def mergePo(origPath, lang, output):
unchanged = path/'unchanged'
# get only header of pot file
header.write_bytes(uwg.poHeader(pot.read_bytes()))
header.write_bytes(mcc.poHeader(pot.read_bytes()))
# messages changed on local/remote
localChanges.write_bytes(uwg.extractChanges(local, base))
remoteChanges.write_bytes(uwg.extractChanges(remote, base))
localChanges.write_bytes(mcc.extractChanges(local, base))
remoteChanges.write_bytes(mcc.extractChanges(remote, base))
# unchanged messages
unchanged.write_bytes(uwg.unchangedChanges(base, local, remote))
unchanged.write_bytes(mcc.unchangedChanges(base, local, remote))
# messages changed on local, not on remote; and vice-versa
unique = subprocess.run(['msgcat', '-o', '-', '--unique', str(localChanges), str(remoteChanges)],
......@@ -100,13 +100,13 @@ def main(repopath, local, localCommit, remote):
try:
local = r.refs[local]
except IndexError:
uwg.logInputError('{} is not a valid git reference.'.format(local))
mcc.logInputError('{} is not a valid git reference.'.format(local))
if localCommit:
try:
local.commit = r.commit(localCommit)
except git.BadName:
uwg.logInputError('{} is not a valid git reference.'.format(local))
mcc.logInputError('{} is not a valid git reference.'.format(local))
local.checkout()
......@@ -123,7 +123,7 @@ def main(repopath, local, localCommit, remote):
try:
remote = r.commit(remote)
except git.BadName:
uwg.logInputError('{} is not a valid git reference or a commit.'.format(remote))
mcc.logInputError('{} is not a valid git reference or a commit.'.format(remote))
logger.info("remote: %s", remote)
......@@ -136,7 +136,7 @@ def main(repopath, local, localCommit, remote):
logger.info("base: %s", base[0])
# create index to prepare the merge
index = uwg.Index(git.IndexFile.from_tree(r, base, local, remote))
index = mcc.Index(git.IndexFile.from_tree(r, base, local, remote))
# is a fast-forward possible
ff_possible_local = (base[0] == local.commit) # remote branch has commits on top of local
......@@ -179,7 +179,7 @@ def main(repopath, local, localCommit, remote):
index.removeFile(path)
continue
if not uwg.isWikiPo(path):
if not mcc.isWikiPo(path):
# Reset file, that is not allowed to be touched by Weblate.
m = "{path}: reset (Weblate is only to touch po files).\n".format(path=path)
logger.debug(m.strip())
......@@ -201,12 +201,12 @@ def main(repopath, local, localCommit, remote):
with temporaryDirectory(path) as tempdir:
temppath = pathlib.Path(tempdir)
potpath = path
(temppath/'pot').write_bytes(uwg.pot(local.commit.tree/potpath))
uwg.msguniq(remote.tree/path, temppath/'remote')
uwg.msguniq(local.commit.tree/i.a_path, temppath/'local')
uwg.msguniq(base[0].tree/i.a_path, temppath/'base')
(temppath/'pot').write_bytes(mcc.pot(local.commit.tree/potpath))
mcc.msguniq(remote.tree/path, temppath/'remote')
mcc.msguniq(local.commit.tree/i.a_path, temppath/'local')
mcc.msguniq(base[0].tree/i.a_path, temppath/'base')
mergePo(temppath, uwg.getLang(path), repopath/path)
mergePo(temppath, mcc.getLang(path), repopath/path)
index.removeFile(path)
index.add([path])
......
......@@ -17,13 +17,13 @@ from .utils import createRepo
@contextlib.contextmanager
def testConfig():
config = uwc.uwg.config
config = uwc.mcc.config
path = pathlib.Path(os.path.realpath(__file__))
uwc.uwg.config = uwc.uwg.Config([path.with_name("testlangs.json")])
uwc.mcc.config = uwc.mcc.Config([path.with_name("testlangs.json")])
try:
yield
finally:
uwc.uwg.config = config
uwc.mcc.config = config
def configDecorator(func):
@functools.wraps(func)
......
......@@ -7,7 +7,7 @@ import logging.config
import pathlib
import tailsWeblate
import merge_canonical_changes as uwg
import merge_canonical_changes as mcc
BASEPATH = "wiki/src"
......@@ -15,10 +15,10 @@ logger = logging.getLogger(__name__)
def deleteComponent(fpath):
if not uwg.isWikiPo(fpath):
if not mcc.isWikiPo(fpath):
logger.debug("deleted file (ignoring): {}".format(fpath))
return
if uwg.getLang(fpath) != uwg.config.defaultlang:
if mcc.getLang(fpath) != mcc.config.defaultlang:
logger.debug("deleted file (ignoring, wrong lang): {}".format(fpath))
return
logger.info("deleted component: {}".format(fpath))
......@@ -29,10 +29,10 @@ def deleteComponent(fpath):
def renameComponent(source, target, remote_master):
if not uwg.isWikiPo(target):
if not mcc.isWikiPo(target):
logger.debug("renamed file (ignoring): {} -> {}".format(source, target))
return
if uwg.getLang(target) != uwg.config.defaultlang:
if mcc.getLang(target) != mcc.config.defaultlang:
logger.debug("renamed file (ignoring, wrong lang): {} -> {}".format(source, target))
return
......@@ -45,10 +45,10 @@ def renameComponent(source, target, remote_master):
def addComponent(fpath, remote_master):
if not uwg.isWikiPo(fpath):
if not mcc.isWikiPo(fpath):
logger.debug("added file (ignoring): {}".format(fpath))
return
if uwg.getLang(fpath) != uwg.config.defaultlang:
if mcc.getLang(fpath) != mcc.config.defaultlang:
logger.debug("added file (ignoring, wrong lang): {}".format(fpath))
return
logger.info("added component: {}".format(fpath))
......@@ -60,7 +60,7 @@ def addComponent(fpath, remote_master):
def updateComponent(fpath):
if not uwg.isWikiPo(fpath):
if not mcc.isWikiPo(fpath):
logger.debug("modified file (ignoring): {}".format(fpath))
return
logger.info("modified file: {}".format(fpath))
......@@ -123,7 +123,7 @@ def perform_update(oldHead, newHead, remoteBranch):
else:
if subproject:
modifiedComponents[subproject.name] = subproject
loadpo[subproject.name].append(uwg.getLang(fpath))
loadpo[subproject.name].append(mcc.getLang(fpath))
# replaces manage.py loadpo call
for name, langs in loadpo.items():
......@@ -224,7 +224,7 @@ if __name__ == "__main__":
# Setup logging
logging.config.fileConfig('/var/lib/weblate/config/updateWeblateComponents.conf')
logger = logging.getLogger('')
uwg.logger = logging.getLogger('uwg')
mcc.logger = logging.getLogger('mcc')
try:
main()
......
......@@ -19,14 +19,14 @@ import pathlib
import sys
import tailsWeblate
import merge_canonical_changes as uwg
import merge_canonical_changes as mcc
PATH = pathlib.Path("/var/lib/weblate/repositories/vcs/tails/index")
repo = git.Repo(str(PATH))
index = uwg.Index(repo.index)
index = mcc.Index(repo.index)
tree = repo.tree()
LANGS = uwg.config.mainlangs + uwg.config.additionallangs
LANGS = mcc.config.mainlangs + mcc.config.additionallangs
LANGS.sort()
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
......@@ -97,12 +97,12 @@ uncompleteComponents = list(itertools.filterfalse(testlang, fileComponents.items
msg = "update weblate git using {}.\n\n".format(sys.argv[0])
for path, langs in uncompleteComponents:
defaultLangPath = path.with_name("{}.{}.po".format(path.name, uwg.config.defaultlang))
if uwg.config.defaultlang in langs:
defaultLangPath = path.with_name("{}.{}.po".format(path.name, mcc.config.defaultlang))
if mcc.config.defaultlang in langs:
logger.info('missing language files for {}'.format(path))
potFile = uwg.pot(tree/str(defaultLangPath))
potFile = mcc.pot(tree/str(defaultLangPath))
if args.modify:
msg += uwg.addNonMainGitLangs(defaultLangPath, potFile, PATH, index, overwriteExisting=False)
msg += mcc.addNonMainGitLangs(defaultLangPath, potFile, PATH, index, overwriteExisting=False)
else:
logger.info('language file leftovers for {}.'.format(path))
if args.modify:
......@@ -111,7 +111,7 @@ for path, langs in uncompleteComponents:
except KeyError:
pass
else:
msg += uwg.unlinkNonMainGitLangs(defaultLangPath, tree, index)
msg += mcc.unlinkNonMainGitLangs(defaultLangPath, tree, index)
for lang in langs:
(PATH/path.with_name("{}.{}.po".format(path.name, lang))).unlink()
del(fileComponents[path])
......
......@@ -339,10 +339,10 @@ class tails::weblate (
mode => '0750',
owner => weblate,
group => weblate_admin,
require => File["${mutable_data_dir}/config/updateWeblateGit.conf"],
require => File["${mutable_data_dir}/config/mergeCanonicalChanges.conf"],
}
file { "${mutable_data_dir}/config/updateWeblateGit.conf":
source => 'puppet:///modules/tails/weblate/config/updateWeblateGit.conf',
file { "${mutable_data_dir}/config/mergeCanonicalChanges.conf":
source => 'puppet:///modules/tails/weblate/config/mergeCanonicalChanges.conf',
mode => '0640',
owner => weblate,
group => weblate_admin,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment