/[navidoc]/navidoc/navidoc/util/path.py
ViewVC logotype

Diff of /navidoc/navidoc/util/path.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by humppake, Mon Apr 28 08:27:34 2003 UTC revision 1.3 by humppake, Mon Jun 2 13:58:14 2003 UTC
# Line 31  import os.path Line 31  import os.path
31    
32  def listdir(path, extensions, dirs=0):  def listdir(path, extensions, dirs=0):
33      """      """
34      Returns all directories and files with specific      listdir(path, extensions, dirs=0)
35      extensions under path. Nonrecursive.  
36        Quite specialized listdir, which returns all directories and files
37        with specific extensions under given path. Nonrecursive.
38    
39        Skipping files starting with '.' or including some of 'CVS', '#', '~'.
40      """      """
41      files = [f for f in os.listdir(path) if not f.startswith('.')      files = [f for f in os.listdir(path) if not f.startswith('.')
42               and not f == 'CVS' and '#' not in f and '~' not in f]               and not f == 'CVS' and '#' not in f and '~' not in f]
43    
44      files = [f for f in files if extensions.count(f.split('.')[-1]) > 0 \      if extensions:
45               or os.path.isdir(slashify(path)+f)]          files = [f for f in files if extensions.count(f.split('.')[-1]) > 0 \
46                     or os.path.isdir(slashify(path)+f)]
47      if not dirs:      if not dirs:
48          files = [f for f in files if os.path.isfile(slashify(path)+f)]          files = [f for f in files if os.path.isfile(slashify(path)+f)]
49      return files      return files
50    
51  def slashify(path):  def slashify(path):
52      """      """
53      Add a trailing slash if not already there.      slashify(path)
54    
55        Ends path with a trailing slash, if still necessary.
56      """      """
57      if len(path) > 0:      if len(path) > 0:
58          return (path+'/').replace('//','/')          return (path+'/').replace('//','/')
# Line 53  def slashify(path): Line 60  def slashify(path):
60    
61  def relative_path(source, target):  def relative_path(source, target):
62      """      """
63      Returns a relative path from the source to the target.      relative_path(source, target)
64    
65        Returns a relative filepath from the source filepath to the target
66        filepath.
67      """      """
68      import config      import config
69      dbg = config.dbg.shorthand('path')      dbg = config.dbg.shorthand('path')

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26