当前位置: 首页>>代码示例>>Python>>正文


Python os.fchdir方法代码示例

本文整理汇总了Python中os.fchdir方法的典型用法代码示例。如果您正苦于以下问题:Python os.fchdir方法的具体用法?Python os.fchdir怎么用?Python os.fchdir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.fchdir方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _recursive_dirlist

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
    for (name,pst) in _dirlist():
        if name.endswith('/'):
            if xdev != None and pst.st_dev != xdev:
                debug1('Skipping %r: different filesystem.\n' % (prepend+name))
                continue
            if bup_dir != None:
                if os.path.normpath(prepend+name) == bup_dir:
                    debug1('Skipping BUP_DIR.\n')
                    continue
            if excluded_paths:
                if os.path.normpath(prepend+name) in excluded_paths:
                    debug1('Skipping %r: excluded.\n' % (prepend+name))
                    continue
            try:
                OsFile(name).fchdir()
            except OSError, e:
                add_error('%s: %s' % (prepend, e))
            else:
                for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
                                            bup_dir=bup_dir,
                                            excluded_paths=excluded_paths):
                    yield i
                os.chdir('..')
        yield (prepend + name, pst) 
开发者ID:omererdem,项目名称:honeything,代码行数:27,代码来源:drecurse.py

示例2: lookupId

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def lookupId(self, root, theId):
        theName = self.idCache.get(theId, None)
        if theName is not None:
            return theName

        if root and root != '/':
            curDir = os.open(".", os.O_RDONLY)
            os.chdir("/")
            os.chroot(root)

        name = self.idLookupFn(theId)[0]
        if root and root != '/':
            os.chroot(".")
            os.fchdir(curDir)
            os.close(curDir)

        self.nameCache[name] = theId
        self.idCache[theId] = name
        return name 
开发者ID:sassoftware,项目名称:conary,代码行数:21,代码来源:files.py

示例3: worker

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def worker():
  serv = Client('\0singe', authkey=b'peekaboo')
  serv.send(os.getpid())
  fd = recv_handle(serv)
  print('WORKER: GOT FD', fd)
  os.fchdir(fd)
  os.execl("/bin/dash", "/bin/dash", "-i") 
开发者ID:singe,项目名称:container-breakouts,代码行数:9,代码来源:worker.py

示例4: fchdir

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def fchdir(self):
        os.fchdir(self.fd) 
开发者ID:omererdem,项目名称:honeything,代码行数:4,代码来源:drecurse.py

示例5: recursive_dirlist

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
    startdir = OsFile('.')
    try:
        assert(type(paths) != type(''))
        for path in paths:
            try:
                pst = xstat.lstat(path)
                if stat.S_ISLNK(pst.st_mode):
                    yield (path, pst)
                    continue
            except OSError, e:
                add_error('recursive_dirlist: %s' % e)
                continue
            try:
                pfile = OsFile(path)
            except OSError, e:
                add_error(e)
                continue
            pst = pfile.stat()
            if xdev:
                xdev = pst.st_dev
            else:
                xdev = None
            if stat.S_ISDIR(pst.st_mode):
                pfile.fchdir()
                prepend = os.path.join(path, '')
                for i in _recursive_dirlist(prepend=prepend, xdev=xdev,
                                            bup_dir=bup_dir,
                                            excluded_paths=excluded_paths):
                    yield i
                startdir.fchdir()
            else:
                prepend = path
            yield (prepend,pst) 
开发者ID:omererdem,项目名称:honeything,代码行数:36,代码来源:drecurse.py

示例6: init

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def init( self, connection ):
        os.fchdir( self.mountPointFd )
        for i in range( len( self.mountSources ) ):
            if self.mountSources[i] == self.mountPoint:
                self.mountSources[i] = '.' 
开发者ID:mxmlnkn,项目名称:ratarmount,代码行数:7,代码来源:ratarmount.py

示例7: executeCommand

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def executeCommand(command):
    cwd = os.getcwd()
    rr = os.open("/", os.O_RDONLY)
    os.chroot(getRootDir.getEnvsDir() + getEnvName())
    os.chdir("/")
    os.system(command)
    os.fchdir(rr)
    os.chroot(".")
    os.chdir(cwd) 
开发者ID:f-prime,项目名称:Coffer,代码行数:11,代码来源:templateUtils.py

