コード例 #1
0
ファイル: win32.py プロジェクト: yangdy-buji/idea-community
def system_rcpath_win32():
    '''return default os-specific hgrc search path'''
    proc = win32api.GetCurrentProcess()
    try:
        # This will fail on windows < NT
        filename = win32process.GetModuleFileNameEx(proc, 0)
    except:
        filename = win32api.GetModuleFileName(0)
    # Use mercurial.ini found in directory with hg.exe
    progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
    if os.path.isfile(progrc):
        return [progrc]
    # Use hgrc.d found in directory with hg.exe
    progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
    if os.path.isdir(progrcd):
        rcpath = []
        for f, kind in osutil.listdir(progrcd):
            if f.endswith('.rc'):
                rcpath.append(os.path.join(progrcd, f))
        return rcpath
    # else look for a system rcpath in the registry
    try:
        value = win32api.RegQueryValue(
                win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial')
        rcpath = []
        for p in value.split(os.pathsep):
            if p.lower().endswith('mercurial.ini'):
                rcpath.append(p)
            elif os.path.isdir(p):
                for f, kind in osutil.listdir(p):
                    if f.endswith('.rc'):
                        rcpath.append(os.path.join(p, f))
        return rcpath
    except pywintypes.error:
        return []
コード例 #2
0
ファイル: scmutil.py プロジェクト: sandeepprasanna/ODOO
 def systemrcpath():
     '''return default os-specific hgrc search path'''
     rcpath = []
     filename = util.executablepath()
     # Use mercurial.ini found in directory with hg.exe
     progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
     if os.path.isfile(progrc):
         rcpath.append(progrc)
         return rcpath
     # Use hgrc.d found in directory with hg.exe
     progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
     if os.path.isdir(progrcd):
         for f, kind in osutil.listdir(progrcd):
             if f.endswith('.rc'):
                 rcpath.append(os.path.join(progrcd, f))
         return rcpath
     # else look for a system rcpath in the registry
     value = util.lookupreg('SOFTWARE\\Mercurial', None,
                            _HKEY_LOCAL_MACHINE)
     if not isinstance(value, str) or not value:
         return rcpath
     value = value.replace('/', os.sep)
     for p in value.split(os.pathsep):
         if p.lower().endswith('mercurial.ini'):
             rcpath.append(p)
         elif os.path.isdir(p):
             for f, kind in osutil.listdir(p):
                 if f.endswith('.rc'):
                     rcpath.append(os.path.join(p, f))
     return rcpath
コード例 #3
0
ファイル: scmwindows.py プロジェクト: pierfort123/mercurial
def systemrcpath():
    '''return default os-specific hgrc search path'''
    rcpath = []
    filename = util.executablepath()
    # Use mercurial.ini found in directory with hg.exe
    progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
    if os.path.isfile(progrc):
        rcpath.append(progrc)
        return rcpath
    # Use hgrc.d found in directory with hg.exe
    progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
    if os.path.isdir(progrcd):
        for f, kind in osutil.listdir(progrcd):
            if f.endswith('.rc'):
                rcpath.append(os.path.join(progrcd, f))
        return rcpath
    # else look for a system rcpath in the registry
    value = util.lookupreg('SOFTWARE\\Mercurial', None,
                           _winreg.HKEY_LOCAL_MACHINE)
    if not isinstance(value, str) or not value:
        return rcpath
    value = util.localpath(value)
    for p in value.split(os.pathsep):
        if p.lower().endswith('mercurial.ini'):
            rcpath.append(p)
        elif os.path.isdir(p):
            for f, kind in osutil.listdir(p):
                if f.endswith('.rc'):
                    rcpath.append(os.path.join(p, f))
    return rcpath
コード例 #4
0
ファイル: util.py プロジェクト: rybesh/mysite-lib
def copyfiles(src, dst, hardlink=None):
    """Copy a directory tree using hardlinks if possible"""

    if hardlink is None:
        hardlink = (os.stat(src).st_dev ==
                    os.stat(os.path.dirname(dst)).st_dev)

    num = 0
    if os.path.isdir(src):
        os.mkdir(dst)
        for name, kind in osutil.listdir(src):
            srcname = os.path.join(src, name)
            dstname = os.path.join(dst, name)
            hardlink, n = copyfiles(srcname, dstname, hardlink)
            num += n
    else:
        if hardlink:
            try:
                oslink(src, dst)
            except (IOError, OSError):
                hardlink = False
                shutil.copy(src, dst)
        else:
            shutil.copy(src, dst)
        num += 1

    return hardlink, num
コード例 #5
0
ファイル: windows.py プロジェクト: html-shell/mozilla-build
def statfiles(files):
    '''Stat each file in files. Yield each stat, or None if a file
    does not exist or has a type we don't care about.

    Cluster and cache stat per directory to minimize number of OS stat calls.'''
    dircache = {} # dirname -> filename -> status | None if file does not exist
    getkind = stat.S_IFMT
    for nf in files:
        nf  = normcase(nf)
        dir, base = os.path.split(nf)
        if not dir:
            dir = '.'
        cache = dircache.get(dir, None)
        if cache is None:
            try:
                dmap = dict([(normcase(n), s)
                             for n, k, s in osutil.listdir(dir, True)
                             if getkind(s.st_mode) in _wantedkinds])
            except OSError as err:
                # Python >= 2.5 returns ENOENT and adds winerror field
                # EINVAL is raised if dir is not a directory.
                if err.errno not in (errno.ENOENT, errno.EINVAL,
                                     errno.ENOTDIR):
                    raise
                dmap = {}
            cache = dircache.setdefault(dir, dmap)
        yield cache.get(base, None)
コード例 #6
0
def statfiles(files):
    '''Stat each file in files and yield stat or None if file does not exist.
    Cluster and cache stat per directory to minimize number of OS stat calls.'''
    ncase = os.path.normcase
    dircache = {} # dirname -> filename -> status | None if file does not exist
    for nf in files:
        nf  = ncase(nf)
        dir, base = os.path.split(nf)
        if not dir:
            dir = '.'
        cache = dircache.get(dir, None)
        if cache is None:
            try:
                dmap = dict([(ncase(n), s)
                    for n, k, s in osutil.listdir(dir, True)])
            except OSError, err:
                # handle directory not found in Python version prior to 2.5
                # Python <= 2.4 returns native Windows code 3 in errno
                # Python >= 2.5 returns ENOENT and adds winerror field
                # EINVAL is raised if dir is not a directory.
                if err.errno not in (3, errno.ENOENT, errno.EINVAL,
                                     errno.ENOTDIR):
                    raise
                dmap = {}
            cache = dircache.setdefault(dir, dmap)
        yield cache.get(base, None)
コード例 #7
0
ファイル: windows.py プロジェクト: CSCI-362-02-2015/RedTeam
def statfiles(files):
    '''Stat each file in files. Yield each stat, or None if a file
    does not exist or has a type we don't care about.

    Cluster and cache stat per directory to minimize number of OS stat calls.'''
    dircache = {
    }  # dirname -> filename -> status | None if file does not exist
    getkind = stat.S_IFMT
    for nf in files:
        nf = normcase(nf)
        dir, base = os.path.split(nf)
        if not dir:
            dir = '.'
        cache = dircache.get(dir, None)
        if cache is None:
            try:
                dmap = dict([(normcase(n), s)
                             for n, k, s in osutil.listdir(dir, True)
                             if getkind(s.st_mode) in _wantedkinds])
            except OSError as err:
                # Python >= 2.5 returns ENOENT and adds winerror field
                # EINVAL is raised if dir is not a directory.
                if err.errno not in (errno.ENOENT, errno.EINVAL,
                                     errno.ENOTDIR):
                    raise
                dmap = {}
            cache = dircache.setdefault(dir, dmap)
        yield cache.get(base, None)
コード例 #8
0
ファイル: util.py プロジェクト: ezc/mercurial
def copyfiles(src, dst, hardlink=None):
    """Copy a directory tree using hardlinks if possible"""

    if hardlink is None:
        hardlink = (os.stat(src).st_dev == os.stat(
            os.path.dirname(dst)).st_dev)

    num = 0
    if os.path.isdir(src):
        os.mkdir(dst)
        for name, kind in osutil.listdir(src):
            srcname = os.path.join(src, name)
            dstname = os.path.join(dst, name)
            hardlink, n = copyfiles(srcname, dstname, hardlink)
            num += n
    else:
        if hardlink:
            try:
                os_link(src, dst)
            except (IOError, OSError):
                hardlink = False
                shutil.copy(src, dst)
        else:
            shutil.copy(src, dst)
        num += 1

    return hardlink, num
コード例 #9
0
ファイル: windows.py プロジェクト: yangdy-buji/idea-community
def statfiles(files):
    '''Stat each file in files and yield stat or None if file does not exist.
    Cluster and cache stat per directory to minimize number of OS stat calls.'''
    ncase = os.path.normcase
    dircache = {
    }  # dirname -> filename -> status | None if file does not exist
    for nf in files:
        nf = ncase(nf)
        dir, base = os.path.split(nf)
        if not dir:
            dir = '.'
        cache = dircache.get(dir, None)
        if cache is None:
            try:
                dmap = dict([(ncase(n), s)
                             for n, k, s in osutil.listdir(dir, True)])
            except OSError, err:
                # handle directory not found in Python version prior to 2.5
                # Python <= 2.4 returns native Windows code 3 in errno
                # Python >= 2.5 returns ENOENT and adds winerror field
                # EINVAL is raised if dir is not a directory.
                if err.errno not in (3, errno.ENOENT, errno.EINVAL,
                                     errno.ENOTDIR):
                    raise
                dmap = {}
            cache = dircache.setdefault(dir, dmap)
        yield cache.get(base, None)
コード例 #10
0
def _rcfiles(path):
    rcs = [os.path.join(path, "hgrc")]
    rcdir = os.path.join(path, "hgrc.d")
    try:
        rcs.extend([os.path.join(rcdir, f) for f, kind in osutil.listdir(rcdir) if f.endswith(".rc")])
    except OSError:
        pass
    return rcs
コード例 #11
0
def _removedirs(name):
    """special version of os.removedirs that does not remove symlinked
    directories or junction points if they actually contain files"""
    if osutil.listdir(name):
        return
    os.rmdir(name)
    head, tail = os.path.split(name)
    if not tail:
        head, tail = os.path.split(head)
    while head and tail:
        try:
            if osutil.listdir(head):
                return
            os.rmdir(head)
        except:
            break
        head, tail = os.path.split(head)
コード例 #12
0
ファイル: windows.py プロジェクト: yangdy-buji/idea-community
def _removedirs(name):
    """special version of os.removedirs that does not remove symlinked
    directories or junction points if they actually contain files"""
    if osutil.listdir(name):
        return
    os.rmdir(name)
    head, tail = os.path.split(name)
    if not tail:
        head, tail = os.path.split(head)
    while head and tail:
        try:
            if osutil.listdir(head):
                return
            os.rmdir(head)
        except:
            break
        head, tail = os.path.split(head)
コード例 #13
0
 def rcfiles(path):
     rcs = [os.path.join(path, 'hgrc')]
     rcdir = os.path.join(path, 'hgrc.d')
     try:
         rcs.extend([os.path.join(rcdir, f)
                     for f, kind in osutil.listdir(rcdir)
                     if f.endswith(".rc")])
     except OSError:
         pass
     return rcs
コード例 #14
0
def osrcpath():
    '''return default os-specific hgrc search path'''
    path = []
    defaultpath = os.path.join(util.datapath, 'default.d')
    if os.path.isdir(defaultpath):
        for f, kind in osutil.listdir(defaultpath):
            if f.endswith('.rc'):
                path.append(os.path.join(defaultpath, f))
    path.extend(systemrcpath())
    path.extend(userrcpath())
    path = [os.path.normpath(f) for f in path]
    return path
コード例 #15
0
ファイル: scmutil.py プロジェクト: CSCI-362-02-2015/RedTeam
def osrcpath():
    '''return default os-specific hgrc search path'''
    path = []
    defaultpath = os.path.join(util.datapath, 'default.d')
    if os.path.isdir(defaultpath):
        for f, kind in osutil.listdir(defaultpath):
            if f.endswith('.rc'):
                path.append(os.path.join(defaultpath, f))
    path.extend(systemrcpath())
    path.extend(userrcpath())
    path = [os.path.normpath(f) for f in path]
    return path
コード例 #16
0
ファイル: streamclone.py プロジェクト: saminigod/cygwin
 def walk(path, recurse):
     for e, kind, st in osutil.listdir(path, stat=True):
         pe = os.path.join(path, e)
         if kind == stat.S_IFDIR:
             if recurse:
                 for x in walk(pe, True):
                     yield x
         else:
             if kind != stat.S_IFREG or len(e) < 2:
                 continue
             sfx = e[-2:]
             if sfx in ('.d', '.i'):
                 yield pe[strip_count:], st.st_size
コード例 #17
0
ファイル: streamclone.py プロジェクト: c0ns0le/cygwin
 def walk(path, recurse):
     for e, kind, st in osutil.listdir(path, stat=True):
         pe = os.path.join(path, e)
         if kind == stat.S_IFDIR:
             if recurse:
                 for x in walk(pe, True):
                     yield x
         else:
             if kind != stat.S_IFREG or len(e) < 2:
                 continue
             sfx = e[-2:]
             if sfx in ('.d', '.i'):
                 yield pe[strip_count:], st.st_size
コード例 #18
0
 def _walk(self, relpath, recurse):
     '''yields (unencoded, encoded, size)'''
     path = self.pathjoiner(self.path, relpath)
     striplen = len(self.path) + len(os.sep)
     l = []
     if os.path.isdir(path):
         visit = [path]
         while visit:
             p = visit.pop()
             for f, kind, st in osutil.listdir(p, stat=True):
                 fp = self.pathjoiner(p, f)
                 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
                     n = util.pconvert(fp[striplen:])
                     l.append((decodedir(n), n, st.st_size))
                 elif kind == stat.S_IFDIR and recurse:
                     visit.append(fp)
     return sorted(l)
コード例 #19
0
ファイル: store.py プロジェクト: ThissDJ/designhub
 def _walk(self, relpath, recurse):
     '''yields (unencoded, encoded, size)'''
     path = self.pathjoiner(self.path, relpath)
     striplen = len(self.path) + len(os.sep)
     l = []
     if os.path.isdir(path):
         visit = [path]
         while visit:
             p = visit.pop()
             for f, kind, st in osutil.listdir(p, stat=True):
                 fp = self.pathjoiner(p, f)
                 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
                     n = util.pconvert(fp[striplen:])
                     l.append((decodedir(n), n, st.st_size))
                 elif kind == stat.S_IFDIR and recurse:
                     visit.append(fp)
     return sorted(l)
コード例 #20
0
 def _walk(self, relpath, recurse):
     """yields (unencoded, encoded, size)"""
     path = self.path
     if relpath:
         path += "/" + relpath
     striplen = len(self.path) + 1
     l = []
     if os.path.isdir(path):
         visit = [path]
         while visit:
             p = visit.pop()
             for f, kind, st in osutil.listdir(p, stat=True):
                 fp = p + "/" + f
                 if kind == stat.S_IFREG and f[-2:] in (".d", ".i"):
                     n = util.pconvert(fp[striplen:])
                     l.append((decodedir(n), n, st.st_size))
                 elif kind == stat.S_IFDIR and recurse:
                     visit.append(fp)
     return sorted(l)
コード例 #21
0
def rcpath():
    '''return hgrc search path. if env var HGRCPATH is set, use it.
    for each item in path, if directory, use files ending in .rc,
    else use item.
    make HGRCPATH empty to only look in .hg/hgrc of current repo.
    if no HGRCPATH, use default os-specific path.'''
    global _rcpath
    if _rcpath is None:
        if 'HGRCPATH' in os.environ:
            _rcpath = []
            for p in os.environ['HGRCPATH'].split(os.pathsep):
                if not p: continue
                if os.path.isdir(p):
                    for f, kind in osutil.listdir(p):
                        if f.endswith('.rc'):
                            _rcpath.append(os.path.join(p, f))
                else:
                    _rcpath.append(p)
        else:
            _rcpath = os_rcpath()
    return _rcpath
コード例 #22
0
ファイル: util.py プロジェクト: dkrisman/Traipse
def rcpath():
    '''return hgrc search path. if env var HGRCPATH is set, use it.
    for each item in path, if directory, use files ending in .rc,
    else use item.
    make HGRCPATH empty to only look in .hg/hgrc of current repo.
    if no HGRCPATH, use default os-specific path.'''
    global _rcpath
    if _rcpath is None:
        if 'HGRCPATH' in os.environ:
            _rcpath = []
            for p in os.environ['HGRCPATH'].split(os.pathsep):
                if not p: continue
                if os.path.isdir(p):
                    for f, kind in osutil.listdir(p):
                        if f.endswith('.rc'):
                            _rcpath.append(os.path.join(p, f))
                else:
                    _rcpath.append(p)
        else:
            _rcpath = os_rcpath()
    return _rcpath
コード例 #23
0
 def readdir(self, path=None, stat=None, skip=None):
     return osutil.listdir(self.join(path), stat, skip)
コード例 #24
0
ファイル: scmutil.py プロジェクト: CSCI-362-02-2015/RedTeam
 def readdir(self, path=None, stat=None, skip=None):
     return osutil.listdir(self.join(path), stat, skip)