Django

Code

Changeset 729

Show
Ignore:
Timestamp:
09/29/05 16:07:35 (3 years ago)
Author:
hugo
Message:

made make-messages.py more intelligent with template scanning

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/i18n/django/bin/make-messages.py

    r727 r729  
    11#!/usr/bin/python 
    22 
     3import re 
    34import os 
    45import sys 
     
    1516    sys.exit(1) 
    1617 
    17 (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:') 
     18(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:v') 
    1819 
    1920lang = None 
    2021domain = 'django' 
     22verbose = False 
    2123 
    2224for o, v in opts: 
     
    2527    elif o == '-d': 
    2628        domain = v 
     29    elif o == '-v': 
     30        verbose = True 
    2731 
    2832if lang is None or domain is None: 
     
    3640lf = os.path.join(basedir, '%s.po' % domain) 
    3741 
     42tpl_re = re.compile(r'{%\s+i18n\s+.*?%}') 
     43 
    3844for (dirpath, dirnames, filenames) in os.walk("."): 
    3945    for file in filenames: 
    4046        if file.endswith('.py') or file.endswith('.html'): 
    41             sys.stderr.write('processing file %s in %s\n' % (file, dirpath)) 
     47            thefile = file 
     48            if file.endswith('.html'): 
     49                src = open(os.path.join(dirpath, file), "rb").read() 
     50                lst = [] 
     51                for match in tpl_re.findall(src): 
     52                   lst.append(match) 
     53                open(os.path.join(dirpath, '%s.py' % file), "wb").write('\n'.join(lst)) 
     54                thefile = '%s.py' % file 
     55            if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
    4256            if os.path.isfile(lf): 
    43                 cmd = 'xgettext -j -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, file)) 
     57                cmd = 'xgettext -j -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, thefile)) 
    4458            else: 
    45                 cmd = 'xgettext -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, file)) 
     59                cmd = 'xgettext -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, thefile)) 
    4660            os.system(cmd) 
     61            if thefile != file: 
     62                os.unlink(os.path.join(dirpath, thefile)) 
    4763