summaryrefslogtreecommitdiff
path: root/rtemstoolkit
diff options
context:
space:
mode:
authorVijay Kumar Banerjee <vijaykumar9597@gmail.com>2019-05-20 16:53:51 +0530
committerChris Johns <chrisj@rtems.org>2019-05-21 15:53:38 +1000
commit9f197dea76995fc2916884e341fb385775e39d2c (patch)
treedac3cd4fd1edb31e36f0bebfbab43d73fd1542fc /rtemstoolkit
parent925448a4527ec1a88b800dbeca8b90ccb365b38e (diff)
rtemstoolkit/path : Add listdir function
Diffstat (limited to 'rtemstoolkit')
-rw-r--r--rtemstoolkit/path.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/rtemstoolkit/path.py b/rtemstoolkit/path.py
index 2b569ae..6b63c8a 100644
--- a/rtemstoolkit/path.py
+++ b/rtemstoolkit/path.py
@@ -157,6 +157,33 @@ def expanduser(path):
path = os.path.expanduser(path)
return shell(path)
+def listdir(path):
+ path = host(path)
+ files = []
+ if not exists(path):
+ raise error.general('path does not exist : %s' % (path))
+ elif not isdir(path):
+ raise error.general('path is not a directory: %s' % (path))
+ else:
+ if windows:
+ try:
+ files = os.listdir(host(path))
+ except IOError:
+ raise error.general('Could not list files: %s' % (path))
+ except OSError as e:
+ raise error.general('Could not list files: %s: %s' % (path, str(e)))
+ except WindowsError as e:
+ raise error.general('Could not list files: %s: %s' % (path, str(e)))
+ else:
+ try:
+ files = os.listdir(host(path))
+ except IOError:
+ raise error.general('Could not list files: %s' % (path))
+ except OSError as e:
+ raise error.general('Could not list files: %s: %s' % (path, str(e)))
+
+ return files
+
def collect_files(path_):
#
# Convert to shell paths and return shell paths.
@@ -184,7 +211,7 @@ def copy_tree(src, dst):
hdst = host(dst)
if os.path.exists(src) and os.path.isdir(src):
- names = os.listdir(src)
+ names = listdir(src)
else:
names = [basename(src)]
src = dirname(src)