diff --git a/openstack_requirements/cmds/edit_constraint.py b/openstack_requirements/cmds/edit_constraint.py index e1bb602449..bf02cc512e 100644 --- a/openstack_requirements/cmds/edit_constraint.py +++ b/openstack_requirements/cmds/edit_constraint.py @@ -71,5 +71,7 @@ def main(argv=None, stdout=None): out = requirement.to_content(out_reqs, prefix=False) with open(args[0] + '.tmp', 'wt') as f: f.write(out) + if os.path.exists(args[0]): + os.remove(args[0]) os.rename(args[0] + '.tmp', args[0]) return 0 diff --git a/openstack_requirements/project.py b/openstack_requirements/project.py index e7e605e7f8..8c9e61d4d7 100644 --- a/openstack_requirements/project.py +++ b/openstack_requirements/project.py @@ -105,7 +105,7 @@ def _safe_read(project, filename, output=None): if output is None: output = project try: - path = project['root'] + '/' + filename + path = os.path.join(project['root'], filename) with io.open(path, 'rt', encoding="utf-8") as f: output[filename] = f.read() except IOError as e: @@ -166,10 +166,12 @@ def write(project, actions, stdout, verbose, noop=False): elif type(action) is File: if noop: continue - fullname = project['root'] + '/' + action.filename + fullname = os.path.join(project['root'], action.filename) tmpname = fullname + '.tmp' with open(tmpname, 'wt') as f: f.write(action.content) + if os.path.exists(fullname): + os.remove(fullname) os.rename(tmpname, fullname) elif type(action) is StdOut: stdout.write(action.message) diff --git a/setup.cfg b/setup.cfg index d24b1e64b3..49f6a121f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,6 +12,7 @@ classifier = Intended Audience :: System Administrators License :: OSI Approved :: Apache Software License Operating System :: POSIX :: Linux + Operating System :: Microsoft :: Windows Programming Language :: Python Programming Language :: Python :: 2 Programming Language :: Python :: 2.7