"Fossies" - the Fresh Open Source Software Archive

Member "horizon-14.0.4/openstack_dashboard/management/commands/extract_messages.py" (22 Oct 2019, 2807 Bytes) of package /linux/misc/openstack/horizon-14.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "extract_messages.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2016 Cisco Systems, Inc.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #    http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 # See the License for the specific language governing permissions and
   13 # limitations under the License.
   14 
   15 from distutils.dist import Distribution
   16 import os
   17 from subprocess import call
   18 
   19 from django.core.management.base import BaseCommand
   20 
   21 DOMAINS = ['django', 'djangojs']
   22 MODULES = ['openstack_dashboard', 'horizon']
   23 
   24 
   25 class Command(BaseCommand):
   26     help = ('Extract strings that have been marked for translation into .POT '
   27             'files.')
   28 
   29     def add_arguments(self, parser):
   30         parser.add_argument('-m', '--module', type=str, nargs='+',
   31                             default=MODULES,
   32                             help=("The target python module(s) to extract "
   33                                   "strings from. "
   34                                   "Default: %s" % MODULES))
   35         parser.add_argument('-d', '--domain', choices=DOMAINS,
   36                             nargs='+', default=DOMAINS,
   37                             metavar='DOMAIN',
   38                             help=("Domain(s) of the .pot file. "
   39                                   "Default: %s" % DOMAINS))
   40         parser.add_argument('--check-only', action='store_true',
   41                             help=("Checks that extraction works correctly, "
   42                                   "then deletes the .pot file to avoid "
   43                                   "polluting the source code"))
   44 
   45     def handle(self, *args, **options):
   46         cmd = ('python setup.py {quiet} extract_messages '
   47                '-F babel-{domain}.cfg '
   48                '--input-dirs {module} '
   49                '-o {potfile}')
   50         distribution = Distribution()
   51         distribution.parse_config_files(distribution.find_config_files())
   52 
   53         quiet = '-q' if int(options['verbosity']) == 0 else ''
   54         if options['check_only']:
   55             cmd += " ; rm {potfile}"
   56 
   57         for module in options['module']:
   58             for domain in options['domain']:
   59                 potfile = '{module}/locale/{domain}.pot'.format(module=module,
   60                                                                 domain=domain)
   61                 if not os.path.exists(potfile):
   62                     with open(potfile, 'wb') as f:
   63                         f.write(b'')
   64 
   65                 call(cmd.format(module=module, domain=domain, potfile=potfile,
   66                                 quiet=quiet), shell=True)