• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.rename函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mercurial.util.rename函数的典型用法代码示例。如果您正苦于以下问题:Python rename函数的具体用法?Python rename怎么用?Python rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: setwithlimit

 def setwithlimit(self, hexnode, manifest, limit=-1):
     """Writes a manifest to the cache.  Returns True if the cache already
     contains the item or if the write is successful.  Returns False if the
     write fails.  Raises CacheFullException if writing the cache entry would
     cause us to pass the limit.
     """
     if hexnode in self:
         return True
     path = self._pathfromnode(hexnode)
     if (isinstance(manifest, cfastmanifest.fastmanifest) or
         isinstance(manifest, fastmanifestdict)):
         fm = manifest
     else:
         fm = cfastmanifest.fastmanifest(manifest.text())
     tmpfpath = util.mktempcopy(path, True)
     entrysize = fm.bytes()
     if limit != -1 and self.totalsize()[0] + entrysize > limit:
         raise CacheFullException()
     try:
         fm._save(tmpfpath)
         util.rename(tmpfpath, path)
         return True
     except EnvironmentError:
         return False
     finally:
         try:
             os.unlink(tmpfpath)
         except OSError:
             pass
开发者ID:davidshepherd7,项目名称:dotfiles,代码行数:29,代码来源:implementation.py


示例2: unshelveabort

def unshelveabort(ui, repo, state, opts):
    """subcommand that abort an in-progress unshelve"""
    wlock = repo.wlock()
    lock = None
    try:
        checkparents(repo, state)

        util.rename(repo.join('unshelverebasestate'),
                    repo.join('rebasestate'))
        try:
            rebase.rebase(ui, repo, **{
                'abort' : True
            })
        except Exception:
            util.rename(repo.join('rebasestate'),
                        repo.join('unshelverebasestate'))
            raise

        lock = repo.lock()

        mergefiles(ui, repo, state.wctx, state.pendingctx)

        repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve')
        shelvedstate.clear(repo)
        ui.warn(_("unshelve of '%s' aborted\n") % state.name)
    finally:
        lockmod.release(lock, wlock)
开发者ID:roopakparikh,项目名称:crane-node-hello,代码行数:27,代码来源:shelve.py


示例3: unshare

def unshare(ui, repo):
    """convert a shared repository to a normal one

    Copy the store data to the repo and remove the sharedpath data.
    """

    if not repo.shared():
        raise error.Abort(_("this is not a shared repo"))

    destlock = lock = None
    lock = repo.lock()
    try:
        # we use locks here because if we race with commit, we
        # can end up with extra data in the cloned revlogs that's
        # not pointed to by changesets, thus causing verify to
        # fail

        destlock = hg.copystore(ui, repo, repo.path)

        sharefile = repo.join('sharedpath')
        util.rename(sharefile, sharefile + '.old')

        repo.requirements.discard('sharedpath')
        repo._writerequirements()
    finally:
        destlock and destlock.release()
        lock and lock.release()

    # update store, spath, svfs and sjoin of repo
    repo.unfiltered().__init__(repo.baseui, repo.root)
开发者ID:Distrotech,项目名称:mercurial,代码行数:30,代码来源:share.py


示例4: _gethash

    def _gethash(self, filename, hash):
        """Get file with the provided hash and store it in the local repo's
        store and in the usercache.
        filename is for informational messages only.
        """
        util.makedirs(lfutil.storepath(self.repo, ''))
        storefilename = lfutil.storepath(self.repo, hash)

        tmpname = storefilename + '.tmp'
        tmpfile = util.atomictempfile(
            tmpname, createmode=self.repo.store.createmode)

        try:
            gothash = self._getfile(tmpfile, filename, hash)
        except StoreError as err:
            self.ui.warn(err.longmessage())
            gothash = ""
        tmpfile.close()

        if gothash != hash:
            if gothash != "":
                self.ui.warn(
                    _('%s: data corruption (expected %s, got %s)\n') %
                    (filename, hash, gothash))
            util.unlink(tmpname)
            return False

        util.rename(tmpname, storefilename)
        lfutil.linktousercache(self.repo, hash)
        return True
开发者ID:html-shell,项目名称:mozilla-build,代码行数:30,代码来源:basestore.py


示例5: rollback

 def rollback(self, dryrun=False):
     if os.path.exists(self.join('undo.bookmarks')):
         if not dryrun:
             util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
         elif not os.path.exists(self.sjoin("undo")):
             # avoid "no rollback information available" message
             return 0
     return super(bookmark_repo, self).rollback(dryrun)
