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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
from urllib import urlopen
import json
from optparse import OptionParser
# from pprint import pprint
import codecs
codecs.register(
lambda name: codecs.lookup("utf-8") if name == "cp65001" else None
)
"""was using this to see what I had currently, could be useful later"""
parser = OptionParser()
parser.add_option(
"-l",
"--list",
dest="list",
action="store_true",
default=False,
help="list available releases",
)
parser.add_option(
"--linux",
dest="linux",
action="store_true",
default=False,
help="find the linux release data",
)
parser.add_option(
"--osx",
dest="osx",
action="store_true",
default=False,
help="find the osx release data",
)
parser.add_option(
"--windows",
dest="windows",
action="store_true",
default=False,
help="find the windows release data",
)
parser.add_option(
"--src",
dest="src",
action="store_true",
default=False,
help="find the src release data",
)
parser.add_option(
"-a",
"--all",
dest="all",
action="store_true",
default=True,
help="find all release data (default)",
)
parser.add_option(
"--pdb2pqr-2.0.0",
dest="pdb2pqr-2.0.0",
action="store_true",
default=False,
help="find the pdb2pqr 2.0.0 release data",
)
parser.add_option(
"--pdb2pqr-1.9.0",
dest="pdb2pqr-1.9.0",
action="store_true",
default=False,
help="find the pdb2pqr 1.9.0 release data",
)
(options, args) = parser.parse_args()
os_version = ["linux", "osx", "src", "windows"]
version_num = ["pdb2pqr-2.0.0", "pdb2pqr-1.9.0"]
data = urlopen(
"https://api.github.com/repos/Electrostatics/apbs-pdb2pqr/releases"
)
html = data.read()
listofreleases = json.loads(html)
# determines if options other than all are selected
counter = 0
for thing in os_version:
if getattr(options, thing) is True or options.list is True:
counter += 1
if counter > 0:
options.all = False
os = []
release_number = []
for version in version_num:
if getattr(options, version):
a = version.split("-")
os.append(a[0])
release_number.append(a[1])
b = set(os)
c = set(release_number)
bool2 = False
if len(b) == 0:
if len(c) == 0:
for version in version_num:
a = version.split("-")
os.append(a[0])
release_number.append(a[1])
b = set(os)
c = set(release_number)
bool2 = True
elif len(c) != 0:
bool2 = False
bool1 = True
# main code body, iterates over the command line inputs
for thing in os_version:
# print getattr(options, thing) == True
if getattr(options, thing) is True:
print("\n \n" + thing.upper() + " RELEASES")
for number in listofreleases:
releasename = number.get("name")
listofassets = number.get("assets")
print("\n" + releasename)
print(number.get("created_at") + "\n")
for info in listofassets:
for d in b:
for e in c:
if d and e in info.get("name"):
if thing in info.get("name"):
print(info.get("name"))
count = info.get("download_count")
print(f"Download Count = {count}")
continue
else:
if bool2 is True:
continue
else:
print("No releases here")
bool1 = False
break
break
if bool1 is False:
bool1 = True
break
# the else case, prints all releases
if options.all is True:
print("\n \n" + "ALL RELEASES")
for number in listofreleases:
releasename = number.get("name")
print("\n" + releasename)
listofassets = number.get("assets")
print(number.get("created_at") + "\n")
for info in listofassets:
print(info.get("name"))
count = info.get("download_count")
print("Download Count = " + str(count))
# lists releases available
if options.list is True:
print("\n" + "RELEASES LIST")
for number in listofreleases:
releasename = number.get("name")
print("\n" + releasename)
|