Created
July 19, 2018 12:57
-
-
Save kinkerl/9f083a002b5a578b2cbb84b9524862fa to your computer and use it in GitHub Desktop.
getversion_from_github.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import click | |
#get version from github | |
def get_version_from_string(line): | |
return line.split("::")[-1].strip() | |
def get_version_info(githubproject): | |
r = requests.get('https://raw.githubusercontent.com/{}/master/setup.py'.format(githubproject), stream=True) | |
info_python_version=[] | |
info_django_version=[] | |
info_djangocms_version = "" | |
if r.status_code == 200: | |
for line in r.iter_lines(): | |
line = line.strip('"\' ,') | |
if "Programming Language :: Python ::" in line: | |
# get python version | |
info_python_version.append(get_version_from_string(line)) | |
if "Framework :: Django ::" in line: | |
# get python version | |
info_django_version.append(get_version_from_string(line)) | |
if "django-cms" in line: | |
info_djangocms_version = line[len("django-cms"):] | |
return info_python_version, info_django_version, info_djangocms_version | |
@click.command() | |
@click.option('--githubproject', help='e.g. "divio/djangocms-text-ckeditor"') | |
def hello(githubproject): | |
info_python_version, info_django_version, info_djangocms_version = get_version_info(githubproject) | |
click.echo('Python Version :{}'.format(info_python_version)) | |
click.echo('Django Version :{}'.format(info_django_version)) | |
click.echo('DjangoCMS Version :{}'.format(info_djangocms_version)) | |
if __name__ == '__main__': | |
hello() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment