1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 12:28:08 +01:00

Implement new commands to handle the xgettext/pybabel infrastructure

This commit is contained in:
David Paleino
2011-10-18 09:52:38 +02:00
parent bf648ab956
commit 7b200c52fc

View File

@@ -23,6 +23,7 @@ import os
import sys import sys
import shutil import shutil
import subprocess import subprocess
from glob import glob
# Be sure to keep this updated! # Be sure to keep this updated!
# VERSIONNUMBER # VERSIONNUMBER
@@ -388,6 +389,10 @@ class clear_generated(Command):
print 'Removed.' print 'Removed.'
else: else:
print 'Does not exist.' print 'Does not exist.'
print 'Removing compiled translation files...'
if os.path.exists('translations'):
shutil.rmtree('translations/')
os.makedirs('translations/')
class test(Command): class test(Command):
description = "run Wicd's unit tests" description = "run Wicd's unit tests"
@@ -422,8 +427,8 @@ class update_message_catalog(Command):
os.system('xgettext -L glade data/wicd.ui -j -o po/wicd.pot') os.system('xgettext -L glade data/wicd.ui -j -o po/wicd.pot')
class update_translations_py(Command): class compile_translations(Command):
description = "download new translations.py from the online translator" description = 'compile po-files to binary mo'
user_options = [] user_options = []
@@ -434,53 +439,15 @@ class update_translations_py(Command):
pass pass
def run(self): def run(self):
import urllib, shutil
# grab translations.py
filename, headers = urllib.urlretrieve('http://wicd.net/translator/generate/translations.py/')
# copy it into the right location
shutil.copyfile(filename,
os.path.join(os.path.dirname(os.path.realpath(__file__)),
'wicd/translations.py'))
class get_translations(Command):
description = "download the translations from the online translator"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import urllib, shutil
if os.path.exists('translations'): if os.path.exists('translations'):
shutil.rmtree('translations/') shutil.rmtree('translations/')
if os.path.exists('po'):
shutil.rmtree('po/')
os.makedirs('translations') os.makedirs('translations')
os.makedirs('po') for pofile in glob('po/*.po'):
filename, headers = urllib.urlretrieve('http://wicd.sourceforge.net/translator/idlist/') lang = pofile.replace('po/', '').replace('.po', '')
id_file = open(filename, 'r') os.makedirs('translations/' + lang + '/LC_MESSAGES/')
lines = id_file.readlines() os.system('msgfmt --output-file=translations/' + lang +
# remove the \n from the end of lines, and remove blank entries '/LC_MESSAGES/wicd.mo ' + pofile)
lines = [ x.strip() for x in lines if not x.strip() is '' ]
for id in lines:
pofile, poheaders = urllib.urlretrieve('http://wicd.sourceforge.net/translator/download/'+str(id)+'/')
try:
lang_identifier = open(pofile,'r').readlines()[0].strip()
first_line = lang_identifier
lang_identifier = lang_identifier[lang_identifier.rindex('(')+1:lang_identifier.rindex(')')]
print first_line
except:
print >> sys.stderr, 'error downloading language %s' % id
else:
shutil.move(pofile, 'po/'+lang_identifier+'.po')
os.makedirs('translations/'+lang_identifier+'/LC_MESSAGES')
os.system('msgfmt --output-file=translations/' + lang_identifier +
'/LC_MESSAGES/wicd.mo po/' + lang_identifier + '.po')
class uninstall(Command): class uninstall(Command):
description = "remove Wicd using uninstall.sh and install.log" description = "remove Wicd using uninstall.sh and install.log"
@@ -640,12 +607,11 @@ iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'],
setup( setup(
cmdclass = { cmdclass = {
'configure' : configure, 'configure' : configure,
'get_translations' : get_translations,
'uninstall' : uninstall, 'uninstall' : uninstall,
'test' : test, 'test' : test,
'clear_generated' : clear_generated, 'clear_generated' : clear_generated,
'update_translations_py' : update_translations_py,
'update_message_catalog' : update_message_catalog, 'update_message_catalog' : update_message_catalog,
'compile_translations' : compile_translations,
}, },
name = "Wicd", name = "Wicd",
version = VERSION_NUM, version = VERSION_NUM,