本文整理汇总了Python中werkzeug.posixemulation.rename函数的典型用法代码示例。如果您正苦于以下问题:Python rename函数的具体用法?Python rename怎么用?Python rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rename函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
def set(self, key, value, timeout=None, mgmt_element=False):
# Management elements have no timeout
if mgmt_element:
timeout = 0
# Don't prune on management element update, to avoid loop
else:
self._prune()
timeout = self._normalize_timeout(timeout)
filename = self._get_filename(key)
try:
fd, tmp = tempfile.mkstemp(suffix=self._fs_transaction_suffix,
dir=self._path)
with os.fdopen(fd, 'wb') as f:
pickle.dump(timeout, f, 1)
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
rename(tmp, filename)
os.chmod(filename, self._mode)
except (IOError, OSError):
return False
else:
# Management elements should not count towards threshold
if not mgmt_element:
self._update_count(delta=1)
return True
示例2: commit
def commit(self):
"""Commits the artifact changes."""
if self._new_artifact_file is not None:
rename(self._new_artifact_file, self.dst_filename)
self._new_artifact_file = None
if self._update_con is not None:
self._update_con.commit()
self._update_con.close()
self._update_con = None
示例3: save
def save(self, session):
fn = self.get_session_filename(session.sid)
fd, tmp = tempfile.mkstemp(suffix=_fs_transaction_suffix, dir=self.path)
f = os.fdopen(fd, "wb")
try:
dump(dict(session), f, HIGHEST_PROTOCOL)
finally:
f.close()
try:
rename(tmp, fn)
os.chmod(fn, self.mode)
except (IOError, OSError):
pass
示例4: set
def set(self, key, value, timeout=None):
timeout = self._normalize_timeout(timeout)
filename = self._get_filename(key)
self._prune()
try:
fd, tmp = tempfile.mkstemp(suffix=self._fs_transaction_suffix,
dir=self._path)
with os.fdopen(fd, 'wb') as f:
pickle.dump(timeout, f, 1)
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
rename(tmp, filename)
os.chmod(filename, self._mode)
except (IOError, OSError):
return False
else:
return True
示例5: set
def set(self, key, value, timeout=None):
if timeout is None:
timeout = self.default_timeout
filename = self._get_filename(key)
self._prune()
try:
fd, tmp = tempfile.mkstemp(suffix=self._fs_transaction_suffix, dir=self._path)
f = os.fdopen(fd, "wb")
try:
pickle.dump(int(time() + timeout), f, 1)
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
finally:
f.close()
rename(tmp, filename)
os.chmod(filename, self._mode)
except (IOError, OSError):
pass
示例6: commit
def commit(self):
"""Commits the artifact changes."""
con = None
try:
for op in self._pending_update_ops:
if con is None:
con = self.build_state.connect_to_database()
op(con)
if self._new_artifact_file is not None:
rename(self._new_artifact_file, self.dst_filename)
self._new_artifact_file = None
if con is not None:
con.commit()
con.close()
con = None
finally:
if con is not None:
con.rollback()
con.close()
示例7: _commit
def _commit(self):
con = None
try:
for op in self._pending_update_ops:
if con is None:
con = self.build_state.connect_to_database()
op(con)
if self._new_artifact_file is not None:
rename(self._new_artifact_file, self.dst_filename)
self._new_artifact_file = None
if con is not None:
con.commit()
con.close()
con = None
self.build_state.updated_artifacts.append(self)
self.build_state.builder.failure_controller.clear_failure(self.artifact_name)
finally:
if con is not None:
con.rollback()
con.close()
示例8: atomic_open
def atomic_open(filename, mode="r"):
if "r" not in mode:
fd, tmp_filename = tempfile.mkstemp(dir=os.path.dirname(filename), prefix=".__atomic-write")
os.chmod(tmp_filename, 0644)
f = os.fdopen(fd, mode)
else:
f = open(filename, mode)
tmp_filename = None
try:
yield f
except:
f.close()
exc_type, exc_value, tb = sys.exc_info()
if tmp_filename is not None:
try:
os.remove(tmp_filename)
except OSError:
pass
raise exc_type, exc_value, tb
else:
f.close()
if tmp_filename is not None:
rename(tmp_filename, filename)
示例9: atomic_open
def atomic_open(filename, mode='r'):
if 'r' not in mode:
fd, tmp_filename = tempfile.mkstemp(
dir=os.path.dirname(filename), prefix='.__atomic-write')
os.chmod(tmp_filename, 0o644)
f = os.fdopen(fd, mode)
else:
f = open(filename, mode)
tmp_filename = None
try:
yield f
except: # pylint: disable=bare-except
f.close()
exc_type, exc_value, tb = sys.exc_info()
if tmp_filename is not None:
try:
os.remove(tmp_filename)
except OSError:
pass
reraise(exc_type, exc_value, tb)
else:
f.close()
if tmp_filename is not None:
rename(tmp_filename, filename)