2019-09-02 12:03:19 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
import tarfile
|
|
|
|
import json
|
2019-10-11 18:12:07 +00:00
|
|
|
import os.path
|
2019-09-02 12:03:19 +00:00
|
|
|
|
|
|
|
def read_spec_provides(spec_path):
|
|
|
|
with open(spec_path) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('Provides:'):
|
|
|
|
yield line.strip()
|
|
|
|
|
|
|
|
def read_node_deps(source_archive_path):
|
2019-10-11 18:12:07 +00:00
|
|
|
root_dir = os.path.basename(source_archive_path)[:-len('.tar.gz')]
|
2019-09-02 12:03:19 +00:00
|
|
|
with tarfile.open(source_archive_path) as tar:
|
2019-10-11 18:12:07 +00:00
|
|
|
f = tar.extractfile(f'{root_dir}/package.json')
|
2019-09-02 12:03:19 +00:00
|
|
|
package_json = json.load(f)
|
|
|
|
return list(package_json['devDependencies'].keys()) + list(package_json['dependencies'].keys())
|
|
|
|
|
|
|
|
def read_node_deps_versions(dep_bundle_path, dependencies):
|
|
|
|
with tarfile.open(dep_bundle_path) as tar:
|
|
|
|
for dependency in dependencies:
|
2019-10-11 18:12:07 +00:00
|
|
|
f = tar.extractfile(f'node_modules/{dependency}/package.json')
|
2019-09-02 12:03:19 +00:00
|
|
|
package_json = json.load(f)
|
2019-10-11 18:12:07 +00:00
|
|
|
yield f'Provides: bundled(nodejs-{package_json["name"]}) = {package_json["version"]}'
|
2019-09-02 12:03:19 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) != 4:
|
|
|
|
print('usage: {} specfile source-archive dependency-bundle'.format(sys.argv[0]))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
provides = list(read_spec_provides(sys.argv[1]))
|
|
|
|
dependencies = sorted(read_node_deps(sys.argv[2]))
|
|
|
|
actual_provides = list(read_node_deps_versions(sys.argv[3], dependencies))
|
|
|
|
|
|
|
|
if provides == actual_provides:
|
|
|
|
print("Dependencies are up-to-date with the specfile.")
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
print("Dependencies don't match, please update the specfile:")
|
|
|
|
print ('\n'.join(actual_provides))
|
|
|
|
sys.exit(1)
|