开发者ID:helloandre,项目名称:cr48,代码行数:8,代码来源:bookmarks.py


示例6: _bind

 def _bind(self, sock):
     # use a unique temp address so we can stat the file and do ownership
     # check later
     tempaddress = _tempaddress(self._realaddress)
     util.bindunixsocket(sock, tempaddress)
     self._socketstat = os.stat(tempaddress)
     # rename will replace the old socket file if exists atomically. the
     # old server will detect ownership change and exit.
     util.rename(tempaddress, self._realaddress)
开发者ID:motlin,项目名称:cyg,代码行数:9,代码来源:chgserver.py


示例7: backup

 def backup(self, repo, files, copy=False):
     # backup local changes in --force case
     for f in sorted(files):
         absf = repo.wjoin(f)
         if os.path.lexists(absf):
             self.ui.note(_('saving current version of %s as %s\n') %
                          (f, f + '.orig'))
             if copy:
                 util.copyfile(absf, absf + '.orig')
             else:
                 util.rename(absf, absf + '.orig')
开发者ID:peiyaoyao,项目名称:intellij-community,代码行数:11,代码来源:mq.py


示例8: get

    def get(self, files):
        '''Get the specified largefiles from the store and write to local
        files under repo.root.  files is a list of (filename, hash)
        tuples.  Return (success, missing), lists of files successfully
        downloaded and those not found in the store.  success is a list
        of (filename, hash) tuples; missing is a list of filenames that
        we could not get.  (The detailed error message will already have
        been presented to the user, so missing is just supplied as a
        summary.)'''
        success = []
        missing = []
        ui = self.ui

        util.makedirs(lfutil.storepath(self.repo, ''))

        at = 0
        available = self.exists(set(hash for (_filename, hash) in files))
        for filename, hash in files:
            ui.progress(_('getting largefiles'), at, unit='lfile',
                total=len(files))
            at += 1
            ui.note(_('getting %s:%s\n') % (filename, hash))

            if not available.get(hash):
                ui.warn(_('%s: largefile %s not available from %s\n')
                        % (filename, hash, self.url))
                missing.append(filename)
                continue

            storefilename = lfutil.storepath(self.repo, hash)
            tmpfile = util.atomictempfile(storefilename + '.tmp',
                                          createmode=self.repo.store.createmode)

            try:
                hhash = self._getfile(tmpfile, filename, hash)
            except StoreError, err:
                ui.warn(err.longmessage())
                hhash = ""
            tmpfile.close()

            if hhash != hash:
                if hhash != "":
                    ui.warn(_('%s: data corruption (expected %s, got %s)\n')
                            % (filename, hash, hhash))
                util.unlink(storefilename + '.tmp')
                missing.append(filename)
                continue

            util.rename(storefilename + '.tmp', storefilename)
            lfutil.linktousercache(self.repo, hash)
            success.append((filename, hhash))
开发者ID:32bitfloat,项目名称:intellij-community,代码行数:51,代码来源:basestore.py


示例9: pickle_atomic

def pickle_atomic(data, file_path, dir=None):
    """pickle some data to a path atomically.

    This is present because I kept corrupting my revmap by managing to hit ^C
    during the pickle of that file.
    """
    try:
        f, path = tempfile.mkstemp(prefix='pickling', dir=dir)
        f = os.fdopen(f, 'w')
        pickle.dump(data, f)
        f.close()
    except: #pragma: no cover
        raise
    else:
        hgutil.rename(path, file_path)
开发者ID:chaptastic,项目名称:config_files,代码行数:15,代码来源:svnmeta.py


示例10: mergefiles

def mergefiles(ui, repo, wctx, shelvectx):
    """updates to wctx and merges the changes from shelvectx into the
    dirstate."""
    with ui.configoverride({('ui', 'quiet'): True}):
        hg.update(repo, wctx.node())
        files = []
        files.extend(shelvectx.files())
        files.extend(shelvectx.parents()[0].files())

        # revert will overwrite unknown files, so move them out of the way
        for file in repo.status(unknown=True).unknown:
            if file in files:
                util.rename(file, scmutil.origpath(ui, repo, file))
        ui.pushbuffer(True)
        cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
                       *pathtofiles(repo, files),
                       **{'no_backup': True})
        ui.popbuffer()
开发者ID:davidshepherd7,项目名称:dotfiles,代码行数:18,代码来源:obsshelve.py


示例11: unshelvecontinue

