1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/hacking/update_bundled.py
Matt Clay 0d46805979 Clean up shebangs for various files.
- Remove shebangs from:
  - ini files
  - unit tests
  - module_utils
  - plugins
  - module_docs_fragments
  - non-executable Makefiles
- Change non-modules from '/usr/bin/python' to '/usr/bin/env python'.
- Change '/bin/env' to '/usr/bin/env'.

Also removed main functions from unit tests (since they no longer
have a shebang) and fixed a python 3 compatibility issue with
update_bundled.py so it does not need to specify a python 2 shebang.

A script was added to check for unexpected shebangs in files.
This script is run during CI on Shippable.
2016-11-02 17:00:27 -07:00

34 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python
import glob
import json
import os.path
from distutils.version import LooseVersion
from ansible.module_utils.urls import open_url
basedir = os.path.dirname(__file__)
for filename in glob.glob(os.path.join(basedir, '../lib/ansible/compat/*/__init__.py')):
if 'compat/tests' in filename:
# compat/tests doesn't bundle any code
continue
filename = os.path.normpath(filename)
with open(filename, 'r') as module:
for line in module:
if line.strip().startswith('_BUNDLED_METADATA'):
data = line[line.index('{'):].strip()
break
else:
print('WARNING: {0} contained no metadata. Could not check for updates'.format(filename))
continue
metadata = json.loads(data)
pypi_fh = open_url('https://pypi.python.org/pypi/{0}/json'.format(metadata['pypi_name']))
pypi_data = json.loads(pypi_fh.read().decode('utf-8'))
if LooseVersion(metadata['version']) < LooseVersion(pypi_data['info']['version']):
print('UPDATE: {0} from {1} to {2} {3}'.format(
metadata['pypi_name'],
metadata['version'],
pypi_data['info']['version'],
'https://pypi.python.org/pypi/{0}/'.format(metadata['pypi_name'])))