From 7bca31945156f9d411b3dc8e11b93dfd2a63448d Mon Sep 17 00:00:00 2001 From: Costin Galan Date: Thu, 4 Feb 2016 13:21:56 +0200 Subject: [PATCH] Add Windows as supported operating system This change is necessary in order to use the project's update-requirements.py script when preparing the environment on the Hyper-V compute nodes used in the Hyper-V CI. Using the mentioned script will set the latest requirements in nova, neutron, manila, etc., reducing the CI's amount of failures caused by outdated requirements. Including Microsoft Windows as a supported operating system on this project. Also, we update the edit-constraints.py and project.py files to support os.rename() of Windows. On Windows, os.rename() will create a file with the source name, without deleting the initial file first. Example of a traceback: Traceback (most recent call last): File "C:\Python27\Scripts\edit-constraints-script.py", line 9, in load_entry_point('openstack.requirements==0.0.1.dev2497', 'console_scripts', 'edit-constraints')() File "C:\Python27\lib\site-packages\openstack_requirements\cmds\edit_constraint.py", line 74, in main os.rename(args[0] + '.tmp', args[0]) WindowsError: [Error 183] Cannot create a file when that file already exists This could be easily solved by removing the file before the rename. Proposed fix: Add before "os.rename(args[0] + '.tmp', args[0])" the line "os.remove(args[0])" in edit_constraint.py Add before "os.rename(tmpname, fullname)" the line "os.remove(fullname)" in project.py Add "Operating System :: Microsoft :: Windows" in setup.cfg DocImpact: Added Windows as a supported OS in setup.cfg Change-Id: If123a65fd8d49d5c67a1db16827a9617ce520dba Signed-off-by: Costin Galan --- openstack_requirements/cmds/edit_constraint.py | 2 ++ openstack_requirements/project.py | 6 ++++-- setup.cfg | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) 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