"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/roundup/scripts/roundup_gettext.py" (29 Feb 2020, 2236 Bytes) of package /linux/www/roundup-2.0.0.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. See also the latest Fossies "Diffs" side-by-side code changes report for "roundup_gettext.py": 1.6.1_vs_2.0.0.

    1 #! /usr/bin/env python
    2 #
    3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net)
    4 
    5 """Extract translatable strings from tracker templates"""
    6 
    7 from __future__ import print_function
    8 import os
    9 import sys
   10 
   11 
   12 # --- patch sys.path to make sure 'import roundup' finds correct version
   13 import os.path as osp
   14 
   15 thisdir = osp.dirname(osp.abspath(__file__))
   16 rootdir = osp.dirname(osp.dirname(thisdir))
   17 if (osp.exists(thisdir + '/__init__.py') and
   18         osp.exists(rootdir + '/roundup/__init__.py')):
   19     # the script is located inside roundup source code
   20     sys.path.insert(0, rootdir)
   21 # --/
   22 
   23 
   24 from roundup.i18n import _
   25 from roundup.cgi.TAL import talgettext
   26 
   27 # name of message template file.
   28 # i don't think this will ever need to be changed, but still...
   29 TEMPLATE_FILE = "messages.pot"
   30 
   31 
   32 def run():
   33     # return unless command line arguments contain single directory path
   34     if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")):
   35         print(_("Usage: %(program)s <tracker home>") %
   36               {"program": sys.argv[0]})
   37         return
   38     # collect file paths of html templates
   39     home = os.path.abspath(sys.argv[1])
   40     htmldir = os.path.join(home, "html")
   41     if os.path.isdir(htmldir):
   42         # glob is not used because i want to match file names
   43         # without case sensitivity, and that is easier done this way.
   44         htmlfiles = [filename for filename in os.listdir(htmldir)
   45                      if os.path.isfile(os.path.join(htmldir, filename))
   46                      and filename.lower().endswith(".html")]
   47     else:
   48         htmlfiles = []
   49     # return if no html files found
   50     if not htmlfiles:
   51         print(_("No tracker templates found in directory %s") % home)
   52         return
   53     # change to locale dir to have relative source references
   54     locale = os.path.join(home, "locale")
   55     if not os.path.isdir(locale):
   56         os.mkdir(locale)
   57     os.chdir(locale)
   58     # tweak sys.argv as this is the only way to tell talgettext what to do
   59     # Note: unix-style paths used instead of os.path.join deliberately
   60     sys.argv[1:] = ["-o", TEMPLATE_FILE] \
   61         + ["../html/" + filename for filename in htmlfiles]
   62     # run
   63     talgettext.main()
   64 
   65 
   66 if __name__ == "__main__":
   67     run()
   68 
   69 # vim: set et sts=4 sw=4 :