X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=d8f216e838b2f82a96f24326f535832f9d87b9f8;hb=74d5761f260b5d887733e826b4ce6aed11f11487;hp=74705aad1774b6d16e7080348a2447f2cb213d7d;hpb=61c1ca0346aea5ed95330e4d4b2dedfb2ee5213a;p=nodemanager.git diff --git a/tools.py b/tools.py index 74705aa..d8f216e 100644 --- a/tools.py +++ b/tools.py @@ -168,7 +168,8 @@ def write_temp_file(do_write, mode=None, uidgid=None): return temporary_filename -def replace_file_with_string(target, new_contents, chmod=None, remove_if_empty=False): +def replace_file_with_string(target, new_contents, + chmod=None, remove_if_empty=False): """ Replace a target file with a new contents checks for changes: does not do anything if previous state was already right @@ -179,8 +180,8 @@ writes in a tmp file, which is then renamed (from sliverauth originally) returns True if a change occurred, or the file is deleted """ try: - with open(target) as f: - current = f.read() + with open(target) as feed: + current = feed.read() except: current = "" if current == new_contents: @@ -197,7 +198,7 @@ returns True if a change occurred, or the file is deleted # overwrite target file: create a temp in the same directory path = os.path.dirname(target) or '.' fd, name = tempfile.mkstemp('', 'repl', path) - os.write(fd, new_contents) + os.write(fd, new_contents.encode()) os.close(fd) if os.path.exists(target): os.unlink(target) @@ -461,7 +462,7 @@ def get_node_virt(): virt = 'vs' if subprocess.call(['vserver', '--help']) == 0 else 'lxc' except: virt = 'lxc' - with file(virt_stamp, "w") as f: + with open(virt_stamp, "w") as f: f.write(virt) return virt