Ticket #10869: 0001-.-manage.py-makemessages-add-D-switch-for-specifyi.patch

File 0001-.-manage.py-makemessages-add-D-switch-for-specifyi.patch, 3.7 KB (added by filipnoetzel, 16 years ago)
  • django/core/management/commands/makemessages.py

    From 624068a084cd47298d6b455d5b4942c4574b7125 Mon Sep 17 00:00:00 2001
    From: Filip Noetzel <filip@j03.de>
    Date: Sat, 18 Apr 2009 23:49:50 +0200
    Subject: [PATCH] ./manage.py makemessages: add -D switch for specifying input directories
    
    ---
     django/core/management/commands/makemessages.py |   22 ++++++++++++++++++----
     1 files changed, 18 insertions(+), 4 deletions(-)
    
    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    index 604cb03..4b73a99 100644
    a b def handle_extensions(extensions=('html',)):  
    4343    # trick xgettext to parse them as Python files)
    4444    return set([x for x in ext_list if x != '.py'])
    4545
    46 def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None):
     46def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, inputdirs=None):
    4747    """
    4848    Uses the locale directory from the Django SVN tree or an application/
    4949    project to process all
    def make_messages(locale=None, domain='django', verbosity='1', all=False, extens  
    9797    elif all:
    9898        languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
    9999
     100    if inputdirs == None:
     101        inputdirs = ["."]
     102
    100103    for locale in languages:
    101104        if verbosity > 0:
    102105            print "processing language", locale
    def make_messages(locale=None, domain='django', verbosity='1', all=False, extens  
    111114            os.unlink(potfile)
    112115
    113116        all_files = []
    114         for (dirpath, dirnames, filenames) in os.walk("."):
    115             all_files.extend([(dirpath, f) for f in filenames])
     117
     118        for inputdir in inputdirs:
     119            if not os.path.exists(inputdir):
     120                raise CommandError("The input directory '%s' does not exist." % inputdir)
     121            for (dirpath, dirnames, filenames) in os.walk(inputdir):
     122                all_files.extend([(dirpath, f) for f in filenames])
     123
    116124        all_files.sort()
    117125        for dirpath, file in all_files:
    118126            file_base, file_ext = os.path.splitext(file)
    class Command(BaseCommand):  
    204212        make_option('--extension', '-e', dest='extensions',
    205213            help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)',
    206214            action='append'),
     215        make_option('--directory', '-D', dest='inputdirs',
     216            help='add DIRECTORY to list for input files search (default: ".", separate multiple directories with commas, or use -D multiple times)',
     217            action='append'),
    207218    )
    208219    help = "Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory."
    209220
    class Command(BaseCommand):  
    219230        verbosity = int(options.get('verbosity'))
    220231        process_all = options.get('all')
    221232        extensions = options.get('extensions') or ['html']
     233        inputdirs = options.get('inputdirs')
     234        if inputdirs:
     235            inputdirs = (",".join(inputdirs)).split(",")
    222236
    223237        if domain == 'djangojs':
    224238            extensions = []
    class Command(BaseCommand):  
    228242        if '.js' in extensions:
    229243            raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.")
    230244
    231         make_messages(locale, domain, verbosity, process_all, extensions)
     245        make_messages(locale, domain, verbosity, process_all, extensions, inputdirs)
Back to Top