Django

Code

Show
Ignore:
Timestamp:
07/06/08 10:23:24 (6 months ago)
Author:
brosner
Message:

newforms-admin: Merged from trunk up to [7852].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7829 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7852
  • django/branches/newforms-admin/django/bin/compile-messages.py

    r6777 r7853  
    11#!/usr/bin/env python 
    22 
    3 import optparse 
    4 import os 
    5 import sys 
     3if __name__ == "__main__": 
     4    import sys 
     5    name = sys.argv[0] 
     6    args = ' '.join(sys.argv[1:]) 
     7    print >> sys.stderr, "%s has been moved into django-admin.py" % name 
     8    print >> sys.stderr, 'Please run "django-admin.py compilemessages %s" instead.'% args 
     9    print >> sys.stderr 
     10    sys.exit(1) 
    611 
    7 try: 
    8     set 
    9 except NameError: 
    10     from sets import Set as set     # For Python 2.3 
    11  
    12  
    13 def compile_messages(locale=None): 
    14     basedirs = (os.path.join('conf', 'locale'), 'locale') 
    15     if os.environ.get('DJANGO_SETTINGS_MODULE'): 
    16         from django.conf import settings 
    17         basedirs += settings.LOCALE_PATHS 
    18  
    19     # Gather existing directories. 
    20     basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs))) 
    21  
    22     if not basedirs: 
    23         print "This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified." 
    24         sys.exit(1) 
    25  
    26     for basedir in basedirs: 
    27         if locale: 
    28             basedir = os.path.join(basedir, locale, 'LC_MESSAGES') 
    29         compile_messages_in_dir(basedir) 
    30  
    31 def compile_messages_in_dir(basedir): 
    32     for dirpath, dirnames, filenames in os.walk(basedir): 
    33         for f in filenames: 
    34             if f.endswith('.po'): 
    35                 sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) 
    36                 pf = os.path.splitext(os.path.join(dirpath, f))[0] 
    37                 # Store the names of the .mo and .po files in an environment 
    38                 # variable, rather than doing a string replacement into the 
    39                 # command, so that we can take advantage of shell quoting, to 
    40                 # quote any malicious characters/escaping. 
    41                 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html 
    42                 os.environ['djangocompilemo'] = pf + '.mo' 
    43                 os.environ['djangocompilepo'] = pf + '.po' 
    44                 if sys.platform == 'win32': # Different shell-variable syntax 
    45                     cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"' 
    46                 else: 
    47                     cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"' 
    48                 os.system(cmd) 
    49  
    50 def main(): 
    51     parser = optparse.OptionParser() 
    52     parser.add_option('-l', '--locale', dest='locale', 
    53             help="The locale to process. Default is to process all.") 
    54     parser.add_option('--settings', 
    55         help='Python path to settings module, e.g. "myproject.settings". If provided, all LOCALE_PATHS will be processed. If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be checked as well.') 
    56     options, args = parser.parse_args() 
    57     if len(args): 
    58         parser.error("This program takes no arguments") 
    59     if options.settings: 
    60         os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 
    61     compile_messages(options.locale) 
    62  
    63 if __name__ == "__main__": 
    64     main()