mirror of
https://github.com/gryf/wicd.git
synced 2025-12-21 21:38:06 +01:00
Only compile translations complete >= 80%, fix setup.py commands dependencies
This commit is contained in:
63
setup.py
63
setup.py
@@ -21,6 +21,7 @@ from distutils.core import setup, Command
|
|||||||
from distutils.command.build import build as _build
|
from distutils.command.build import build as _build
|
||||||
from distutils.command.install import install as _install
|
from distutils.command.install import install as _install
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -58,6 +59,12 @@ class build(_build):
|
|||||||
sub_commands = _build.sub_commands + [('compile_translations', None)]
|
sub_commands = _build.sub_commands + [('compile_translations', None)]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
try:
|
||||||
|
import wpath
|
||||||
|
except ImportError:
|
||||||
|
self.run_command('configure')
|
||||||
|
import wpath
|
||||||
|
#raise Exception, 'Please run "./setup.py configure" first.'
|
||||||
_build.run(self)
|
_build.run(self)
|
||||||
|
|
||||||
class configure(Command):
|
class configure(Command):
|
||||||
@@ -307,12 +314,10 @@ class configure(Command):
|
|||||||
self.distro_check()
|
self.distro_check()
|
||||||
else:
|
else:
|
||||||
print "WARNING: Distro detection failed!"
|
print "WARNING: Distro detection failed!"
|
||||||
self.init='init/default/wicd'
|
|
||||||
self.no_install_init = True
|
self.no_install_init = True
|
||||||
self.distro_detect_failed = True
|
self.distro_detect_failed = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
self.distro_check()
|
self.distro_check()
|
||||||
if self.distro_detect_failed and not self.no_install_init and \
|
if self.distro_detect_failed and not self.no_install_init and \
|
||||||
@@ -416,10 +421,8 @@ class install(_install):
|
|||||||
try:
|
try:
|
||||||
import wpath
|
import wpath
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# if there's no wpath.py, then run configure+build
|
self.run_command('build')
|
||||||
print 'Running configure with default parameters.'
|
import wpath
|
||||||
for cmd in [configure,build]:
|
|
||||||
cmd(self.distribution).run()
|
|
||||||
|
|
||||||
print "Using init file",(wpath.init, wpath.initfile)
|
print "Using init file",(wpath.init, wpath.initfile)
|
||||||
data.extend([
|
data.extend([
|
||||||
@@ -526,8 +529,8 @@ class install(_install):
|
|||||||
print 'Using pid path', os.path.basename(wpath.pidfile)
|
print 'Using pid path', os.path.basename(wpath.pidfile)
|
||||||
if not wpath.no_install_i18n:
|
if not wpath.no_install_i18n:
|
||||||
print 'Language support for',
|
print 'Language support for',
|
||||||
for pofile in sorted(glob('po/*.po')):
|
for language in sorted(glob('translations/*')):
|
||||||
language = pofile.replace('po/', '').replace('.po', '')
|
language = language.replace('translations/', '')
|
||||||
print language,
|
print language,
|
||||||
data.append((wpath.translations + language + '/LC_MESSAGES/',
|
data.append((wpath.translations + language + '/LC_MESSAGES/',
|
||||||
['translations/' + language + '/LC_MESSAGES/wicd.mo']))
|
['translations/' + language + '/LC_MESSAGES/wicd.mo']))
|
||||||
@@ -585,6 +588,7 @@ class update_translations(Command):
|
|||||||
|
|
||||||
class compile_translations(Command):
|
class compile_translations(Command):
|
||||||
description = 'compile po-files to binary mo'
|
description = 'compile po-files to binary mo'
|
||||||
|
threshold = 0.8
|
||||||
|
|
||||||
user_options = []
|
user_options = []
|
||||||
|
|
||||||
@@ -595,17 +599,54 @@ class compile_translations(Command):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
import wpath
|
try:
|
||||||
|
import wpath
|
||||||
|
except ImportError:
|
||||||
|
# if there's no wpath.py, then run configure+build
|
||||||
|
self.run_command('build')
|
||||||
|
import wpath
|
||||||
|
|
||||||
if not wpath.no_install_i18n:
|
if not wpath.no_install_i18n:
|
||||||
if os.path.exists('translations'):
|
if os.path.exists('translations'):
|
||||||
shutil.rmtree('translations/')
|
shutil.rmtree('translations/')
|
||||||
os.makedirs('translations')
|
os.makedirs('translations')
|
||||||
|
|
||||||
|
oldlang = os.environ['LANG']
|
||||||
|
os.environ['LANG'] = 'C'
|
||||||
|
|
||||||
for pofile in sorted(glob('po/*.po')):
|
for pofile in sorted(glob('po/*.po')):
|
||||||
lang = pofile.replace('po/', '').replace('.po', '')
|
lang = pofile.replace('po/', '').replace('.po', '')
|
||||||
os.makedirs('translations/' + lang + '/LC_MESSAGES/')
|
compile_po = False
|
||||||
os.system('pybabel compile -D wicd -i %s -l %s -d translations/' % (pofile, lang))
|
try:
|
||||||
|
msgfmt = subprocess.Popen(['msgfmt', '--statistics', pofile,
|
||||||
|
'-o', '/dev/null'], stderr=subprocess.PIPE)
|
||||||
|
returncode = msgfmt.wait() # let it finish, and get the exit code
|
||||||
|
output = msgfmt.stderr.readline().strip()
|
||||||
|
if len(output) == 0 or returncode != 0:
|
||||||
|
print len(output), returncode
|
||||||
|
raise ValueError
|
||||||
|
else:
|
||||||
|
m = re.match('(\d+) translated messages(?:, (\d+) fuzzy translation)?(?:, (\d+) untranslated messages)?.', output)
|
||||||
|
if m:
|
||||||
|
done, fuzzy, missing = m.groups()
|
||||||
|
fuzzy = int(fuzzy) if fuzzy else 0
|
||||||
|
missing = int(missing) if missing else 0
|
||||||
|
|
||||||
|
completeness = float(done)/(int(done) + missing + fuzzy)
|
||||||
|
if completeness >= self.threshold:
|
||||||
|
compile_po = True
|
||||||
|
else:
|
||||||
|
print 'Disabled %s (%s%% < %s%%).' % \
|
||||||
|
(lang, completeness*100, self.threshold*100)
|
||||||
|
continue
|
||||||
|
except (OSError, ValueError):
|
||||||
|
print 'ARGH'
|
||||||
|
|
||||||
|
if compile_po:
|
||||||
|
os.makedirs('translations/' + lang + '/LC_MESSAGES/')
|
||||||
|
os.system('pybabel compile -D wicd -i %s -l %s -d translations/' % (pofile, lang))
|
||||||
|
|
||||||
|
os.environ['LANG'] = oldlang
|
||||||
|
|
||||||
class uninstall(Command):
|
class uninstall(Command):
|
||||||
description = "remove Wicd using uninstall.sh and install.log"
|
description = "remove Wicd using uninstall.sh and install.log"
|
||||||
|
|||||||
Reference in New Issue
Block a user