home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / dospath.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  7.8 KB  |  302 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import os
  5. import stat
  6. __all__ = [
  7.     'normcase',
  8.     'isabs',
  9.     'join',
  10.     'splitdrive',
  11.     'split',
  12.     'splitext',
  13.     'basename',
  14.     'dirname',
  15.     'commonprefix',
  16.     'getsize',
  17.     'getmtime',
  18.     'getatime',
  19.     'islink',
  20.     'exists',
  21.     'isdir',
  22.     'isfile',
  23.     'ismount',
  24.     'walk',
  25.     'expanduser',
  26.     'expandvars',
  27.     'normpath',
  28.     'abspath']
  29.  
  30. def normcase(s):
  31.     return s.replace('/', '\\').lower()
  32.  
  33.  
  34. def isabs(s):
  35.     s = splitdrive(s)[1]
  36.     if s != '':
  37.         pass
  38.     return s[:1] in '/\\'
  39.  
  40.  
  41. def join(a, *p):
  42.     path = a
  43.     for b in p:
  44.         if isabs(b):
  45.             path = b
  46.         elif path == '' or path[-1:] in '/\\:':
  47.             path = path + b
  48.         else:
  49.             path = path + '\\' + b
  50.     
  51.     return path
  52.  
  53.  
  54. def splitdrive(p):
  55.     if p[1:2] == ':':
  56.         return (p[0:2], p[2:])
  57.     
  58.     return ('', p)
  59.  
  60.  
  61. def split(p):
  62.     (d, p) = splitdrive(p)
  63.     i = len(p)
  64.     while i and p[i - 1] not in '/\\':
  65.         i = i - 1
  66.     (head, tail) = (p[:i], p[i:])
  67.     head2 = head
  68.     while head2 and head2[-1] in '/\\':
  69.         head2 = head2[:-1]
  70.     if not head2:
  71.         pass
  72.     head = head
  73.     return (d + head, tail)
  74.  
  75.  
  76. def splitext(p):
  77.     (root, ext) = ('', '')
  78.     for c in p:
  79.         if c in '/\\':
  80.             (root, ext) = (root + ext + c, '')
  81.         elif c == '.' or ext:
  82.             ext = ext + c
  83.         else:
  84.             root = root + c
  85.     
  86.     return (root, ext)
  87.  
  88.  
  89. def basename(p):
  90.     return split(p)[1]
  91.  
  92.  
  93. def dirname(p):
  94.     return split(p)[0]
  95.  
  96.  
  97. def commonprefix(m):
  98.     if not m:
  99.         return ''
  100.     
  101.     prefix = m[0]
  102.     for item in m:
  103.         for i in range(len(prefix)):
  104.             if prefix[:i + 1] != item[:i + 1]:
  105.                 prefix = prefix[:i]
  106.                 if i == 0:
  107.                     return ''
  108.                 
  109.                 break
  110.             
  111.         
  112.     
  113.     return prefix
  114.  
  115.  
  116. def getsize(filename):
  117.     st = os.stat(filename)
  118.     return st[stat.ST_SIZE]
  119.  
  120.  
  121. def getmtime(filename):
  122.     st = os.stat(filename)
  123.     return st[stat.ST_MTIME]
  124.  
  125.  
  126. def getatime(filename):
  127.     st = os.stat(filename)
  128.     return st[stat.ST_ATIME]
  129.  
  130.  
  131. def islink(path):
  132.     return 0
  133.  
  134.  
  135. def exists(path):
  136.     
  137.     try:
  138.         st = os.stat(path)
  139.     except os.error:
  140.         return 0
  141.  
  142.     return 1
  143.  
  144.  
  145. def isdir(path):
  146.     
  147.     try:
  148.         st = os.stat(path)
  149.     except os.error:
  150.         return 0
  151.  
  152.     return stat.S_ISDIR(st[stat.ST_MODE])
  153.  
  154.  
  155. def isfile(path):
  156.     
  157.     try:
  158.         st = os.stat(path)
  159.     except os.error:
  160.         return 0
  161.  
  162.     return stat.S_ISREG(st[stat.ST_MODE])
  163.  
  164.  
  165. def ismount(path):
  166.     return isabs(splitdrive(path)[1])
  167.  
  168.  
  169. def walk(top, func, arg):
  170.     
  171.     try:
  172.         names = os.listdir(top)
  173.     except os.error:
  174.         return None
  175.  
  176.     func(arg, top, names)
  177.     exceptions = ('.', '..')
  178.     for name in names:
  179.         if name not in exceptions:
  180.             name = join(top, name)
  181.             if isdir(name):
  182.                 walk(name, func, arg)
  183.             
  184.         
  185.     
  186.  
  187.  
  188. def expanduser(path):
  189.     if path[:1] != '~':
  190.         return path
  191.     
  192.     (i, n) = (1, len(path))
  193.     while i < n and path[i] not in '/\\':
  194.         i = i + 1
  195.     if i == 1:
  196.         if not os.environ.has_key('HOME'):
  197.             return path
  198.         
  199.         userhome = os.environ['HOME']
  200.     else:
  201.         return path
  202.     return userhome + path[i:]
  203.  
  204.  
  205. def expandvars(path):
  206.     if '$' not in path:
  207.         return path
  208.     
  209.     import string
  210.     varchars = string.ascii_letters + string.digits + '_-'
  211.     res = ''
  212.     index = 0
  213.     pathlen = len(path)
  214.     while index < pathlen:
  215.         c = path[index]
  216.         if c == "'":
  217.             path = path[index + 1:]
  218.             pathlen = len(path)
  219.             
  220.             try:
  221.                 index = path.index("'")
  222.                 res = res + "'" + path[:index + 1]
  223.             except ValueError:
  224.                 res = res + path
  225.                 index = pathlen - 1
  226.  
  227.         elif c == '$':
  228.             if path[index + 1:index + 2] == '$':
  229.                 res = res + c
  230.                 index = index + 1
  231.             elif path[index + 1:index + 2] == '{':
  232.                 path = path[index + 2:]
  233.                 pathlen = len(path)
  234.                 
  235.                 try:
  236.                     index = path.index('}')
  237.                     var = path[:index]
  238.                     if os.environ.has_key(var):
  239.                         res = res + os.environ[var]
  240.                 except ValueError:
  241.                     res = res + path
  242.                     index = pathlen - 1
  243.  
  244.             else:
  245.                 var = ''
  246.                 index = index + 1
  247.                 c = path[index:index + 1]
  248.                 while c != '' and c in varchars:
  249.                     var = var + c
  250.                     index = index + 1
  251.                     c = path[index:index + 1]
  252.                 if os.environ.has_key(var):
  253.                     res = res + os.environ[var]
  254.                 
  255.                 if c != '':
  256.                     res = res + c
  257.                 
  258.         else:
  259.             res = res + c
  260.         index = index + 1
  261.     return res
  262.  
  263.  
  264. def normpath(path):
  265.     path = path.replace('/', '\\')
  266.     (prefix, path) = splitdrive(path)
  267.     while path[:1] == '\\':
  268.         prefix = prefix + '\\'
  269.         path = path[1:]
  270.     comps = path.split('\\')
  271.     i = 0
  272.     while i < len(comps):
  273.         if comps[i] == '.':
  274.             del comps[i]
  275.         elif comps[i] == '..' and i > 0 and comps[i - 1] not in ('', '..'):
  276.             del comps[i - 1:i + 1]
  277.             i = i - 1
  278.         elif comps[i] == '' and i > 0 and comps[i - 1] != '':
  279.             del comps[i]
  280.         elif '.' in comps[i]:
  281.             comp = comps[i].split('.')
  282.             comps[i] = comp[0][:8] + '.' + comp[1][:3]
  283.             i = i + 1
  284.         elif len(comps[i]) > 8:
  285.             comps[i] = comps[i][:8]
  286.             i = i + 1
  287.         else:
  288.             i = i + 1
  289.     if not prefix and not comps:
  290.         comps.append('.')
  291.     
  292.     return prefix + '\\'.join(comps)
  293.  
  294.  
  295. def abspath(path):
  296.     if not isabs(path):
  297.         path = join(os.getcwd(), path)
  298.     
  299.     return normpath(path)
  300.  
  301. realpath = abspath
  302.