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

Diff of /navidoc/navidoc/utils/path.py

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

revision 1.4 by humppake, Fri Mar 21 10:36:28 2003 UTC revision 1.5 by humppake, Mon Mar 24 08:08:13 2003 UTC
# Line 35  def _listdir(path, extensions, dirs=0): Line 35  def _listdir(path, extensions, dirs=0):
35      extensions under path. Nonrecursive.      extensions under path. Nonrecursive.
36      """      """
37      files = [f for f in os.listdir(path) if not f.startswith('.')      files = [f for f in os.listdir(path) if not f.startswith('.')
38               and not f == "CVS" and '#' not in f and '~' not in f]               and not f == 'CVS' and '#' not in f and '~' not in f]
39    
40        files = [f for f in files if extensions.count(f.split('.')[-1]) > 0 \
41                 or os.path.isdir(_slashify(path)+f)]
42      if not dirs:      if not dirs:
43          files = [f for f in os.listdir(path) if os.path.isfile(_slashify(path)+f)]          files = [f for f in files if os.path.isfile(_slashify(path)+f)]
     files = [f for f in files if extensions.count(f.split('.')[-1]) > 0]  
44      return files      return files
45    
46  def _slashify(path):  def _slashify(path):
# Line 46  def _slashify(path): Line 48  def _slashify(path):
48      Add a trailing slash if not already there.      Add a trailing slash if not already there.
49      """      """
50      if len(path) > 0:      if len(path) > 0:
51          return (path+"/").replace("//","/")          return (path+'/').replace('//','/')
52      return path      return path
53    
54  def relative_path(source, target):  def relative_path(source, target):
55      """      """
56      Returns a relative path from the source to the target.      Returns a relative path from the source to the target.
57      """      """
58      if source.startswith("../") or target.startswith("../"):      if source == None or len(source) == 0: return target
59        if source.startswith('../') or target.startswith('../'):
60          source = os.path.normpath(os.path.abspath(source))          source = os.path.normpath(os.path.abspath(source))
61          target = os.path.normpath(os.path.abspath(target))          target = os.path.normpath(os.path.abspath(target))
62    
63      depth = source.count("/")      depth = source.count('/')
64      source_parts = source.split("/")      source_parts = source.split('/')
65      target_parts = target.split("/")      target_parts = target.split('/')
66    
67      parts = len(source_parts) < len(target_parts) \      parts = len(source_parts) < len(target_parts) \
68              and len(source_parts) or len(target_parts)              and len(source_parts) or len(target_parts)
# Line 69  def relative_path(source, target): Line 72  def relative_path(source, target):
72              parts = i              parts = i
73              break              break
74    
75      relative = "".join(["../" for i in range(depth-parts)]) \      relative = ''.join(['../' for i in range(depth-parts)]) \
76                 +"".join([target_parts[i+parts]+"/" \                 +''.join([target_parts[i+parts]+'/' \
77                           for i in range(len(target_parts)-parts)])                           for i in range(len(target_parts)-parts)])
78    
79      return (relative[0:len(relative)-1])      return (relative[0:len(relative)-1])

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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