diff options
| author | Christophe Simonis <christophe@tinyerp.com> | 2008-12-04 16:36:56 +0100 |
|---|---|---|
| committer | Christophe Simonis <christophe@tinyerp.com> | 2008-12-04 16:36:56 +0100 |
| commit | 23d5e09e286cf7d5d8f80ac8d6f3313a50bb0ea3 (patch) | |
| tree | 3a7c2b5a7c1929b2e423933252b43b579209e42b | |
| parent | 086fbc2d4d986e9d22d13c4ad65fd9fade250b44 (diff) | |
[IMP] move oswalksymlinks to a new module tools.osutil
bzr revid: christophe@tinyerp.com-20081204153656-l247acif1eqvyvl0
| -rw-r--r-- | bin/tools/misc.py | 17 | ||||
| -rw-r--r-- | bin/tools/osutil.py | 63 | ||||
| -rw-r--r-- | bin/tools/translate.py | 2 |
3 files changed, 64 insertions, 18 deletions
diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 6d65a425484..6c6efc5438b 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -252,23 +252,6 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False): raise IOError, 'File not found : '+str(name) -def oswalksymlinks(top, topdown=True, onerror=None): - """ - 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 #---------------------------------------------------------- diff --git a/bin/tools/osutil.py b/bin/tools/osutil.py new file mode 100644 index 00000000000..ba1d650f4ef --- /dev/null +++ b/bin/tools/osutil.py @@ -0,0 +1,63 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +""" +Some functions related to the os and os.path module +""" + +import os +from os.path import join as opj + +def listdir(dir, recursive=False): + """Allow to recursively get the file listing""" + dir = os.path.normpath(dir) + if not recursive: + return os.listdir(dir) + + res = [] + for root, dirs, files in os.walk(dir): + root = root[len(dir)+1:] + res.extend([opj(root, f) for f in files]) + return res + +def walksymlinks(top, topdown=True, onerror=None): + """ + 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 walksymlinks(os.path.join(dirpath, s), topdown, onerror): + yield x + + if not topdown: + yield dirpath, dirnames, filenames + + + +if __name__ == '__main__': + from pprint import pprint as pp + pp(listdir('../report', True)) diff --git a/bin/tools/translate.py b/bin/tools/translate.py index 5163fa6c7e4..8a20541210f 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -452,7 +452,7 @@ def trans_generate(lang, modules, dbname=None): installed_modids = modobj.search(cr, uid, [('state', '=', 'installed')]) installed_modules = map(lambda m: m['name'], modobj.read(cr, uid, installed_modids, ['name'])) - for root, dirs, files in tools.oswalksymlinks(tools.config['root_path']): + for root, dirs, files in tools.osutil.walksymlinks(tools.config['root_path']): for fname in fnmatch.filter(files, '*.py'): fabsolutepath = join(root, fname) frelativepath = fabsolutepath[len(tools.config['root_path'])+1:] |
