Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3cfa3cb

Browse files
committed
Fixed #5522 -- Moved make-messages, compile-messages and daily-cleanup into django-admin.py.
They are now called "makemessages", "compilemessages" and "cleanup". This is backwards incompatible for make-messages.py and compile-messages.py, although the old executables still exist for now and print an error pointing the caller to the right command to call. This reduces the number of binaries and man pages Django needs to install. Patch from Janis Leidel. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7844 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent bff0759 commit 3cfa3cb

16 files changed

+418
-381
lines changed

‎django/bin/compile-messages.py‎

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,11 @@
11
#!/usr/bin/env python
22

3-
import optparse
4-
import os
5-
import sys
6-
7-
try:
8-
set
9-
except NameError:
10-
from sets import Set as set # For Python 2.3
11-
12-
13-
def compile_messages(locale=None):
14-
basedirs = (os.path.join('conf', 'locale'), 'locale')
15-
if os.environ.get('DJANGO_SETTINGS_MODULE'):
16-
from django.conf import settings
17-
basedirs += settings.LOCALE_PATHS
18-
19-
# Gather existing directories.
20-
basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))
21-
22-
if not basedirs:
23-
print "This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified."
24-
sys.exit(1)
25-
26-
for basedir in basedirs:
27-
if locale:
28-
basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
29-
compile_messages_in_dir(basedir)
30-
31-
def compile_messages_in_dir(basedir):
32-
for dirpath, dirnames, filenames in os.walk(basedir):
33-
for f in filenames:
34-
if f.endswith('.po'):
35-
sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
36-
pf = os.path.splitext(os.path.join(dirpath, f))[0]
37-
# Store the names of the .mo and .po files in an environment
38-
# variable, rather than doing a string replacement into the
39-
# command, so that we can take advantage of shell quoting, to
40-
# quote any malicious characters/escaping.
41-
# See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
42-
os.environ['djangocompilemo'] = pf + '.mo'
43-
os.environ['djangocompilepo'] = pf + '.po'
44-
if sys.platform == 'win32': # Different shell-variable syntax
45-
cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
46-
else:
47-
cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
48-
os.system(cmd)
49-
50-
def main():
51-
parser = optparse.OptionParser()
52-
parser.add_option('-l', '--locale', dest='locale',
53-
help="The locale to process. Default is to process all.")
54-
parser.add_option('--settings',
55-
help='Python path to settings module, e.g. "myproject.settings". If provided, all LOCALE_PATHS will be processed. If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be checked as well.')
56-
options, args = parser.parse_args()
57-
if len(args):
58-
parser.error("This program takes no arguments")
59-
if options.settings:
60-
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
61-
compile_messages(options.locale)
62-
633
if __name__ == "__main__":
64-
main()
4+
import sys
5+
name = sys.argv[0]
6+
args = ' '.join(sys.argv[1:])
7+
print >> sys.stderr, "%s has been moved into django-admin.py" % name
8+
print >> sys.stderr, 'Please run "django-admin.py compilemessages %s" instead.'% args
9+
print >> sys.stderr
10+
sys.exit(1)
11+

