forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpackage.py
75 lines (63 loc) · 1.96 KB
/
checkpackage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Requires: python-PyGithub
import sys
from github import Github
import urllib2
import re
import httplib
if len(sys.argv) != 2:
print "Synopsis: %s <repo_url>" % sys.argv[0]
exit(0)
repo_url = sys.argv[1]
RED = '\033[91m'
GREEN = '\033[92m'
BLUE = '\033[94m'
CYAN = '\033[96m'
WHITE = '\033[97m'
YELLOW = '\033[93m'
MAGENTA = '\033[95m'
GREY = '\033[90m'
BLACK = '\033[90m'
DEFAULT = '\033[99m'
ENDC = '\033[0m'
#https://github.com/kr/pretty
def detectRepo(repo_url):
if "github" in repo_url:
repo = repo_url.split("github.com")[1]
repo = repo[1:]
pkg_name = "golang-github-%s" % repo.replace("/","-")
return (repo, pkg_name)
return ("","")
# get upstream latest commit
def getGithubLatestCommit(repo_name):
g = Github()
for branch in g.get_repo(repo_name).get_branches():
if branch.name == "master":
return branch.commit.sha
return ""
# get fedora latest commit
def getFedoraLatestCommit(pkg_name):
# "http://pkgs.fedoraproject.org/cgit/golang-github-kr-pretty.git/plain/golang-github-kr-pretty.spec"
spec = "http://pkgs.fedoraproject.org/cgit/%s.git/plain/%s.spec" % (pkg_name, pkg_name)
try:
for line in urllib2.urlopen(spec):
if "%global commit" in line:
commit = re.sub("[ \t]+", " ", line).split(' ')[2].strip()
return commit
except urllib2.HTTPError, e:
sys.stderr.write('HTTPError = %s\n' % str(e.code))
except urllib2.URLError, e:
sys.stderr.write('URLError = %s\n' % str(e.reason))
except httplib.HTTPException, e:
sys.stderr.write('HTTPException %s\n' % e)
except Exception, e:
sys.stderr.write("%s\n" % e)
return ""
(repo, pkg_name) = detectRepo(repo_url)
upstream_commit = getGithubLatestCommit(repo)
fedora_commit = getFedoraLatestCommit(pkg_name)
status = "%s up2date %s" % (GREEN, ENDC)
if upstream_commit != fedora_commit:
status = "%s outdated %s" % (RED, ENDC)
print "%s %s %s %s" % (upstream_commit, fedora_commit, status, repo_url)
#print "Upstream commit: %s" % upstream_commit
#print "Commit in Fedora: %s" % fedora_commit