def unshelvecontinue(ui, repo, state, opts):
    """subcommand to continue an in-progress unshelve"""
    # We're finishing off a merge. First parent is our original
    # parent, second is the temporary "fake" commit we're unshelving.
    wlock = repo.wlock()
    lock = None
    try:
        checkparents(repo, state)
        ms = merge.mergestate(repo)
        if [f for f in ms if ms[f] == 'u']:
            raise error.Abort(
                _("unresolved conflicts, can't continue"),
                hint=_("see 'hg resolve', then 'hg unshelve --continue'"))

        lock = repo.lock()

        util.rename(repo.join('unshelverebasestate'),
                    repo.join('rebasestate'))
        try:
            rebase.rebase(ui, repo, **{
                'continue' : True
            })
        except Exception:
            util.rename(repo.join('rebasestate'),
                        repo.join('unshelverebasestate'))
            raise

        shelvectx = repo['tip']
        if not shelvectx in state.pendingctx.children():
            # rebase was a no-op, so it produced no child commit
            shelvectx = state.pendingctx
        else:
            # only strip the shelvectx if the rebase produced it
            state.stripnodes.append(shelvectx.node())

        mergefiles(ui, repo, state.wctx, shelvectx)

        repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve')
        shelvedstate.clear(repo)
        unshelvecleanup(ui, repo, state.name, opts)
        ui.status(_("unshelve of '%s' complete\n") % state.name)
    finally:
        lockmod.release(lock, wlock)
开发者ID:html-shell,项目名称:mozilla-build,代码行数:43,代码来源:shelve.py


示例12: server_bind

 def server_bind(self):
     # use a unique temp address so we can stat the file and do ownership
     # check later
     tempaddress = _tempaddress(self.server_address)
     # use relative path instead of full path at bind() if possible, since
     # AF_UNIX path has very small length limit (107 chars) on common
     # platforms (see sys/un.h)
     dirname, basename = os.path.split(tempaddress)
     bakwdfd = None
     if dirname:
         bakwdfd = os.open('.', os.O_DIRECTORY)
         os.chdir(dirname)
     self.socket.bind(basename)
     self._socketstat = os.stat(basename)
     # rename will replace the old socket file if exists atomically. the
     # old server will detect ownership change and exit.
     util.rename(basename, self.server_address)
     if bakwdfd:
         os.fchdir(bakwdfd)
         os.close(bakwdfd)
开发者ID:cmjonze,项目名称:mercurial,代码行数:20,代码来源:chgserver.py


示例13: stripmarker

def stripmarker(ui, repo, markers):
    """remove <markers> from the repo obsstore

    The old obsstore content is saved in a `obsstore.prestrip` file
    """
    repo = repo.unfiltered()
    repo.destroying()
    oldmarkers = list(repo.obsstore._all)
    util.rename(repo.sjoin('obsstore'),
                repo.join('obsstore.prestrip'))
    del repo.obsstore # drop the cache
    newstore = repo.obsstore
    assert not newstore # should be empty after rename
    newmarkers = [m for m in oldmarkers if m not in markers]
    tr = repo.transaction('drophack')
    try:
        newstore.add(tr, newmarkers)
        tr.close()
    finally:
        tr.release()
    repo.destroyed()
开发者ID:dan-passaro,项目名称:hgrc,代码行数:21,代码来源:drophack.py


示例14: mergefiles

def mergefiles(ui, repo, wctx, shelvectx):
    """updates to wctx and merges the changes from shelvectx into the
    dirstate."""
    oldquiet = ui.quiet
    try:
        ui.quiet = True
        hg.update(repo, wctx.node())
        files = []
        files.extend(shelvectx.files())
        files.extend(shelvectx.parents()[0].files())

        # revert will overwrite unknown files, so move them out of the way
        m, a, r, d, u = repo.status(unknown=True)[:5]
        for file in u:
            if file in files:
                util.rename(file, file + ".orig")
        cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
                       *pathtofiles(repo, files),
                       **{'no_backup': True})
    finally:
        ui.quiet = oldquiet
开发者ID:roopakparikh,项目名称:crane-node-hello,代码行数:21,代码来源:shelve.py


示例15: unsharejournal

