Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 5396:5105b119edd2
Add osutil module, containing a listdir function.
This is similar to os.listdir, only it returns a sorted list of tuples.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Fri, 05 Oct 2007 15:01:06 -0700 |
parents | b98c377b3c16 |
children | 6d1bd20ae14d |
comparison
equal
deleted
inserted
replaced
5395:e73a83af7926 | 5396:5105b119edd2 |
---|---|
12 platform-specific details from the core. | 12 platform-specific details from the core. |
13 """ | 13 """ |
14 | 14 |
15 from i18n import _ | 15 from i18n import _ |
16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil | 16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil |
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob | 17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil |
18 | 18 |
19 try: | 19 try: |
20 set = set | 20 set = set |
21 frozenset = frozenset | 21 frozenset = frozenset |
22 except NameError: | 22 except NameError: |
674 hardlink = (os.stat(src).st_dev == | 674 hardlink = (os.stat(src).st_dev == |
675 os.stat(os.path.dirname(dst)).st_dev) | 675 os.stat(os.path.dirname(dst)).st_dev) |
676 | 676 |
677 if os.path.isdir(src): | 677 if os.path.isdir(src): |
678 os.mkdir(dst) | 678 os.mkdir(dst) |
679 for name in os.listdir(src): | 679 for name, kind in osutil.listdir(src): |
680 srcname = os.path.join(src, name) | 680 srcname = os.path.join(src, name) |
681 dstname = os.path.join(dst, name) | 681 dstname = os.path.join(dst, name) |
682 copyfiles(srcname, dstname, hardlink) | 682 copyfiles(srcname, dstname, hardlink) |
683 else: | 683 else: |
684 if hardlink: | 684 if hardlink: |
1058 | 1058 |
1059 def rcfiles(path): | 1059 def rcfiles(path): |
1060 rcs = [os.path.join(path, 'hgrc')] | 1060 rcs = [os.path.join(path, 'hgrc')] |
1061 rcdir = os.path.join(path, 'hgrc.d') | 1061 rcdir = os.path.join(path, 'hgrc.d') |
1062 try: | 1062 try: |
1063 rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir) | 1063 rcs.extend([os.path.join(rcdir, f) |
1064 for f, kind in osutil.listdir(rcdir) | |
1064 if f.endswith(".rc")]) | 1065 if f.endswith(".rc")]) |
1065 except OSError: | 1066 except OSError: |
1066 pass | 1067 pass |
1067 return rcs | 1068 return rcs |
1068 | 1069 |
1651 if 'HGRCPATH' in os.environ: | 1652 if 'HGRCPATH' in os.environ: |
1652 _rcpath = [] | 1653 _rcpath = [] |
1653 for p in os.environ['HGRCPATH'].split(os.pathsep): | 1654 for p in os.environ['HGRCPATH'].split(os.pathsep): |
1654 if not p: continue | 1655 if not p: continue |
1655 if os.path.isdir(p): | 1656 if os.path.isdir(p): |
1656 for f in os.listdir(p): | 1657 for f, kind in osutil.listdir(p): |
1657 if f.endswith('.rc'): | 1658 if f.endswith('.rc'): |
1658 _rcpath.append(os.path.join(p, f)) | 1659 _rcpath.append(os.path.join(p, f)) |
1659 else: | 1660 else: |
1660 _rcpath.append(p) | 1661 _rcpath.append(p) |
1661 else: | 1662 else: |