Django

Code

Show
Ignore:
Timestamp:
07/13/08 09:31:09 (4 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7837-7838,7842-7852,7856-7869,7871,7876-7877,7882-7891,7900-7917 via svnmerge from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis

    • Property svnmerge-integrated changed from /django/trunk:1-7835 to /django/trunk:1-7917
  • django/branches/gis/django/bin/compile-messages.py

    r6815 r7918  
    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() 
  • django/branches/gis/django/bin/daily_cleanup.py

    r5492 r7918  
    88""" 
    99 
    10 import datetime 
    11 from django.db import transaction 
    12 from django.contrib.sessions.models import Session 
    13  
    14 def clean_up(): 
    15     """Clean up expired sessions.""" 
    16     Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete() 
    17     transaction.commit_unless_managed() 
     10from django.core import management 
    1811 
    1912if __name__ == "__main__": 
    20     clean_up(
     13    management.call_command('cleanup'
  • django/branches/gis/django/bin/make-messages.py

    r7482 r7918  
    11#!/usr/bin/env python 
    22 
    3 # Need to ensure that the i18n framework is enabled 
    4 from django.conf import settings 
    5 settings.configure(USE_I18N = True) 
     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 makemessages %s" instead.'% args 
     9    print >> sys.stderr 
     10    sys.exit(1) 
    611 
    7 from django.utils.translation import templatize 
    8 import re 
    9 import os 
    10 import sys 
    11 import getopt 
    12 from itertools import dropwhile 
    13  
    14 pythonize_re = re.compile(r'\n\s*//') 
    15  
    16 def make_messages(): 
    17     localedir = None 
    18  
    19     if os.path.isdir(os.path.join('conf', 'locale')): 
    20         localedir = os.path.abspath(os.path.join('conf', 'locale')) 
    21     elif os.path.isdir('locale'): 
    22         localedir = os.path.abspath('locale') 
    23     else: 
    24         print "This script should be run from the django svn tree or your project or app tree." 
    25         print "If you did indeed run it from the svn checkout or your project or application," 
    26         print "maybe you are just missing the conf/locale (in the django tree) or locale (for project" 
    27         print "and application) directory?" 
    28         print "make-messages.py doesn't create it automatically, you have to create it by hand if" 
    29         print "you want to enable i18n for your project or application." 
    30         sys.exit(1) 
    31  
    32     (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va') 
    33  
    34     lang = None 
    35     domain = 'django' 
    36     verbose = False 
    37     all = False 
    38  
    39     for o, v in opts: 
    40         if o == '-l': 
    41             lang = v 
    42         elif o == '-d': 
    43             domain = v 
    44         elif o == '-v': 
    45             verbose = True 
    46         elif o == '-a': 
    47             all = True 
    48  
    49     if domain not in ('django', 'djangojs'): 
    50         print "currently make-messages.py only supports domains 'django' and 'djangojs'" 
    51         sys.exit(1) 
    52     if (lang is None and not all) or domain is None: 
    53         print "usage: make-messages.py -l <language>" 
    54         print "   or: make-messages.py -a" 
    55         sys.exit(1) 
    56  
    57     languages = [] 
    58  
    59     if lang is not None: 
    60         languages.append(lang) 
    61     elif all: 
    62         languages = [el for el in os.listdir(localedir) if not el.startswith('.')] 
    63  
    64     for lang in languages: 
    65  
    66         print "processing language", lang 
    67         basedir = os.path.join(localedir, lang, 'LC_MESSAGES') 
    68         if not os.path.isdir(basedir): 
    69             os.makedirs(basedir) 
    70  
    71         pofile = os.path.join(basedir, '%s.po' % domain) 
    72         potfile = os.path.join(basedir, '%s.pot' % domain) 
    73  
    74         if os.path.exists(potfile): 
    75             os.unlink(potfile) 
    76  
    77         all_files = [] 
    78         for (dirpath, dirnames, filenames) in os.walk("."): 
    79             all_files.extend([(dirpath, f) for f in filenames]) 
    80         all_files.sort() 
    81         for dirpath, file in all_files: 
    82             if domain == 'djangojs' and file.endswith('.js'): 
    83                 if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
    84                 src = open(os.path.join(dirpath, file), "rb").read() 
    85                 src = pythonize_re.sub('\n#', src) 
    86                 open(os.path.join(dirpath, '%s.py' % file), "wb").write(src) 
    87                 thefile = '%s.py' % file 
    88                 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile)) 
    89                 (stdin, stdout, stderr) = os.popen3(cmd, 't') 
    90                 msgs = stdout.read() 
    91                 errors = stderr.read() 
    92                 if errors: 
    93                     print "errors happened while running xgettext on %s" % file 
    94                     print errors 
    95                     sys.exit(8) 
    96                 old = '#: '+os.path.join(dirpath, thefile)[2:] 
    97                 new = '#: '+os.path.join(dirpath, file)[2:] 
    98                 msgs = msgs.replace(old, new) 
    99                 if os.path.exists(potfile): 
    100                     # Strip the header 
    101                     msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) 
    102                 else: 
    103                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') 
    104                 if msgs: 
    105                     open(potfile, 'ab').write(msgs) 
    106                 os.unlink(os.path.join(dirpath, thefile)) 
    107             elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): 
    108                 thefile = file 
    109                 if file.endswith('.html'): 
    110                     src = open(os.path.join(dirpath, file), "rb").read() 
    111                     thefile = '%s.py' % file 
    112                     open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) 
    113                 if verbose: 
    114                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
    115                 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( 
    116                     domain, os.path.join(dirpath, thefile)) 
    117                 (stdin, stdout, stderr) = os.popen3(cmd, 't') 
    118                 msgs = stdout.read() 
    119                 errors = stderr.read() 
    120                 if errors: 
    121                     print "errors happened while running xgettext on %s" % file 
    122                     print errors 
    123                     sys.exit(8) 
    124                 if thefile != file: 
    125                     old = '#: '+os.path.join(dirpath, thefile)[2:] 
    126                     new = '#: '+os.path.join(dirpath, file)[2:] 
    127                     msgs = msgs.replace(old, new) 
    128                 if os.path.exists(potfile): 
    129                     # Strip the header 
    130                     msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) 
    131                 else: 
    132                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') 
    133                 if msgs: 
    134                     open(potfile, 'ab').write(msgs) 
    135                 if thefile != file: 
    136                     os.unlink(os.path.join(dirpath, thefile)) 
    137  
    138         if os.path.exists(potfile): 
    139             (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b') 
    140             msgs = stdout.read() 
    141             errors = stderr.read() 
    142             if errors: 
    143                 print "errors happened while running msguniq" 
    144                 print errors 
    145                 sys.exit(8) 
    146             open(potfile, 'w').write(msgs) 
    147             if os.path.exists(pofile): 
    148                 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b') 
    149                 msgs = stdout.read() 
    150                 errors = stderr.read() 
    151                 if errors: 
    152                     print "errors happened while running msgmerge" 
    153                     print errors 
    154                     sys.exit(8) 
    155             open(pofile, 'wb').write(msgs) 
    156             os.unlink(potfile) 
    157  
    158 if __name__ == "__main__": 
    159     make_messages()