def unsharejournal(orig, ui, repo, repopath):
    """Copy shared journal entries into this repo when unsharing"""
    if (repo.path == repopath and repo.shared() and
            util.safehasattr(repo, 'journal')):
        sharedrepo = share._getsrcrepo(repo)
        sharedfeatures = _readsharedfeatures(repo)
        if sharedrepo and sharedfeatures > set(['journal']):
            # there is a shared repository and there are shared journal entries
            # to copy. move shared date over from source to destination but
            # move the local file first
            if repo.vfs.exists('namejournal'):
                journalpath = repo.join('namejournal')
                util.rename(journalpath, journalpath + '.bak')
            storage = repo.journal
            local = storage._open(
                repo.vfs, filename='namejournal.bak', _newestfirst=False)
            shared = (
                e for e in storage._open(sharedrepo.vfs, _newestfirst=False)
                if sharednamespaces.get(e.namespace) in sharedfeatures)
            for entry in _mergeentriesiter(local, shared, order=min):
                storage._write(repo.vfs, entry)

    return orig(ui, repo, repopath)
开发者ID:motlin,项目名称:cyg,代码行数:23,代码来源:journal.py


示例16: _createsymlink

 def _createsymlink(self):
     if self._baseaddress == self._realaddress:
         return
     tempaddress = _tempaddress(self._baseaddress)
     os.symlink(os.path.basename(self._realaddress), tempaddress)
     util.rename(tempaddress, self._baseaddress)
开发者ID:motlin,项目名称:cyg,代码行数:6,代码来源:chgserver.py


示例17: rollback

 def rollback(self):
     if os.path.exists(self.join("undo.bookmarks")):
         util.rename(self.join("undo.bookmarks"), self.join("bookmarks"))
     return super(bookmark_repo, self).rollback()
开发者ID:fuzxxl,项目名称:plan9front,代码行数:4,代码来源:bookmarks.py


示例18: uncrustify

def uncrustify(ui, repo, *patterns, **options):
    """Run uncrustify on the specified files or directories.

    If no files are specified, operates on the whole working
    directory.

    Note: Files that don't have a .cc or .h suffix are always ignored,
    even if specified on the command line explicitly.

    By default, prints a list of files that are not clean according to
    uncrustify, using a similar output format as with hg status. No
    changes are made to the working directory.

    With the --diff option, prints the changes suggested by uncrustify
    in unified diff format. No changes are made to the working
    directory.

    With the --modify option, actually performs the changes suggested
    by uncrustify. The original (dirty) files are backed up with a
    .crusty suffix. Existing files with such a suffix are silently
    overwritten. To disable these backups, use --no-backup.

    This command always operates on the working directory, not on
    arbitrary repository revisions.

    Returns 0 on success.
    """
    if options["diff"] and options["modify"]:
        raise util.Abort("cannot specify --diff and --modify at the same time")

    if options["diff"]:
        mode = "diff"
    elif options["modify"]:
        mode = "modify"
    else:
        mode = "status"

    no_backup = options["no_backup"]
    show_clean = options["show_clean"]

    paths = [path for path in _get_files(repo, patterns, options)
             if path.endswith((".cc", ".h"))]


    uncrustify_cfg = repo.pathto(".uncrustify.cfg")
    relpaths = [repo.pathto(path) for path in paths]
    if not os.path.exists(uncrustify_cfg):
        raise util.Abort("could not find .uncrustify.cfg in repository root")
    _run_uncrustify(uncrustify_cfg, relpaths)

    ctx = repo[None]
    for path in paths:
        relpath = repo.pathto(path)
        uncr_path = path + SUFFIX
        uncr_relpath = relpath + SUFFIX
        have_changes = (ctx[path].data() != ctx[uncr_path].data())

        if have_changes:
            if mode == "status":
                ui.write("M %s\n" % relpath, label="status.modified")
                util.unlink(uncr_relpath)
            elif mode == "diff":
                _run_diff(relpath, uncr_relpath)
                util.unlink(uncr_relpath)
            elif mode == "modify":
                if not no_backup:
                    util.rename(relpath, relpath + ".crusty")
                util.rename(uncr_relpath, relpath)
                if not ui.quiet:
                    ui.write("%s uncrustified\n" % relpath)
        else:
            if show_clean:
                if mode == "status":
                    ui.write("C %s\n" % relpath, label="status.clean")
                elif mode == "modify":
                    ui.write("%s is clean\n" % relpath)
            util.unlink(uncr_relpath)
开发者ID:harmankumar,项目名称:AI-Assignment3,代码行数:77,代码来源:uncrustify.py


