Blame SOURCES/nodejs-setversion

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