Blame SOURCES/nodejs-setversion

27913e
#!/usr/bin/python
27913e
27913e
"""Set a package version in a package.json file"""
27913e
27913e
# Copyright 2018 Tom Hughes <tom@compton.nu>
27913e
#
27913e
# Permission is hereby granted, free of charge, to any person obtaining a copy
27913e
# of this software and associated documentation files (the "Software"), to
27913e
# deal in the Software without restriction, including without limitation the
27913e
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
27913e
# sell copies of the Software, and to permit persons to whom the Software is
27913e
# furnished to do so, subject to the following conditions:
27913e
#
27913e
# The above copyright notice and this permission notice shall be included in
27913e
# all copies or substantial portions of the Software.
27913e
#
27913e
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27913e
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27913e
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27913e
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27913e
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27913e
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27913e
# IN THE SOFTWARE.
27913e
27913e
import json
27913e
import os
27913e
import shutil
27913e
import sys
27913e
27913e
if not os.path.exists('package.json~'):
27913e
    shutil.copy2('package.json', 'package.json~')
27913e
27913e
md = json.load(open('package.json'))
27913e
27913e
if 'version' in md and sys.argv[1] != md['version']:
27913e
    raise RuntimeError('Version is already set to {0}'.format(md['version']))
27913e
else:
27913e
    md['version'] = sys.argv[1]
27913e
27913e
fh = open('package.json', 'w')
27913e
data = json.JSONEncoder(indent=4).encode(md)
27913e
fh.write(data)
27913e
fh.close()