Last active
July 28, 2016 09:22
-
-
Save klanjabrik/97b91d43a5d74aafaf8f52206b48cfbf to your computer and use it in GitHub Desktop.
Get latest version of repo at Github
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 sys | |
import getopt | |
from github import Github | |
from colored import fg, bg, attr | |
LONGSDESC = """ | |
Usage: $python lsqrl.py sample.txt | |
content of file: | |
---------------- | |
square/okhttp;parent-3.4.1 | |
square/retrofit;parent-2.0.0 | |
""" | |
def compare(ifile): | |
gh = Github() # gh = Github(username, password) | |
with open(ifile) as fp: | |
for line in iter(fp): | |
row = line.strip() | |
split_row = row.split(';', 2) | |
repo = split_row[0].split('/', 2) | |
if repo: | |
latest_tag = gh.get_user( | |
repo[0]).get_repo(repo[1]).get_tags()[0] | |
tex = '# {}\nCurrent: {}\nLatest : {}'.format( | |
split_row[0].upper(), | |
split_row[1], | |
latest_tag.name) | |
if (split_row[1] != latest_tag.name): | |
foreground = fg('red') | |
tag_zipball = '==> '+latest_tag.zipball_url | |
else: | |
foreground = fg('green') | |
tag_zipball = '' | |
print ('{}{}{}{}\n{}'.format( | |
foreground, | |
attr('bold'), | |
tex, | |
attr('reset'), | |
tag_zipball)) | |
def usage(): | |
print ('USAGE ==> $python lsqrl.py <input_file>') | |
def main(): | |
ifile = '' | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "hi:v", ["help", "ifile="]) | |
except getopt.GetoptError as err: | |
# print help information and exit: | |
print str(err) # will print something like "option -a not recognized" | |
usage() | |
sys.exit(2) | |
if args and args[0]: | |
ifile = args[0] | |
if ifile: | |
compare(ifile) | |
else: | |
usage() | |
if __name__ == '__main__': | |
main() |
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
square/okhttp;parent-3.4.1 | |
square/retrofit;parent-2.0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment