2015-06-25 21:50:40 +12:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
# implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import optparse
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
|
|
|
|
from openstack_requirements import requirement
|
|
|
|
|
|
|
|
|
|
|
|
def edit(reqs, name, replacement):
|
2015-09-16 14:49:07 -04:00
|
|
|
key = requirement.canonical_name(name)
|
2015-06-25 21:50:40 +12:00
|
|
|
if not replacement:
|
2015-09-16 14:49:07 -04:00
|
|
|
reqs.pop(key, None)
|
2015-06-25 21:50:40 +12:00
|
|
|
else:
|
2015-09-16 14:49:07 -04:00
|
|
|
reqs[key] = [
|
2015-07-03 12:20:23 +12:00
|
|
|
(requirement.Requirement('', '', '', '', replacement), '')]
|
2015-06-25 21:50:40 +12:00
|
|
|
result = []
|
|
|
|
for entries in reqs.values():
|
|
|
|
for entry, _ in entries:
|
|
|
|
result.append(entry)
|
|
|
|
return requirement.Requirements(sorted(result))
|
|
|
|
|
|
|
|
|
|
|
|
# -- untested UI glue from here down.
|
|
|
|
|
|
|
|
|
|
|
|
def _validate_options(options, args):
|
|
|
|
"""Check that options and arguments are valid.
|
|
|
|
|
|
|
|
:param options: The optparse options for this program.
|
|
|
|
:param args: The args for this program.
|
|
|
|
"""
|
|
|
|
if len(args) < 2:
|
|
|
|
raise Exception("No enough arguments given")
|
|
|
|
if not os.path.exists(args[0]):
|
|
|
|
raise Exception(
|
|
|
|
"Constraints file %(con)s not found."
|
|
|
|
% dict(con=args[0]))
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv=None, stdout=None):
|
|
|
|
parser = optparse.OptionParser(
|
|
|
|
usage="%prog [options] constraintpath name replacement",
|
|
|
|
epilog=textwrap.dedent("""\
|
|
|
|
Replaces any entries of "name" in the constraints file with
|
|
|
|
"replacement". If "name" is not present, it is added to the end of
|
|
|
|
the file. If "replacement" is missing or empty, remove "name" from
|
|
|
|
the file.
|
|
|
|
"""))
|
|
|
|
options, args = parser.parse_args(argv)
|
|
|
|
if stdout is None:
|
|
|
|
stdout = sys.stdout
|
|
|
|
_validate_options(options, args)
|
|
|
|
args = args + [""]
|
|
|
|
content = open(args[0], 'rt').read()
|
2015-07-03 13:23:26 +12:00
|
|
|
reqs = requirement.parse(content, permit_urls=True)
|
2015-06-25 21:50:40 +12:00
|
|
|
out_reqs = edit(reqs, args[1], args[2])
|
|
|
|
out = requirement.to_content(out_reqs, prefix=False)
|
|
|
|
with open(args[0] + '.tmp', 'wt') as f:
|
|
|
|
f.write(out)
|
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
<module>
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 <cgalan@cloudbasesolutions.com>
2016-02-04 13:21:56 +02:00
|
|
|
if os.path.exists(args[0]):
|
|
|
|
os.remove(args[0])
|
2015-06-25 21:50:40 +12:00
|
|
|
os.rename(args[0] + '.tmp', args[0])
|
|
|
|
return 0
|