‎django/bin/daily_cleanup.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
sessions at the moment).
88
"""
99

10-
import datetime
11-
from django.db import transaction
12-
from django.contrib.sessions.models import Session
13-
14-
def clean_up():
15-
"""Clean up expired sessions."""
16-
Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
17-
transaction.commit_unless_managed()
10+
from django.core import management
1811

1912
if __name__ == "__main__":
20-
clean_up()
13+
management.call_command('cleanup')

‎django/bin/make-messages.py‎

Lines changed: 8 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,11 @@
11
#!/usr/bin/env python
22

3-
# Need to ensure that the i18n framework is enabled
4-
from django.conf import settings
5-
settings.configure(USE_I18N = True)
6-
7-
from django.utils.translation import templatize
8-
import re
9-
import os
10-
import sys
11-
import getopt
12-
from itertools import dropwhile
13-
14-
pythonize_re = re.compile(r'\n\s*//')
15-
16-
def make_messages():
17-
localedir = None
18-
19-
if os.path.isdir(os.path.join('conf', 'locale')):
20-
localedir = os.path.abspath(os.path.join('conf', 'locale'))
21-
elif os.path.isdir('locale'):
22-
localedir = os.path.abspath('locale')
23-
else:
24-
print "This script should be run from the django svn tree or your project or app tree."
25-
print "If you did indeed run it from the svn checkout or your project or application,"
26-
print "maybe you are just missing the conf/locale (in the django tree) or locale (for project"
27-
print "and application) directory?"
28-
print "make-messages.py doesn't create it automatically, you have to create it by hand if"
29-
print "you want to enable i18n for your project or application."
30-
sys.exit(1)
31-
32-
(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
33-
34-
lang = None
35-
domain = 'django'
36-
verbose = False
37-
all = False
38-
39-
for o, v in opts:
40-
if o == '-l':
41-
lang = v
42-
elif o == '-d':
43-
domain = v
44-
elif o == '-v':
45-
verbose = True
46-
elif o == '-a':
47-
all = True
48-
49-
if domain not in ('django', 'djangojs'):
50-
print "currently make-messages.py only supports domains 'django' and 'djangojs'"
51-
sys.exit(1)
52-
if (lang is None and not all) or domain is None:
53-
print "usage: make-messages.py -l <language>"
54-
print " or: make-messages.py -a"
55-
sys.exit(1)
56-
57-
languages = []
58-
59-
if lang is not None:
60-
languages.append(lang)
61-
elif all:
62-
languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
63-
64-
for lang in languages:
65-
66-
print "processing language", lang
67-
basedir = os.path.join(localedir, lang, 'LC_MESSAGES')
68-
if not os.path.isdir(basedir):
69-
os.makedirs(basedir)
70-
71-
pofile = os.path.join(basedir, '%s.po' % domain)
72-
potfile = os.path.join(basedir, '%s.pot' % domain)
73-
74-
if os.path.exists(potfile):
75-
os.unlink(potfile)
76-
77-
all_files = []
78-
for (dirpath, dirnames, filenames) in os.walk("."):
79-
all_files.extend([(dirpath, f) for f in filenames])
80-
all_files.sort()
81-
for dirpath, file in all_files:
82-
if domain == 'djangojs' and file.endswith('.js'):
83-
if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
84-
src = open(os.path.join(dirpath, file), "rb").read()
85-
src = pythonize_re.sub('\n#', src)
86-
open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
87-
thefile = '%s.py' % file
88-
cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
89-
(stdin, stdout, stderr) = os.popen3(cmd, 't')
90-
msgs = stdout.read()
91-
errors = stderr.read()
92-
if errors:
93-
print "errors happened while running xgettext on %s" % file
94-
print errors
95-
sys.exit(8)
96-
old = '#: '+os.path.join(dirpath, thefile)[2:]
97-
new = '#: '+os.path.join(dirpath, file)[2:]
98-
msgs = msgs.replace(old, new)
99-
if os.path.exists(potfile):
100-
# Strip the header
101-
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
102-
else:
103-
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
104-
if msgs:
105-
open(potfile, 'ab').write(msgs)
106-
os.unlink(os.path.join(dirpath, thefile))
107-
elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
108-
thefile = file
109-
if file.endswith('.html'):
110-
src = open(os.path.join(dirpath, file), "rb").read()
111-
thefile = '%s.py' % file
112-
open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
113-
if verbose:
114-
sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
115-
cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
116-
domain, os.path.join(dirpath, thefile))
117-
(stdin, stdout, stderr) = os.popen3(cmd, 't')
118-
msgs = stdout.read()
119-
errors = stderr.read()
120-
if errors:
121-
print "errors happened while running xgettext on %s" % file
122-
print errors
123-
sys.exit(8)
124-
if thefile != file:
125-
old = '#: '+os.path.join(dirpath, thefile)[2:]
126-
new = '#: '+os.path.join(dirpath, file)[2:]
127-
msgs = msgs.replace(old, new)
128-
if os.path.exists(potfile):
129-
# Strip the header
130-
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
131-
else:
132-
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
133-
if msgs:
134-
open(potfile, 'ab').write(msgs)
135-
if thefile != file:
136-
os.unlink(os.path.join(dirpath, thefile))
137-
138-
if os.path.exists(potfile):
139-
(stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')
140-
msgs = stdout.read()
141-
errors = stderr.read()
142-
if errors:
143-
print "errors happened while running msguniq"
144-
print errors
145-
sys.exit(8)
146-
open(potfile, 'w').write(msgs)
147-
if os.path.exists(pofile):
148-
(stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
149-
msgs = stdout.read()
150-
errors = stderr.read()
151-
if errors:
152-
print "errors happened while running msgmerge"
153-
print errors
154-
sys.exit(8)
155-
open(pofile, 'wb').write(msgs)
156-
os.unlink(potfile)
157-
1583
if __name__ == "__main__":
159-
make_messages()
4+
import sys
5+
name = sys.argv[0]
6+
args = ' '.join(sys.argv[1:])
7+
print >> sys.stderr, "%s has been moved into django-admin.py" % name
8+
print >> sys.stderr, 'Please run "django-admin.py makemessages %s" instead.'% args
9+
print >> sys.stderr
10+
sys.exit(1)
11+

‎django/core/management/base.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from django.core.exceptions import ImproperlyConfigured
77
from django.core.management.color import color_style
88

9+
try:
10+
set
11+
except NameError:
12+
from sets import Set as set # For Python 2.3
13+
914
class CommandError(Exception):
1015
pass
1116

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import datetime
2+
from django.core.management.base import NoArgsCommand
3+
4+
class Command(NoArgsCommand):
5+
help = "Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment)."
6+
7+
def handle_noargs(self, **options):
8+
from django.db import transaction
9+
from django.contrib.sessions.models import Session
10+
Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
11+
transaction.commit_unless_managed()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import sys
3+
from optparse import make_option
4+
from django.core.management.base import BaseCommand
5+
from django.core.management.color import no_style
6+
7+
try:
8+
set
9+
except NameError:
10+
from sets import Set as set # For Python 2.3
11+
12+
def compile_messages(locale=None):
13+
basedirs = (os.path.join('conf', 'locale'), 'locale')
14+
if os.environ.get('DJANGO_SETTINGS_MODULE'):
15+
from django.conf import settings
16+
basedirs += settings.LOCALE_PATHS
17+
18+
# Gather existing directories.
19+
basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))
20+
21+
if not basedirs:
22+
raise CommandError("This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified.")
23+
24+
for basedir in basedirs:
25+
if locale:
26+
basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
27+
for dirpath, dirnames, filenames in os.walk(basedir):
28+
for f in filenames:
29+
if f.endswith('.po'):
30+
sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
31+
pf = os.path.splitext(os.path.join(dirpath, f))[0]
32+
# Store the names of the .mo and .po files in an environment
33+
# variable, rather than doing a string replacement into the
34+
# command, so that we can take advantage of shell quoting, to
35+
# quote any malicious characters/escaping.
36+
# See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
37+
os.environ['djangocompilemo'] = pf + '.mo'
38+
os.environ['djangocompilepo'] = pf + '.po'
39+
if sys.platform == 'win32': # Different shell-variable syntax
40+
cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
41+
else:
42+
cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
43+
os.system(cmd)
44+
45+
46+
class Command(BaseCommand):
47+
option_list = BaseCommand.option_list + (
48+
make_option('--locale', '-l', dest='locale',
49+
help='The locale to process. Default is to process all.'),
50+
)
51+
help = 'Compiles .po files to .mo files for use with builtin gettext support.'
52+
53+
requires_model_validation = False
54+
can_import_settings = False
55+
56+
def handle(self, **options):
57+
locale = options.get('locale')
58+
compile_messages(locale)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /