本文整理汇总了Python中exe.engine.path.Path.walkfiles方法的典型用法代码示例。如果您正苦于以下问题:Python Path.walkfiles方法的具体用法?Python Path.walkfiles怎么用?Python Path.walkfiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.path.Path
的用法示例。
在下文中一共展示了Path.walkfiles方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeXulPO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import walkfiles [as 别名]
def makeXulPO(applicationDirectoryPath, applicationDomain=None, verbose=0):
"""Searches through xul files and appends to messages.pot"""
if verbose:
print "Importing xul templates..."
path = Path(applicationDirectoryPath)
messages = pot2dict('exe/locale/messages.pot')
messageCommentTemplate = '\n#: %s:%s\nmsgid "'
seq = len(messages)
skipPaths = (
applicationDirectoryPath/'exe/webui/firefox',
)
for fn in path.walkfiles():
if fn.ext.lower() == '.xul':
for skipPath in skipPaths:
if fn.startswith(skipPath):
print 'IGNORING', fn
break
else:
if verbose:
print "template: ", fn
reader = Sax2.Reader()
doc = reader.fromStream(file(fn, 'rb'))
xul2dict(doc, messages, seq, fn.relpath())
pot = Path('exe/locale/messages.pot')
if pot.exists():
pot.remove()
pot.touch()
dict2pot(messages, 'exe/locale/messages.pot')
示例2: makePO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import walkfiles [as 别名]
def makePO(applicationDirectoryPath, applicationDomain=None, verbose=1) :
"""Build the Portable Object Template file for the application.
makePO builds the .pot file for the application stored inside
a specified directory by running xgettext for all application source
files. It finds the name of all files by looking for a file called 'app.fil'.
If this file does not exists, makePo raises an IOError exception.
By default the application domain (the application
name) is the same as the directory name but it can be overridden by the
'applicationDomain' argument.
makePO always creates a new file called messages.pot. If it finds files
of the form app_xx.po where 'app' is the application name and 'xx' is one
of the ISO 639 two-letter language codes, makePO resynchronizes those
files with the latest extracted strings (now contained in messages.pot).
This process updates all line location number in the language-specific
.po files and may also create new entries for translation (or comment out
some). The .po file is not changed, instead a new file is created with
the .new extension appended to the name of the .po file.
By default the function does not display what it is doing. Set the
verbose argument to 1 to force it to print its commands.
"""
if applicationDomain is None:
applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
else:
applicationName = applicationDomain
currentDir = os.getcwd()
messages_pot = Path('exe/locale/messages.pot')
# Use xgettext to make the base messages.pot (with header, etc.)
if messages_pot.exists():
messages_pot.remove()
messages_pot.touch()
cmd = 'xgettext -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 exe/engine/package.py'
if verbose: print cmd
os.system(cmd)
if not os.path.exists('app.fil'):
raise IOError(2,'No module file: app.fil')
# Steps:
# Use xgettext to parse all application modules
# The following switches are used:
#
# -s : sort output by string content (easier to use when we need to merge several .po files)
# --files-from=app.fil : The list of files is taken from the file: app.fil
# --output= : specifies the name of the output file (using a .pot extension)
cmd = 'xgettext -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 %s'
if verbose: print cmd
for fn in open('app.fil'):
print 'Extracting from', fn,
os.system(cmd % fn[:-1])
makeXulPO(applicationDirectoryPath, applicationDomain, verbose)
# Merge new pot with .po files
localeDirs = Path('exe/locale')
for filename in localeDirs.walkfiles('*_*.po'):
cmd = "msgmerge -U --no-wrap %s exe/locale/messages.pot" % filename
if verbose: print cmd
os.system(cmd)
示例3: do_export
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import walkfiles [as 别名]
def do_export(self, inputf, outputf):
if hasattr(self, 'export_' + self.options["export"]):
LOG.debug("Exporting to type %s, in: %s, out: %s, overwrite: %s" \
% (self.options["export"], inputf, outputf, str(self.options["overwrite"])))
if not outputf:
if self.options["export"] in ('website', 'singlepage'):
outputf = inputf.rsplit(".elp")[0]
else:
outputf = inputf + self.extensions[self.options["export"]]
outputfp = Path(outputf)
if outputfp.exists() and not self.options["overwrite"]:
error = _(u'"%s" already exists.\nPlease try again \
with a different filename') % outputf
raise Exception(error.encode(sys.stdout.encoding))
else:
if outputfp.exists() and self.options["overwrite"]:
if outputfp.isdir():
for filen in outputfp.walkfiles():
filen.remove()
outputfp.rmdir()
else:
outputfp.remove()
pkg = Package.load(inputf)
LOG.debug("Package %s loaded" % (inputf))
if not pkg:
error = _(u"Invalid input package")
raise Exception(error.encode(sys.stdout.encoding))
self.styles_dir = self.web_dir.joinpath('style', pkg.style)
LOG.debug("Styles dir: %s" % (self.styles_dir))
getattr(self, 'export_' + self.options["export"])(pkg, outputf)
return outputf
else:
raise Exception(_(u"Export format not implemented")\
.encode(sys.stdout.encoding))
示例4: makeMO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import walkfiles [as 别名]
def makeMO(applicationDirectoryPath,targetDir=None,applicationDomain=None, verbose=0,
forceEnglish=0, keep_new=False) :
"""Compile the Portable Object files into the Machine Object stored in the right location.
makeMO converts all translated language-specific PO files located inside
the application directory into the binary .MO files stored inside the
LC_MESSAGES sub-directory for the found locale files.
makeMO searches for all files that have a name of the form 'app_xx.po'
inside the application directory specified by the first argument. The
'app' is the application domain name (that can be specified by the
applicationDomain argument or is taken from the directory name). The 'xx'
corresponds to one of the ISO 639 two-letter language codes.
makeMo stores the resulting files inside a sub-directory of `targetDir`
called xx/LC_MESSAGES where 'xx' corresponds to the 2-letter language
code.
"""
if targetDir is None:
targetDir = 'exe/locale'
if verbose:
print "Target directory for .mo files is: %s" % targetDir
targetDir = Path(targetDir)
if applicationDomain is None:
applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
else:
applicationName = applicationDomain
currentDir = os.getcwd()
os.chdir(applicationDirectoryPath)
exp = re.compile(r'exe_(.*)\.po')
for filename in targetDir.walkfiles('*_*.po'):
langCode = exp.match(filename.basename()).group(1)
mo_targetDir = targetDir/langCode/'LC_MESSAGES'
# if not keeping new languages, both mo_targetDir and its .svn subdir must exist
if not keep_new and (not mo_targetDir.exists()
or not (mo_targetDir/'.svn').exists()):
print "not building %s" % filename
continue
if not mo_targetDir.exists():
mo_targetDir.makedirs()
cmd = "msgfmt -f --statistics -c --output-file=%s.mo %s" % (
mo_targetDir/applicationName,filename)
if verbose:
print cmd
os.system(cmd)
os.chdir(currentDir)
示例5: makeXulPO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import walkfiles [as 别名]
def makeXulPO(applicationDirectoryPath, applicationDomain=None, verbose=0):
"""Searches through xul files and appends to messages.pot"""
if verbose:
print "Importing xul templates..."
path = Path(applicationDirectoryPath)
messages = pot2dict("messages.pot")
messageCommentTemplate = '\n#: %s:%s\nmsgid "'
seq = len(messages)
skipPaths = (applicationDirectoryPath / "exe/webui/firefox",)
for fn in path.walkfiles():
if fn.ext.lower() == ".xul":
for skipPath in skipPaths:
if fn.startswith(skipPath):
print "IGNORING", fn
break
else:
if verbose:
print "template: ", fn
reader = Sax2.Reader()
doc = reader.fromStream(file(fn, "rb"))
xul2dict(doc, messages, seq, fn.relpath())
dict2pot(messages, "messages.pot")
示例6: makePO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import walkfiles [as 别名]
def makePO(applicationDirectoryPath, applicationDomain=None, verbose=1) :
"""Build the Portable Object Template file for the application.
makePO builds the .pot file for the application stored inside
a specified directory by running xgettext for all application source
files. It finds the name of all files by looking for a file called 'app.fil'.
If this file does not exists, makePo raises an IOError exception.
By default the application domain (the application
name) is the same as the directory name but it can be overridden by the
'applicationDomain' argument.
makePO always creates a new file called messages.pot. If it finds files
of the form app_xx.po where 'app' is the application name and 'xx' is one
of the ISO 639 two-letter language codes, makePO resynchronizes those
files with the latest extracted strings (now contained in messages.pot).
This process updates all line location number in the language-specific
.po files and may also create new entries for translation (or comment out
some). The .po file is not changed, instead a new file is created with
the .new extension appended to the name of the .po file.
By default the function does not display what it is doing. Set the
verbose argument to 1 to force it to print its commands.
"""
if applicationDomain is None:
applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
else:
applicationName = applicationDomain
currentDir = os.getcwd()
os.chdir(applicationDirectoryPath)
if not os.path.exists('app.fil'):
raise IOError(2,'No module file: app.fil')
cmd = 'xgettext -kx_ -s --no-wrap --files-from=app.fil ' \
'--output=exe/locale/messages.pot --from-code=utf8'
if verbose: print cmd
os.system(cmd)
os.chdir(currentDir)
makeXulPO(applicationDirectoryPath, applicationDomain, verbose)
localeDirs = Path('exe/locale')
for filename in localeDirs.walkfiles('*_*.po'):
cmd = "msgmerge -U --no-wrap %s exe/locale/messages.pot" % filename
if verbose: print cmd
os.system(cmd)