Commit 6f6c9409 authored by Julien Pivotto's avatar Julien Pivotto

Update Pox-py

Signed-off-by: Julien Pivotto's avatarJulien Pivotto <roidelapluie@inuits.eu>
parent f6c63a7e
......@@ -2,7 +2,8 @@
"""lingvoj.py
Usage:
tox.py <sourcedir>
tox.py post-update <sourcedir>
tox.py pre-commit <sourcedir>
Options:
sourcedir: Path to the source directory
......@@ -20,12 +21,60 @@ class Pox:
def __init__(self, directory):
self.directory = directory
def run(self):
def precommit(self):
self.walk_into_dirs()
return 0
def walk_into_dirs(self):
def postupdate(self):
self.walk_into_dirs(True)
return 0
def regen_pofiles(self, generate_pot=True):
for dirpath, _, filenames in os.walk('.'):
if 'locale.pot' in filenames:
logging.debug('Pot in %s' % dirpath)
potfiles = self.get_pot_files(filenames)
for potfilename in potfiles:
orig_filename = '%s.en.xhtml' % (potfilename.split('.')[1])
command = ['html2po',
os.path.join(dirpath, orig_filename),
'-P',
os.path.join(dirpath, potfilename)]
subprocess.call(command)
logging.info('Running %s' % ' '.join(command))
try:
command = ['git', 'add', os.path.join(dirpath, potfilename)]
logging.info('Running %s' % ' '.join(command))
subprocess.call(command)
except:
pass
if len(potfiles) > 1:
command = ['msgcat'] + potfiles + ['-o'] + os.path.join(dirpath, 'locale.pot')
logging.info('Running %s' % ' '.join(command))
subprocess.call(command)
try:
command = ['git', 'add', os.path.join(dirpath, 'locale.pot')]
logging.info('Running %s' % ' '.join(command))
subprocess.call(command)
except:
pass
pofiles = self.get_po_files(filenames)
for pofile in pofiles:
command = ['msgmerge', '-U', os.path.join(dirpath, pofile), os.path.join(dirpath, 'locale.pot')]
logging.info('Running %s' % ' '.join(command))
subprocess.call(command)
try:
command = ['git', 'add', os.path.join(dirpath, pofile)]
logging.info('Running %s' % ' '.join(command))
subprocess.call(command)
except:
pass
def walk_into_dirs(self, generate_pot=False):
os.chdir(self.directory)
if generate_pot:
self.regen_pofiles()
for dirpath, _, filenames in os.walk('.'):
if 'locale.pot' in filenames:
logging.debug('Pot in %s' % dirpath)
......@@ -55,6 +104,7 @@ class Pox:
except:
pass
def is_pofile_translated_for_file(self, pofile, filename):
result = False
for unit in pofile.unit_iter():
......@@ -109,7 +159,10 @@ class Pox:
def main():
arguments = docopt(__doc__, version='0.1')
srcdir = arguments['<sourcedir>']
exit(Pox(srcdir).run())
if arguments['pre-commit']:
exit(Pox(srcdir).precommit())
elif arguments['post-update']:
exit(Pox(srcdir).postupdate())
if __name__ == '__main__':
......
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