本文整理汇总了Python中mercurial.util.atomictempfile函数的典型用法代码示例。如果您正苦于以下问题:Python atomictempfile函数的具体用法?Python atomictempfile怎么用?Python atomictempfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了atomictempfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _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
示例2: update_parent
def update_parent(path, line, parent):
line = line - 1 # The line number we're passed will be 1-based
fp = None
try:
fp = open(path)
data = fp.readlines()
finally:
if fp and not fp.closed:
fp.close()
#
# line will be the last line of any continued block, go back
# to the first removing the continuation as we go.
#
while data[line][0].isspace():
data.pop(line)
line -= 1
assert data[line].startswith('default')
data[line] = "default = %s\n" % parent
if data[-1] != '\n':
data.append('\n')
try:
fp = util.atomictempfile(path, 'w', 0644)
fp.writelines(data)
fp.rename()
finally:
if fp and not fp.closed:
fp.close()
示例3: test3_oops
def test3_oops():
try:
file = atomictempfile()
except TypeError:
print "OK"
else:
print "expected TypeError"
示例4: putlfile
def putlfile(repo, proto, sha):
'''Put a largefile into a repository's local store and into the
user cache.'''
proto.redirect()
path = lfutil.storepath(repo, sha)
util.makedirs(os.path.dirname(path))
tmpfp = util.atomictempfile(path, createmode=repo.store.createmode)
try:
try:
proto.getfile(tmpfp)
tmpfp._fp.seek(0)
if sha != lfutil.hexsha1(tmpfp._fp):
raise IOError(0, _('largefile contents do not match hash'))
tmpfp.close()
lfutil.linktousercache(repo, sha)
except IOError, e:
repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') %
(sha, e.strerror))
return wireproto.pushres(1)
finally:
tmpfp.discard()
return wireproto.pushres(0)
示例5: removeFile
def removeFile(self, wfile):
repo = self.repo
ctx = self.ctx
if isinstance(ctx, patchctx):
repo.thgbackup(ctx._path)
fp = util.atomictempfile(ctx._path, 'wb')
try:
if ctx._ph.comments:
fp.write('\n'.join(ctx._ph.comments))
fp.write('\n\n')
for file in ctx._fileorder:
if file == wfile:
continue
for chunk in ctx._files[file]:
chunk.write(fp)
fp.close()
finally:
del fp
ctx.invalidate()
else:
fullpath = repo.wjoin(wfile)
repo.thgbackup(fullpath)
wasadded = wfile in repo[None].added()
try:
commands.revert(repo.ui, repo, fullpath, rev='.',
no_backup=True)
if wasadded and os.path.exists(fullpath):
os.unlink(fullpath)
except EnvironmentError:
qtlib.InfoMsgBox(_("Unable to remove"),
_("Unable to remove file %s,\n"
"permission denied") %
hglib.tounicode(wfile))
self.fileModified.emit()
示例6: dump
def dump(data, file_path):
"""Serialize some data to a path atomically.
This is present because I kept corrupting my revmap by managing to hit ^C
during the serialization of that file.
"""
f = hgutil.atomictempfile(file_path, 'w+b', 0644)
json.dump(_convert(data, _scrub), f)
f.close()
示例7: link
def link(src, dest):
try:
util.oslink(src, dest)
except OSError:
# if hardlinks fail, fallback on atomic copy
dst = util.atomictempfile(dest)
for chunk in util.filechunkiter(open(src, 'rb')):
dst.write(chunk)
dst.close()
os.chmod(dest, os.stat(src).st_mode)
示例8: test2_discard
def test2_discard(self):
if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
file.write('yo\n')
file.discard()
self.assertFalse(os.path.isfile('foo'))
self.assertTrue(basename not in os.listdir('.'))
示例9: copytostoreabsolute
def copytostoreabsolute(repo, file, hash):
if inusercache(repo.ui, hash):
link(usercachepath(repo.ui, hash), storepath(repo, hash))
else:
util.makedirs(os.path.dirname(storepath(repo, hash)))
with open(file, 'rb') as srcf:
with util.atomictempfile(storepath(repo, hash),
createmode=repo.store.createmode) as dstf:
for chunk in util.filechunkiter(srcf):
dstf.write(chunk)
linktousercache(repo, hash)
示例10: copytostoreabsolute
def copytostoreabsolute(repo, file, hash):
util.makedirs(os.path.dirname(storepath(repo, hash)))
if inusercache(repo.ui, hash):
link(usercachepath(repo.ui, hash), storepath(repo, hash))
else:
dst = util.atomictempfile(storepath(repo, hash))
for chunk in util.filechunkiter(open(file, 'rb')):
dst.write(chunk)
dst.close()
util.copymode(file, storepath(repo, hash))
linktousercache(repo, hash)
示例11: copytostoreabsolute
def copytostoreabsolute(repo, file, hash):
if inusercache(repo.ui, hash):
link(usercachepath(repo.ui, hash), storepath(repo, hash))
elif not getattr(repo, "_isconverting", False):
util.makedirs(os.path.dirname(storepath(repo, hash)))
dst = util.atomictempfile(storepath(repo, hash),
createmode=repo.store.createmode)
for chunk in util.filechunkiter(open(file, 'rb')):
dst.write(chunk)
dst.close()
linktousercache(repo, hash)
示例12: test2_discard
def test2_discard():
if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
file.write('yo\n')
file.discard()
assert not os.path.isfile('foo')
assert basename not in os.listdir('.')
print 'OK'
示例13: link
def link(src, dest):
"""Try to create hardlink - if that fails, efficiently make a copy."""
util.makedirs(os.path.dirname(dest))
try:
util.oslink(src, dest)
except OSError:
# if hardlinks fail, fallback on atomic copy
dst = util.atomictempfile(dest)
for chunk in util.filechunkiter(open(src, 'rb')):
dst.write(chunk)
dst.close()
os.chmod(dest, os.stat(src).st_mode)
示例14: writefile
def writefile(config, path):
"""Write the given config obj to the specified file"""
f = util.atomictempfile(os.path.realpath(path), 'w')
try:
buf = cStringIO.StringIO()
config.write(buf)
# normalize line endings
for line in buf.getvalue().splitlines():
f.write(line + '\n')
f.close()
finally:
del f # unlink temp file
示例15: test1_simple
def test1_simple(self):
if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
self.assertFalse(os.path.isfile('foo'))
self.assertTrue(basename in glob.glob('.foo-*'))
file.write('argh\n')
file.close()
self.assertTrue(os.path.isfile('foo'))
self.assertTrue(basename not in glob.glob('.foo-*'))