[PATCH] rtemstoolkit/path : Add listdir function

Chris Johns chrisj at rtems.org
Sun May 19 22:05:58 UTC 2019


Hi,

Looks good, however in review I wonder if we should print the os error in each
case? Something like:

 except IOError as e:
     raise error.general('Could not list files: %s: %s' % (path, str(e)))

If we do this would it also make sense to update `mkdir`? Something like:

  except OSError as e:
     raise error.general('cannot make directory: %s: %s' % (path, str(e)))

Thanks
Chris

On 19/5/19 9:56 pm, Vijay Kumar Banerjee wrote:
> ---
>  rtemstoolkit/path.py  | 29 ++++++++++++++++++++++++++++-
>  tester/rt/coverage.py |  4 ++--
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/rtemstoolkit/path.py b/rtemstoolkit/path.py
> index 2b569ae..9051bb5 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 for path: %s' % (path))
> +            except OSError:
> +                raise error.general('Could not list files for path: %s' % (path))
> +            except WindowsError:
> +                raise error.general('Could not list files for path: %s' % (path))
> +        else:
> +            try:
> +                files = os.listdir(host(path))
> +            except IOError:
> +                raise error.general('Could not list files for path: %s' % (path))
> +            except OSError:
> +                raise error.general('Could not list files for path: %s' % (path))
> +
> +    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)
> diff --git a/tester/rt/coverage.py b/tester/rt/coverage.py
> index bdf3c5f..31e2cd7 100644
> --- a/tester/rt/coverage.py
> +++ b/tester/rt/coverage.py
> @@ -215,7 +215,7 @@ class report_gen_html:
>          for symbol_set in self.symbol_sets:
>               symbol_set_dir = path.join(self.build_dir,
>                                          self.bsp + '-coverage', symbol_set)
> -             html_files = os.listdir(symbol_set_dir)
> +             html_files = path.listdir(symbol_set_dir)
>               for html_file in html_files:
>                   html_file = path.join(symbol_set_dir, html_file)
>                   if path.exists(html_file) and 'html' in html_file:
> @@ -291,7 +291,7 @@ class symbol_parser(object):
>              config.add_section('symbol-sets')
>              config.set('symbol-sets', 'sets', sset)
>              config.add_section(sset)
> -            object_files = [o for o in os.listdir(self.symbol_sets[sset]) if o[-1] == 'o']
> +            object_files = [o for o in path.listdir(self.symbol_sets[sset]) if o[-1] == 'o']
>              object_paths = []
>              for o in object_files:
>                  object_paths.append(path.join(self.symbol_sets[sset], o))
> 



More information about the devel mailing list