X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=36754fc9fc45547c766555d72fcce55107d1270e;hb=0bba1275cfbe21f44144b82ad644105709671dbf;hp=22895c4da311b7f3b2fb84a9aefd05f6f630a351;hpb=030819db61f9c6316f1d44d7c3e3486348ae49cc;p=nodemanager.git diff --git a/tools.py b/tools.py index 22895c4..36754fc 100644 --- a/tools.py +++ b/tools.py @@ -1,6 +1,3 @@ -# $Id$ -# $URL$ - """A few things that didn't seem to fit anywhere else.""" import os, os.path @@ -10,6 +7,7 @@ import fcntl import errno import threading import subprocess +import shutil import logger @@ -60,7 +58,7 @@ def daemon(): os.setsid() if os.fork() != 0: os._exit(0) os.chdir('/') - os.umask(0) + os.umask(0022) devnull = os.open(os.devnull, os.O_RDWR) os.dup2(devnull, 0) # xxx fixme - this is just to make sure that nothing gets stupidly lost - should use devnull @@ -111,7 +109,7 @@ The return value is the pid of the other running process, or None otherwise.""" def write_file(filename, do_write, **kw_args): """Write file atomically by opening a temporary file, using to write that file, and then renaming the temporary file.""" - os.rename(write_temp_file(do_write, **kw_args), filename) + shutil.move(write_temp_file(do_write, **kw_args), filename) def write_temp_file(do_write, mode=None, uidgid=None): fd, temporary_filename = tempfile.mkstemp() @@ -148,7 +146,7 @@ def replace_file_with_string (target, new_contents, chmod=None, remove_if_empty= os.close(fd) if os.path.exists(target): os.unlink(target) - os.rename(name,target) + shutil.move(name,target) if chmod: os.chmod(target,chmod) return True