fix with code source walking in translation export

bzr revid: christophe@tinyerp.com-20080908075251-gbr4dp0vyl5dhv9u
This commit is contained in:
Christophe Simonis
2008-09-08 09:52:51 +02:00
parent f1c9e258a4
commit b7fbf0aa72
2 changed files with 21 additions and 17 deletions
+15 -14
View File
@@ -257,20 +257,21 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
def oswalksymlinks(top, topdown=True, onerror=None):
"""
same as os.walk but follow symlinks
"""
for dirpath, dirnames, filenames in os.walk(top, topdown, onerror):
symlinks = filter(lambda dirname: os.path.islink(os.path.join(dirpath, dirname)), dirnames)
if not topdown:
for s in symlinks:
for x in oswalksymlinks(os.path.join(dirpath, s), topdown, onerror):
yield x
yield dirpath, dirnames, filenames
if topdown:
for s in symlinks:
for x in oswalksymlinks(os.path.join(dirpath, s), topdown, onerror):
yield x
"""
same as os.walk but follow symlinks
attention: all symlinks are walked before all normals directories
"""
for dirpath, dirnames, filenames in os.walk(top, topdown, onerror):
if topdown:
yield dirpath, dirnames, filenames
symlinks = filter(lambda dirname: os.path.islink(os.path.join(dirpath, dirname)), dirnames)
for s in symlinks:
for x in oswalksymlinks(os.path.join(dirpath, s), topdown, onerror):
yield x
if not topdown:
yield dirpath, dirnames, filenames
#----------------------------------------------------------
# iterables
+6 -3
View File
@@ -436,23 +436,26 @@ def trans_generate(lang, modules, dbname=None):
# parse source code for _() calls
def get_module_from_path(path):
relative_addons_path = tools.config['addons_path'][len(tools.config['root_path'])+1:]
if path.startswith(relative_addons_path):
if path.startswith(relative_addons_path) and (os.path.dirname(path) != relative_addons_path):
path = path[len(relative_addons_path)+1:]
return path.split(os.path.sep)[0]
return 'base' # files that are not in a module are considered as being in 'base' module
modobj = pool.get('ir.module.module')
installed_modids = modobj.search(cr, uid, [('state', '=', 'installed')])
installed_modules = map(lambda m: m['name'], modobj.browse(cr, uid, installed_modids, ['name']))
for root, dirs, files in tools.oswalksymlinks(tools.config['root_path']):
for fname in fnmatch.filter(files, '*.py'):
fabsolutepath = join(root, fname)
frelativepath = fabsolutepath[len(tools.config['root_path'])+1:]
module = get_module_from_path(frelativepath)
is_mod_installed = modobj.search(cr, uid, [('state', '=', 'installed'), ('name', '=', module)]) <> []
is_mod_installed = module in installed_modules
if (('all' in modules) or (module in modules)) and is_mod_installed:
code_string = tools.file_open(fabsolutepath, subdir='').read()
iter = re.finditer(
'[^a-zA-Z0-9_]_\([\s]*["\'](.+?)["\'][\s]*\)',
code_string)
code_string, re.M)
for i in iter:
push_translation(module, 'code', frelativepath, 0, i.group(1).encode('utf8'))