本文整理汇总了Python中mercurial.util.copyfile函数的典型用法代码示例。如果您正苦于以下问题:Python copyfile函数的具体用法?Python copyfile怎么用?Python copyfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copyfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
def write(repo):
'''Write bookmarks
Write the given bookmark => hash dictionary to the .hg/bookmarks file
in a format equal to those of localtags.
We also store a backup of the previous state in undo.bookmarks that
can be copied back on rollback.
'''
refs = repo._bookmarks
if os.path.exists(repo.join('bookmarks')):
util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
if repo._bookmarkcurrent not in refs:
setcurrent(repo, None)
wlock = repo.wlock()
try:
file = repo.opener('bookmarks', 'w', atomictemp=True)
for refspec, node in refs.iteritems():
file.write("%s %s\n" % (hex(node), refspec))
file.rename()
# touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
try:
os.utime(repo.sjoin('00changelog.i'), None)
except OSError:
pass
finally:
wlock.release()
示例2: orderFiles
def orderFiles(sourcePath, file):
srcPath = sourcePath + "/" + file
d = get_date(srcPath)
destPath = dest + d[0] + "/" + d[1] + "_" + d[0] + "/" + file
make_sure_path_exists(dest + d[0] + "/" + d[1] + "_" + d[0])
if not (os.path.exists(destPath)):
copyfile(srcPath, destPath)
示例3: _updatebigrepo
def _updatebigrepo(ui, repo, files, brepo, bigfiles, ds):
for file in files:
f = repo.wjoin(file)
hash = accelerated_hash(repo, file, os.lstat(f), ds)
bigfiles[file] = hash
rf = "%s/%s.%s" % (brepo, file, hash)
util.makedirs(os.path.dirname(rf))
try:
ext = f.split('.')[-1]
dont_pack=['gz', 'zip', 'tgz', '7z', 'jpg', 'jpeg', 'gif',
'mpg', 'mpeg', 'avi', 'rar', 'cab']
if ext in dont_pack:
util.copyfile(f, rf)
else:
fo = open(f, 'rb')
rfo_fileobj = open(rf+'.gz', 'wb')
rfo = gzip.GzipFile(file+'.'+hash, 'wb', 9, rfo_fileobj)
def read10Mb():
return fo.read(1024*1024*10)
for chunk in iter(read10Mb, ''):
rfo.write(chunk)
fo.close()
rfo.close()
rfo_fileobj.close()
except:
ui.write(_('failed to store %s\n') % f)
示例4: remember_path
def remember_path(ui, repo, path, value):
'''appends the path to the working copy's hgrc and backs up the original'''
paths = dict(ui.configitems('paths'))
# This should never happen.
if path in paths:
return
# ConfigParser only cares about these three characters.
if re.search(r'[:=\s]', path):
return
try:
audit_path = scmutil.pathauditor(repo.root)
except ImportError:
audit_path = getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))
audit_path('hgrc')
audit_path('hgrc.backup')
base = repo.opener.base
hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
if os.path.exists(hgrc):
util.copyfile(hgrc, backup)
ui.setconfig('paths', path, value)
try:
fp = repo.opener('hgrc', 'a', text=True)
# Mercurial assumes Unix newlines by default and so do we.
fp.write('\n[paths]\n%s = %s\n' % (path, value))
fp.close()
except IOError:
return
示例5: storeuntracked
def storeuntracked(repo, untracked):
if not untracked:
return
os.mkdir(repo.join('tasks/untrackedbackup'))
for f in untracked:
shaname = util.sha1(f).hexdigest()
util.copyfile(util.pathto(repo.root, None, f),
repo.join('tasks/untrackedbackup/%s' % shaname))
util.unlink(util.pathto(repo.root, None, f))
示例6: unshelve
def unshelve(ui, repo, **opts):
'''restore shelved changes'''
# Shelf name and path
shelfname = opts.get('name')
shelfpath = getshelfpath(repo, shelfname)
# List all the active shelves by name and return '
if opts['list']:
listshelves(ui,repo)
return
try:
patch_diff = repo.opener(shelfpath).read()
fp = cStringIO.StringIO(patch_diff)
if opts['inspect']:
ui.status(fp.getvalue())
else:
files = []
ac = parsepatch(fp)
for chunk in ac:
if isinstance(chunk, header):
files += chunk.files()
backupdir = repo.join('shelve-backups')
backups = makebackup(ui, repo, backupdir, set(files))
ui.debug('applying shelved patch\n')
patchdone = 0
try:
try:
fp.seek(0)
internalpatch(fp, ui, 1, repo.root)
patchdone = 1
except:
if opts['force']:
patchdone = 1
else:
ui.status('restoring backup files\n')
for realname, tmpname in backups.iteritems():
ui.debug('restoring %r to %r\n' %
(tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
finally:
try:
ui.debug('removing backup files\n')
shutil.rmtree(backupdir, True)
except OSError:
pass
if patchdone:
ui.debug("removing shelved patches\n")
os.unlink(repo.join(shelfpath))
ui.status("unshelve completed\n")
except IOError:
ui.warn('nothing to unshelve\n')
示例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')
示例8: unremember_path
def unremember_path(ui, repo):
'''restores the working copy's hgrc'''
audit_path = getattr(repo.opener, 'audit_path',
util.path_auditor(repo.root))
audit_path('hgrc')
audit_path('hgrc.backup')
base = repo.opener.base
if os.path.exists(os.path.join(base, 'hgrc')):
util.copyfile(os.path.join(base, 'hgrc.backup'),
os.path.join(base, 'hgrc'))
示例9: copyfile
def copyfile(abssrc, relsrc, otarget, exact):
abstarget = scmutil.canonpath(repo.root, cwd, otarget)
reltarget = repo.pathto(abstarget, cwd)
target = repo.wjoin(abstarget)
src = repo.wjoin(abssrc)
state = repo.dirstate[abstarget]
scmutil.checkportable(ui, abstarget)
# check for collisions
prevsrc = targets.get(abstarget)
if prevsrc is not None:
ui.warn(_('%s: not overwriting - %s collides with %s\n') %
(reltarget, repo.pathto(abssrc, cwd),
repo.pathto(prevsrc, cwd)))
return
# check for overwrites
exists = os.path.lexists(target)
if not after and exists or after and state in 'mn':
if not opts['force']:
ui.warn(_('%s: not overwriting - file exists\n') %
reltarget)
return
if after:
if not exists:
if rename:
ui.warn(_('%s: not recording move - %s does not exist\n') %
(relsrc, reltarget))
else:
ui.warn(_('%s: not recording copy - %s does not exist\n') %
(relsrc, reltarget))
return
elif not dryrun:
try:
if exists:
os.unlink(target)
targetdir = os.path.dirname(target) or '.'
if not os.path.isdir(targetdir):
os.makedirs(targetdir)
util.copyfile(src, target)
srcexists = True
except IOError, inst:
if inst.errno == errno.ENOENT:
ui.warn(_('%s: deleted in working copy\n') % relsrc)
srcexists = False
else:
ui.warn(_('%s: cannot copy - %s\n') %
(relsrc, inst.strerror))
return True # report a failure
示例10: unremember_path
def unremember_path(ui, repo):
'''restores the working copy's hgrc'''
try:
audit_path = scmutil.pathauditor(repo.root)
except ImportError:
audit_path = getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))
audit_path('hgrc')
audit_path('hgrc.backup')
base = repo.opener.base
hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
if os.path.exists(backup):
util.copyfile(backup, hgrc)
else:
os.remove(hgrc)
示例11: unshelve
def unshelve(ui, repo, *pats, **opts):
'''restore shelved changes'''
try:
fp = cStringIO.StringIO()
fp.write(repo.opener('shelve').read())
if opts['inspect']:
ui.status(fp.getvalue())
else:
files = []
for chunk in parsepatch(fp):
if isinstance(chunk, header):
files += chunk.files()
backupdir = repo.join('shelve-backups')
backups = makebackup(ui, repo, backupdir, set(files))
ui.debug('applying shelved patch\n')
patchdone = 0
try:
try:
fp.seek(0)
internalpatch(fp, ui, 1, repo.root)
patchdone = 1
except:
if opts['force']:
patchdone = 1
else:
ui.status('restoring backup files\n')
for realname, tmpname in backups.iteritems():
ui.debug('restoring %r to %r\n' %
(tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
finally:
try:
ui.debug('removing backup files\n')
shutil.rmtree(backupdir, True)
except OSError:
pass
if patchdone:
ui.debug("removing shelved patches\n")
os.unlink(repo.join('shelve'))
ui.status("unshelve completed\n")
except IOError:
ui.warn('nothing to unshelve\n')
示例12: write
def write(ui, repo, tasks):
'''Write tasks
Write the given task dictionary to the .hg/tasks/tasks file.
We also store a backup of the previous state in .hg/tasks/undo.tasks that
can be copied back on rollback.
'''
if os.path.exists(repo.join('tasks/tasks')):
util.copyfile(repo.join('tasks/tasks'), repo.join('tasks/undo.tasks'))
# is this needed here?
if current(repo) not in tasks:
setcurrent(ui, repo, None)
if not os.path.isdir(repo.join('tasks')):
try:
os.mkdir(repo.join('tasks'))
except OSError, inst:
if inst.errno != errno.EEXIST:
raise
示例13: write
def write(repo, refs):
"""Write bookmarks
Write the given bookmark => hash dictionary to the .hg/bookmarks file
in a format equal to those of localtags.
We also store a backup of the previous state in undo.bookmarks that
can be copied back on rollback.
"""
if os.path.exists(repo.join("bookmarks")):
util.copyfile(repo.join("bookmarks"), repo.join("undo.bookmarks"))
if current(repo) not in refs:
setcurrent(repo, None)
wlock = repo.wlock()
try:
file = repo.opener("bookmarks", "w", atomictemp=True)
for refspec, node in refs.iteritems():
file.write("%s %s\n" % (hex(node), refspec))
file.rename()
finally:
wlock.release()
示例14: bigupdate
def bigupdate(ui, repo, *pats, **opts):
'''fetch files from versions directory as recorded in '.bigfiles'.
Also complain about necessary files missing in the version directory'''
ds = read_bigfiledirstate(ui, repo)
bigfiles = parse_bigfiles(repo)
tracked_gotbig, added_big, modified, removed, gotsmall, \
missinginrepo = _bigstatus(ui, repo, pats, opts, ds, bigfiles)
brepo = bigfiles_repo(ui)
tocopy = removed
if opts['clean']:
tocopy = tocopy+modified
for file in tocopy:
f = repo.wjoin(file)
hash= bigfiles[file]
rf = "%s/%s.%s" % (brepo, file, hash)
ui.write(_("fetching %s\n") % rf)
if not opts['dry_run']:
util.makedirs(os.path.dirname(f))
if os.path.exists(f):
util.unlink(f)
if os.path.exists(rf):
util.copyfile(rf, f)
else:
fo = open(f, 'wb')
rfo = gzip.open(rf + '.gz', 'rb')
def read10Mb():
return rfo.read(1024*1024*10)
for chunk in iter(read10Mb, ''):
fo.write(chunk)
fo.close()
rfo.close()
if missinginrepo:
ui.write(_("\nNeeded files missing in bigrepo %s:\n") % brepo)
for file in missinginrepo:
hash = bigfiles[file]
ui.write("%s.%s\n" % (file, hash))
write_bigfiledirstate(ui, repo, ds)
示例15: dodiff
#.........这里部分代码省略.........
if revs and change:
msg = _('cannot specify --rev and --change at the same time')
raise util.Abort(msg)
elif change:
node2 = repo.lookup(change)
node1a, node1b = repo.changelog.parents(node2)
else:
node1a, node2 = cmdutil.revpair(repo, revs)
if not revs:
node1b = repo.dirstate.parents()[1]
else:
node1b = nullid
# Disable 3-way merge if there is only one parent
if do3way:
if node1b == nullid:
do3way = False
matcher = cmdutil.match(repo, pats, opts)
mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher)[:3])
if do3way:
mod_b, add_b, rem_b = map(set, repo.status(node1b, node2, matcher)[:3])
else:
mod_b, add_b, rem_b = set(), set(), set()
modadd = mod_a | add_a | mod_b | add_b
common = modadd | rem_a | rem_b
if not common:
return 0
tmproot = tempfile.mkdtemp(prefix='extdiff.')
try:
# Always make a copy of node1a (and node1b, if applicable)
dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a)
dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot)[0]
if do3way:
dir1b_files = mod_b | rem_b | ((mod_a | add_a) - add_b)
dir1b = snapshot(ui, repo, dir1b_files, node1b, tmproot)[0]
else:
dir1b = None
fns_and_mtime = []
# If node2 in not the wc or there is >1 change, copy it
dir2root = ''
if node2:
dir2 = snapshot(ui, repo, modadd, node2, tmproot)[0]
elif len(common) > 1:
#we only actually need to get the files to copy back to
#the working dir in this case (because the other cases
#are: diffing 2 revisions or single file -- in which case
#the file is already directly passed to the diff tool).
dir2, fns_and_mtime = snapshot(ui, repo, modadd, None, tmproot)
else:
# This lets the diff tool open the changed file directly
dir2 = ''
dir2root = repo.root
# If only one change, diff the files instead of the directories
# Handle bogus modifies correctly by checking if the files exist
if len(common) == 1:
common_file = util.localpath(common.pop())
dir1a = os.path.join(dir1a, common_file)
if not os.path.isfile(os.path.join(tmproot, dir1a)):
dir1a = os.devnull
if do3way:
dir1b = os.path.join(dir1b, common_file)
if not os.path.isfile(os.path.join(tmproot, dir1b)):
dir1b = os.devnull
dir2 = os.path.join(dir2root, dir2, common_file)
# Function to quote file/dir names in the argument string.
# When not operating in 3-way mode, an empty string is
# returned for parent2
replace = dict(parent=dir1a, parent1=dir1a, parent2=dir1b, child=dir2)
def quote(match):
key = match.group()[1:]
if not do3way and key == 'parent2':
return ''
return util.shellquote(replace[key])
# Match parent2 first, so 'parent1?' will match both parent1 and parent
regex = '\$(parent2|parent1?|child)'
if not do3way and not re.search(regex, args):
args += ' $parent1 $child'
args = re.sub(regex, quote, args)
cmdline = util.shellquote(diffcmd) + ' ' + args
ui.debug('running %r in %s\n' % (cmdline, tmproot))
util.system(cmdline, cwd=tmproot)
for copy_fn, working_fn, mtime in fns_and_mtime:
if os.path.getmtime(copy_fn) != mtime:
ui.debug('file changed while diffing. '
'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn))
util.copyfile(copy_fn, working_fn)
return 1
finally:
ui.note(_('cleaning up temp directory\n'))
shutil.rmtree(tmproot)