Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
1f7bf1f0
Commit
1f7bf1f0
authored
May 12, 2013
by
Steve Strassmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use global LOG instead of local log
parent
2b7d7bcd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
20 deletions
+17
-20
i18n/execute.py
+7
-11
i18n/extract.py
+3
-2
i18n/generate.py
+6
-6
i18n/tests/test_validate.py
+1
-1
No files found.
i18n/execute.py
View file @
1f7bf1f0
...
...
@@ -4,28 +4,24 @@ from config import CONFIGURATION, BASE_DIR
LOG
=
logging
.
getLogger
(
__name__
)
def
execute
(
command
,
working_directory
=
BASE_DIR
,
log
=
True
):
def
execute
(
command
,
working_directory
=
BASE_DIR
):
"""
Executes shell command in a given working_directory.
Command is a string to pass to the shell.
log is boolean. If true, the command's invocation string is logged.
Output is ignored.
"""
if
log
:
LOG
.
info
(
command
)
LOG
.
info
(
command
)
subprocess
.
call
(
command
.
split
(
' '
),
cwd
=
working_directory
)
def
call
(
command
,
working_directory
=
BASE_DIR
,
log
=
True
):
def
call
(
command
,
working_directory
=
BASE_DIR
):
"""
Executes shell command in a given working_directory.
Command is a string to pass to the shell.
Returns a tuple of two strings: (stdout, stderr)
log is boolean. If true, the command's invocation string is logged.
"""
if
log
:
LOG
.
info
(
command
)
LOG
.
info
(
command
)
p
=
subprocess
.
Popen
(
command
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
cwd
=
working_directory
)
out
,
err
=
p
.
communicate
()
return
(
out
,
err
)
...
...
@@ -36,7 +32,7 @@ def create_dir_if_necessary(pathname):
os
.
makedirs
(
dirname
)
def
remove_file
(
filename
,
log
=
LOG
,
verbose
=
True
):
def
remove_file
(
filename
,
verbose
=
True
):
"""
Attempt to delete filename.
log is boolean. If true, removal is logged.
...
...
@@ -44,8 +40,8 @@ def remove_file(filename, log=LOG, verbose=True):
Logging filenames are releative to BASE_DIR to cut down on noise in output.
"""
if
verbose
:
log
.
info
(
'Deleting file
%
s'
%
os
.
path
.
relpath
(
filename
,
BASE_DIR
))
LOG
.
info
(
'Deleting file
%
s'
%
os
.
path
.
relpath
(
filename
,
BASE_DIR
))
if
not
os
.
path
.
exists
(
filename
):
log
.
warn
(
"File does not exist:
%
s"
%
os
.
path
.
relpath
(
filename
,
BASE_DIR
))
LOG
.
warn
(
"File does not exist:
%
s"
%
os
.
path
.
relpath
(
filename
,
BASE_DIR
))
else
:
os
.
remove
(
filename
)
i18n/extract.py
View file @
1f7bf1f0
...
...
@@ -32,8 +32,9 @@ BABEL_OUT = BASE_DIR.relpathto(CONFIGURATION.source_messages_dir.joinpath('mako.
SOURCE_WARN
=
'This English source file is machine-generated. Do not check it into github'
LOG
=
logging
.
getLogger
(
__name__
)
def
main
():
log
=
logging
.
getLogger
(
__name__
)
logging
.
basicConfig
(
stream
=
sys
.
stdout
,
level
=
logging
.
INFO
)
create_dir_if_necessary
(
LOCALE_DIR
)
source_msgs_dir
=
CONFIGURATION
.
source_messages_dir
...
...
@@ -63,7 +64,7 @@ def main ():
execute
(
make_djangojs_cmd
,
working_directory
=
BASE_DIR
)
for
filename
in
generated_files
:
log
.
info
(
'Cleaning
%
s'
%
filename
)
LOG
.
info
(
'Cleaning
%
s'
%
filename
)
po
=
pofile
(
source_msgs_dir
.
joinpath
(
filename
))
# replace default headers with edX headers
fix_header
(
po
)
...
...
i18n/generate.py
View file @
1f7bf1f0
...
...
@@ -17,9 +17,11 @@ import os, sys, logging
from
polib
import
pofile
from
config
import
BASE_DIR
,
CONFIGURATION
from
execute
import
execute
,
remove_file
from
execute
import
execute
def
merge
(
locale
,
target
=
'django.po'
,
fail_if_missing
=
True
,
log
=
None
):
LOG
=
logging
.
getLogger
(
__name__
)
def
merge
(
locale
,
target
=
'django.po'
,
fail_if_missing
=
True
):
"""
For the given locale, merge django-partial.po, messages.po, mako.po -> django.po
target is the resulting filename
...
...
@@ -28,8 +30,7 @@ def merge(locale, target='django.po', fail_if_missing=True, log=None):
If fail_if_missing is False, and the files to be merged are missing,
just return silently.
"""
if
log
:
log
.
info
(
'Merging locale={0}'
.
format
(
locale
))
LOG
.
info
(
'Merging locale={0}'
.
format
(
locale
))
locale_directory
=
CONFIGURATION
.
get_messages_dir
(
locale
)
files_to_merge
=
(
'django-partial.po'
,
'messages.po'
,
'mako.po'
)
try
:
...
...
@@ -71,13 +72,12 @@ def validate_files(dir, files_to_merge):
raise
Exception
(
"I18N: Cannot generate because file not found: {0}"
.
format
(
pathname
))
def
main
():
log
=
logging
.
getLogger
(
__name__
)
logging
.
basicConfig
(
stream
=
sys
.
stdout
,
level
=
logging
.
INFO
)
for
locale
in
CONFIGURATION
.
locales
:
merge
(
locale
)
# Dummy text is not required. Don't raise exception if files are missing.
merge
(
CONFIGURATION
.
dummy_locale
,
fail_if_missing
=
False
,
log
=
log
)
merge
(
CONFIGURATION
.
dummy_locale
,
fail_if_missing
=
False
)
compile_cmd
=
'django-admin.py compilemessages'
execute
(
compile_cmd
,
working_directory
=
BASE_DIR
)
...
...
i18n/tests/test_validate.py
View file @
1f7bf1f0
...
...
@@ -28,7 +28,7 @@ def validate_po_file(filename, log):
raise
SkipTest
()
# Use relative paths to make output less noisy.
rfile
=
os
.
path
.
relpath
(
filename
,
LOCALE_DIR
)
(
out
,
err
)
=
call
([
'msgfmt'
,
'-c'
,
rfile
],
log
=
False
,
working_directory
=
LOCALE_DIR
)
(
out
,
err
)
=
call
([
'msgfmt'
,
'-c'
,
rfile
],
working_directory
=
LOCALE_DIR
)
if
err
!=
''
:
log
.
warn
(
'
\n
'
+
err
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment