Code

remove unused, deprecated import
[roundup.git] / roundup / scripts / roundup_gettext.py
1 #! /usr/bin/env python
2 #
3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net)
4 #
5 # $Id: roundup_gettext.py,v 1.1 2004-10-20 10:25:23 a1s Exp $
7 """Extract translatable strings from tracker templates"""
9 import os
10 import sys
12 from roundup.i18n import _
13 from roundup.cgi.TAL import talgettext
15 # name of message template file.
16 # i don't think this will ever need to be changed, but still...
17 TEMPLATE_FILE = "messages.pot"
19 def run():
20     # return unless command line arguments contain single directory path
21     if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")):
22         print _("Usage: %(program)s <tracker home>") % {"program": sys.argv[0]}
23         return
24     # collect file paths of html templates
25     home = os.path.abspath(sys.argv[1])
26     htmldir = os.path.join(home, "html")
27     if os.path.isdir(htmldir):
28         # glob is not used because i want to match file names
29         # without case sensitivity, and that is easier done this way.
30         htmlfiles = [filename for filename in os.listdir(htmldir)
31             if os.path.isfile(os.path.join(htmldir, filename))
32             and filename.lower().endswith(".html")]
33     else:
34         htmlfiles = []
35     # return if no html files found
36     if not htmlfiles:
37         print _("No tracker templates found in directory %s") % home
38         return
39     # change to locale dir to have relative source references
40     locale = os.path.join(home, "locale")
41     if not os.path.isdir(locale):
42         os.mkdir(locale)
43     os.chdir(locale)
44     # tweak sys.argv as this is the only way to tell talgettext what to do
45     # Note: unix-style paths used instead of os.path.join deliberately
46     sys.argv[1:] = ["-o", TEMPLATE_FILE] \
47         + ["../html/" + filename for filename in htmlfiles]
48     # run
49     talgettext.main()
51 if __name__ == "__main__":
52     run()
54 # vim: set et sts=4 sw=4 :