Commit e475e39d authored by Hefee's avatar Hefee

move logging into configfile.

parent ea519d08
......@@ -10,11 +10,18 @@
# DJANGO_IS_MANAGEMENT_COMMAND=1
# python /var/lib/weblate/repositories/home/save-suggestions.py
import logging
import logging.config
import os
import shutil
import subprocess
import sys
logging.config.fileConfig('saveSuggestions.conf')
logger = logging.getLogger('saveSuggestions')
sys.path.append("/usr/local/share/weblate")
from django.core.wsgi import get_wsgi_application
......@@ -24,25 +31,34 @@ from weblate.trans.models import *
TMPDIR="/var/lib/weblate/repositories/vcs/staging/"
subprocess.call(["git","reset",'HEAD',"--hard"], cwd=TMPDIR)
subprocess.call(["git","clean","-fdx"], cwd=TMPDIR)
subprocess.call(["git","pull"], cwd=TMPDIR)
# sys.exit(-1) # test if the previous git commands work
logger.info("Start a new run.")
try:
subprocess.check_call(["git","reset",'HEAD',"--hard"], cwd=TMPDIR)
subprocess.check_call(["git","clean","-fdx"], cwd=TMPDIR)
subprocess.check_call(["git","pull"], cwd=TMPDIR)
except:
logger.exception("Got an exception")
raise
len_subprojects = len(SubProject.objects.all())
subprojects = list(SubProject.objects.all())
for i in range(len_subprojects):
subproject = subprojects[i]
print("[{}/{}] {}".format(i+1, len_subprojects, subproject.name))
for translation in subproject.translation_set.all():
for unit in translation.unit_set.all():
if unit.suggestions():
s = list(unit.suggestions())[-1]
print(translation.language, unit.target, s.target)
# weblate/trans/models/translations.py: update_units
pounit, add = translation.store.find_unit(unit.context, unit.get_source_plurals()[0])
pounit.set_target(s.target) # update po file with first suggestion
# save with suggestions
with open(TMPDIR+"/"+translation.filename, "wb") as f:
translation.store.store.serialize(f)
# now: build the wiki :)
\ No newline at end of file
try:
for translation in subproject.translation_set.all():
for unit in translation.unit_set.all():
if unit.suggestions():
s = list(unit.suggestions())[-1]
# weblate/trans/models/translations.py: update_units
pounit, add = translation.store.find_unit(unit.context, unit.get_source_plurals()[0])
pounit.set_target(s.target) # update po file with first suggestion
# save with suggestions
with open(TMPDIR+"/"+translation.filename, "wb") as f:
translation.store.store.serialize(f)
# now: build the wiki :)
except:
logger.exception("Got an exception for %s(%i)", subproject.name, i)
raise
logger.info("Successfully updated %s.", TMPDIR)
......@@ -2,6 +2,7 @@
import git
import logging
import logging.config
import os
import os.path
import pathlib
......@@ -27,22 +28,9 @@ def weblateComponentFile(filename, tree):
return False
return False
# log to file
fh = logging.FileHandler('/var/lib/weblate/repositories/home/update.log')
fh.setLevel(logging.DEBUG)
# Format logging
ch = logging.StreamHandler()
ch.setLevel(logging.INFO) # Change to DEBUG if you wnat to see debug messages
formatter = logging.Formatter('%(levelname)s: %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
logging.config.fileConfig('updateWeblateComponents.conf')
logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)
logger.addHandler(fh)
# DJANGO/WEBLATE setup to be able to change stuff within weblate
sys.path.insert(0,"/usr/local/share/weblate")
......@@ -159,4 +147,4 @@ for added_file in diff.iter_change_type('A'):
for directory in rescanDirs:
logger.info("searching for new components in {}".format(directory))
runImportProject(directory)
\ No newline at end of file
runImportProject(directory)
[loggers]
keys=root
[handlers]
keys=consoleHandler, fileHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler, fileHandler
[handler_consoleHandler]
class=StreamHandler
level=ERROR
formatter=simpleFormatter
args=(sys.stdout,)
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
args=('/var/lib/weblate/repositories/home/update.log', 'w')
[formatter_simpleFormatter]
format=%(asctime)s - %(name)s(%(levelname)s): %(message)s
datefmt=
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