diff options
| -rw-r--r-- | websites/langpo.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/websites/langpo.py b/websites/langpo.py index 052c4d5a..9e036e44 100644 --- a/websites/langpo.py +++ b/websites/langpo.py @@ -1,13 +1,37 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import errno, glob, polib, re, os +import errno, glob, polib, re, os, getopt, sys from time import strftime -for langfile in glob.glob('*.en.lang'): - langfilename = langfile.replace('.en.lang', '') +def usage(): + print '\nUsage: python %s [OPTION]' %os.path.basename(sys.argv[0]) + print ' generate pot catalogs and updates po files for lang resources in the specified directory' + print 'Options: -h, --help : usage' + print ' -d <directory>, --directory <directory> : directory with lang files' + sys.exit(2) +try: + opts, args = getopt.getopt(sys.argv[1:], "hd:", ["help", "directory="]) +except getopt.GetoptError: + usage() # print help information and exit + +directory='' +for o,a in opts: + if o in ("-h", "--help"): + usage() + if o in ("-d", "--directory"): + directory=a + +directory = directory.rstrip('/') + +if (directory != '') and (os.path.isdir(directory) == False): + sys.exit('Specified directory does not exixst') + +for langfile in glob.glob(os.path.join(directory, '*.en.lang')): + langfiledir = langfile.replace('.en.lang', '') + langfilename = langfiledir.rpartition('/')[2] # Create localization directories if needed - podir = langfilename + '/po' + podir = langfiledir + '/po' try: os.makedirs(podir) except OSError, e: @@ -50,7 +74,7 @@ for langfile in glob.glob('*.en.lang'): occurrences=[(langfile,'')] ) pot.append(potentry) - potfilename = langfilename + '/po/' + langfilename + '.pot' + potfilename = langfiledir + '/po/' + langfilename + '.pot' pot.save(potfilename) # Parse PO files |
