summaryrefslogtreecommitdiff
path: root/bin/tools/osutil.py
diff options
context:
space:
mode:
authorChristophe Simonis <christophe@tinyerp.com>2008-12-04 16:36:56 +0100
committerChristophe Simonis <christophe@tinyerp.com>2008-12-04 16:36:56 +0100
commit23d5e09e286cf7d5d8f80ac8d6f3313a50bb0ea3 (patch)
tree3a7c2b5a7c1929b2e423933252b43b579209e42b /bin/tools/osutil.py
parent086fbc2d4d986e9d22d13c4ad65fd9fade250b44 (diff)
[IMP] move oswalksymlinks to a new module tools.osutil
bzr revid: christophe@tinyerp.com-20081204153656-l247acif1eqvyvl0
Diffstat (limited to 'bin/tools/osutil.py')
-rw-r--r--bin/tools/osutil.py63
1 files changed, 63 insertions, 0 deletions
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))