[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r18006: {projects} Automated .po file compilation and .mo file installation: ge (projects/gettor)
Author: kaner
Date: 2009-01-07 10:56:19 -0500 (Wed, 07 Jan 2009)
New Revision: 18006
Modified:
projects/gettor/TODO
projects/gettor/gettor.py
projects/gettor/gettor_opt.py
Log:
Automated .po file compilation and .mo file installation:
gettor.py -r takes care of this now: todolistitems--
Modified: projects/gettor/TODO
===================================================================
--- projects/gettor/TODO 2009-01-07 14:24:36 UTC (rev 18005)
+++ projects/gettor/TODO 2009-01-07 15:56:19 UTC (rev 18006)
@@ -8,5 +8,4 @@
- Rename the library modules and move them to something like lib/ so that only
the gettor.py executable stays in the top-level dir
- Enhance README file
-- Automatically parse .po files and move the .mo files to their proper place
- Add more translations
Modified: projects/gettor/gettor.py
===================================================================
--- projects/gettor/gettor.py 2009-01-07 14:24:36 UTC (rev 18005)
+++ projects/gettor/gettor.py 2009-01-07 15:56:19 UTC (rev 18006)
@@ -80,6 +80,56 @@
# XXX
return True
+def installMo(poFile, targetDir):
+ args = os.getcwd() + "/" + poFile + " -o " + targetDir + "/gettor.mo"
+ try:
+ ret = subprocess.call("msgfmt" + " " + args, shell=True)
+ if ret < 0:
+ print >> sys.stdout, "Error in msgfmt execution: ", ret
+ return False
+ except OSError, e:
+ print >> sys.stdout, "Comilation failed: ", e
+ return False
+ return True
+
+def installTrans(config):
+ hasDirs = None
+ localeSrcdir = "i18n"
+
+ if config is None:
+ log.error("Bad arg.")
+ return False
+ localeDir = config.getLocaleDir()
+ if not os.path.isdir(localeDir):
+ print >> sys.stderr, "Sorry, %s is not a directory." % distDir
+ return False
+ for root, dirs, files in os.walk(localeSrcdir):
+ # XXX Python lacks 'depth' featue for os.walk()
+ if root != localeSrcdir:
+ continue
+ for dir in dirs:
+ hasDirs = True
+ if dir.startswith("."):
+ continue
+ try:
+ poFile = os.path.join(root, dir) + "/gettor_" + dir + ".po"
+ # Construct target dir
+ targetDir = localeDir + "/" + dir + "/LC_MESSAGES"
+ if os.path.isdir(targetDir):
+ if installMo(poFile, targetDir) == False:
+ print >> sys.err, "Installing .mo files failed."
+ return False
+ else:
+ print >> sys.stderr, "Not a directory: ", targetDir
+ return False
+ except Exception, e:
+ print >> sys.stderr, "Error accessing translation files: ", e
+ return False
+ if hasDirs is None:
+ print >> sys.stderr, "Empty locale dir: ", locale
+ return False
+ return True
+
def installCron():
# XXX: Check if cron is installed and understands our syntax?
currentCronTab = getCurrentCrontab()
@@ -168,14 +218,25 @@
conf = gettor_config.gettorConf(options.configfile)
gettor_log.initialize()
log = gettor_log.getLogger()
+
+ # Setup locale
logLang = conf.getLocale()
localeDir = conf.getLocaleDir()
+ # We need to do this first
+ if options.insttrans:
+ if installTrans(conf):
+ log.info("Installing translation files done.")
+ success = True
+ else:
+ log.error("Installing translation files failed.")
+ return False
# Just check for the english .mo file, because that's the fallback
englishMoFile = localeDir + "/en/LC_MESSAGES/gettor.mo"
if not os.path.isfile(englishMoFile):
log.error("Sorry, %s is not a file we can access." % englishMoFile)
return False
switchLocale(logLang, localeDir)
+
distDir = conf.getDistDir()
if not os.path.isdir(distDir):
log.error(_("Sorry, %s is not a directory.") % distDir)
Modified: projects/gettor/gettor_opt.py
===================================================================
--- projects/gettor/gettor_opt.py 2009-01-07 14:24:36 UTC (rev 18005)
+++ projects/gettor/gettor_opt.py 2009-01-07 15:56:19 UTC (rev 18006)
@@ -55,6 +55,9 @@
cmdParser.add_option("-y", "--clear-blacklist", dest="clearbl",
action="store_true", default=False,
help="clear all entrys in the blacklist")
+ cmdParser.add_option("-r", "--install-translations", dest="insttrans",
+ action="store_true", default=False,
+ help="Compile and install translation files")
return cmdParser.parse_args()