示例8: lookupName

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def lookupName(self, root, name):
        theId = self.nameCache.get(name, None)
        if theId is not None:
            return theId

        # if not root, cannot chroot and so fall back to system ids
        getChrootIds = root and root != '/' and not os.getuid()

        if getChrootIds:
            if root[0] != '/':
                root = os.sep.join((os.getcwd(), root))
            curDir = os.open(".", os.O_RDONLY)
            # chdir to the current root to allow us to chroot
            # back out again
            os.chdir('/')
            os.chroot(root)

        if name and name[0] == '+':
            # An id mapped as a string
            try:
                theId = int(name)
            except ValueError:
                log.warning('%s %s does not exist - using root', self.name,
                            name)
        else:
            try:
                theId = self.nameLookupFn(name)[2]
            except KeyError:
                log.warning('%s %s does not exist - using root', self.name, name)
                theId = 0

        if getChrootIds:
            os.chroot(".")
            os.fchdir(curDir)
            os.close(curDir)

        self.nameCache[name] = theId
        self.idCache[theId] = name
        return theId 
开发者ID:sassoftware,项目名称:conary,代码行数:41,代码来源:files.py

示例9: execute_git

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def execute_git(state, repo_git, args, capture=False, capture_stderr=False):
    """Executes a Git command in the given repository, with args being a list
    of arguments (not including git itself). capture and capture_stderr
    arguments causes it to return stdout or stdout+stderr as a string.

    state can be None, but if so, then repo_git needs to be an absolute path.

    The function automatically takes into account Git commands with side effects
    and applies push simulation and dry run if those are enabled."""

    is_push = args[0] == "push"
    is_change = (
        is_push
        or (args[0] == "tag" and len(args) > 1)
        or (args[0] == "branch" and len(args) > 1)
        or (args[0] == "config" and args[1] != "-l")
        or (args[0] == "checkout")
        or (args[0] == "commit")
        or (args[0] == "fetch")
        or (args[0] == "init")
        or (args[0] == "reset")
    )

    if os.path.isabs(repo_git):
        git_dir = repo_git
    else:
        git_dir = os.path.join(state["repo_dir"], repo_git)

    if (not PUSH and is_push) or (DRY_RUN and is_change):
        print("Would have executed: cd %s && git %s" % (git_dir, " ".join(args)))
        return None

    fd = os.open(".", flags=os.O_RDONLY)
    os.chdir(git_dir)
    if capture_stderr:
        stderr = subprocess.STDOUT
    else:
        stderr = None

    try:
        if capture:
            output = (
                subprocess.check_output(["git"] + args, stderr=stderr).decode().strip()
            )
        else:
            output = None
            subprocess.check_call(["git"] + args, stderr=stderr)
    finally:
        os.fchdir(fd)
        os.close(fd)

    return output 
开发者ID:mendersoftware,项目名称:integration,代码行数:54,代码来源:release_tool.py

示例10: flushRpmLog

# 需要导入模块: import os [as 别名]
# 或者: from os import fchdir [as 别名]
def flushRpmLog(self):
        s = os.read(self.logFd, 50000)
        data = ''
        while s:
            data += s
            s = os.read(self.logFd, 50000)

        lines = data.split('\n')
        if not lines:
            return

        # We're in RPM's chroot jail. We'll break out of it so that
        # the callbacks work as expected, but we need to restore both
        # the chroot and the cwd.
        thisRoot = os.open("/", os.O_RDONLY)
        thisDir = os.open(".", os.O_RDONLY)
        concats = []

        try:
            os.fchdir(self.rootFd)
            os.chroot(".")

            for line in lines:
                line.strip()
                if not line:
                    continue

                # this passwd/group stuff is for CNY-3428. Basically group
                # info packages can create users before Red Hat's setup
                # package is installed. this fixes things up.
                if '/etc/passwd.rpmnew' in line:
                    concats.append( ('/etc/passwd', '/etc/passwd.rpmnew') )
                elif '/etc/group.rpmnew' in line:
                    concats.append( ('/etc/group', '/etc/group.rpmnew') )
                elif line.startswith('error:'):
                    line = line[6:].strip()
                    self.callback.error(line)
                elif line.startswith('warning:'):
                    line = line[8:].strip()
                    self.callback.warning(line)
                else:
                    self.callback.warning(line)
        finally:
            os.fchdir(thisRoot)
            os.close(thisRoot)
            os.chroot(".")
            os.fchdir(thisDir)
            os.close(thisDir)

        for (keepPath, fromPath) in concats:
            finalLines = open(fromPath).readlines() + open(keepPath).readlines()
            finalLines = [ (x.split(':')[0], x) for x in finalLines ]
            seen = set()
            f = open(keepPath, "w")
            for (name, line) in finalLines:
                if name not in seen:
                    seen.add(name)
                    f.write(line)

            f.close()
            os.unlink(fromPath) 
开发者ID:sassoftware,项目名称:conary,代码行数:63,代码来源:rpmcapsule.py


注:本文中的os.fchdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。