示例19: in

            tr.close()
        except: # re-raises
            # Abort transaction first, so we truncate the files before
            # deleting them.
            tr.abort()
            for fn in (tmpindexfn, tmpdatafn):
                ignoremissing(os.unlink)(fn)
            raise
        if not opts.get('dry_run'):
            # racy, both files cannot be renamed atomically
            # copy files
            util.oslink(indexfn, oldindexfn)
            ignoremissing(util.oslink)(datafn, olddatafn)

            # rename
            util.rename(tmpindexfn, indexfn)
            try:
                os.chmod(tmpdatafn, os.stat(datafn).st_mode)
                util.rename(tmpdatafn, datafn)
            except OSError, inst:
                if inst.errno != errno.ENOENT:
                    raise
                ignoremissing(os.unlink)(datafn)
        else:
            for fn in (tmpindexfn, tmpdatafn):
                ignoremissing(os.unlink)(fn)
    finally:
        lock.release()

    if not opts.get('dry_run'):
        ui.write(
开发者ID:iaddict,项目名称:mercurial.rb,代码行数:31,代码来源:shrink-revlog.py


示例20: shrink

def shrink(ui, repo, **opts):
    """
    Shrink revlog by re-ordering revisions. Will operate on manifest for
    the given repository if no other revlog is specified."""

    # Unbuffer stdout for nice progress output.
    sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

    if not repo.local():
        raise util.Abort('not a local repository: %s' % repo.root)

    fn = opts.get('revlog')
    if not fn:
        indexfn = repo.sjoin('00manifest.i')
    else:
        if not fn.endswith('.i'):
            raise util.Abort('--revlog option must specify the revlog index '
                             'file (*.i), not %s' % opts.get('revlog'))

        indexfn = os.path.realpath(fn)
        store = repo.sjoin('')
        if not indexfn.startswith(store):
            raise util.Abort('--revlog option must specify a revlog in %s, '
                             'not %s' % (store, indexfn))

    datafn = indexfn[:-2] + '.d'
    if not os.path.exists(indexfn):
        raise util.Abort('no such file: %s' % indexfn)
    if '00changelog' in indexfn:
        raise util.Abort('shrinking the changelog will corrupt your repository')
    if not os.path.exists(datafn):
        # This is just a lazy shortcut because I can't be bothered to
        # handle all the special cases that entail from no .d file.
        raise util.Abort('%s does not exist: revlog not big enough '
                         'to be worth shrinking' % datafn)

    oldindexfn = indexfn + '.old'
    olddatafn = datafn + '.old'
    if os.path.exists(oldindexfn) or os.path.exists(olddatafn):
        raise util.Abort('one or both of\n'
                         '  %s\n'
                         '  %s\n'
                         'exists from a previous run; please clean up before '
                         'running again' % (oldindexfn, olddatafn))

    ui.write('shrinking %s\n' % indexfn)
    prefix = os.path.basename(indexfn)[:-1]
    (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn),
                                           prefix=prefix,
                                           suffix='.i')
    tmpdatafn = tmpindexfn[:-2] + '.d'
    os.close(tmpfd)

    r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn)
    r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn)

    # Don't use repo.transaction(), because then things get hairy with
    # paths: some need to be relative to .hg, and some need to be
    # absolute. Doing it this way keeps things simple: everything is an
    # absolute path.
    lock = repo.lock(wait=False)
    tr = transaction.transaction(ui.warn,
                                 open,
                                 repo.sjoin('journal'))

    try:
        try:
            order = toposort(ui, r1)
            writerevs(ui, r1, r2, order, tr)
            report(ui, datafn, tmpdatafn)
            tr.close()
        except:
            # Abort transaction first, so we truncate the files before
            # deleting them.
            tr.abort()
            if os.path.exists(tmpindexfn):
                os.unlink(tmpindexfn)
            if os.path.exists(tmpdatafn):
                os.unlink(tmpdatafn)
            raise
        if not opts.get('dry_run'):
            # Racy since both files cannot be renamed atomically
            util.os_link(indexfn, oldindexfn)
            util.os_link(datafn, olddatafn)
            util.rename(tmpindexfn, indexfn)
            util.rename(tmpdatafn, datafn)
        else:
            os.unlink(tmpindexfn)
            os.unlink(tmpdatafn)
    finally:
        lock.release()

    if not opts.get('dry_run'):
        ui.write('note: old revlog saved in:\n'
                 '  %s\n'
                 '  %s\n'
                 '(You can delete those files when you are satisfied that your\n'
                 'repository is still sane.  '
                 'Running \'hg verify\' is strongly recommended.)\n'
                 % (oldindexfn, olddatafn))
开发者ID:iluxa-c0m,项目名称:mercurial-crew-tonfa,代码行数:100,代码来源:shrink-revlog.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.safehasattr函数代码示例发布时间:2022-05-27
下一篇:
Python util.popen函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap