Commit bbfcc019 authored by onny's avatar onny
Browse files

sort packages by name

parent 7aa2e658
{
"temp_directory": "/tmp/arch-upstream",
"database_sources": [
"http://mirror.23media.de/archlinux/core/os/x86_64/core.db"
"http://mirror.23media.de/archlinux/community/os/x86_64/community.db",
"http://mirror.23media.de/archlinux/core/os/x86_64/core.db",
"http://mirror.23media.de/archlinux/extra/os/x86_64/extra.db"
]
}
......@@ -12,23 +12,24 @@ class Database:
def __init__(self, package_database, config):
self.package_database = package_database
self.temp_directory = config['temp_directory']
self.pkglist = pkglist = []
self.pkglist = []
self.packages = []
def parse_database(self, database):
os.chdir(self.temp_directory)
tar = tarfile.open(database, "r:tar")
tar.extractall()
pkglist = []
for entry in tar.getmembers():
if entry.isfile() and "desc" in entry.name:
descfile = tar.extractfile(entry)
content = str(descfile.read())
pkgversion = re.search(r'%VERSION%\\n(?:\d+\:)?(.*?)-',content).group(1)
pkgname = re.search(r'%NAME%\\n(.*?)\\n',content).group(1)
self.pkglist.append({ 'name' : pkgname, 'version' : pkgversion })
pkglist.append({ 'name' : pkgname, 'version' : pkgversion })
descfile.close()
tar.close()
return self.pkglist
return pkglist
def load_database(self):
widgets[0] = 'Loading local database : '
......@@ -39,6 +40,6 @@ class Database:
bar.update(idx+1)
print("")
print(self.packages)
self.packages = sorted(self.packages, key=lambda k: k['name'])
return self.packages
......@@ -5,6 +5,7 @@ from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, \
ProgressBar, ReverseBar, RotatingMarker, \
SimpleProgress, Timer, AdaptiveETA, AbsoluteETA, AdaptiveTransferSpeed
widgets = ['', Percentage(), ' ', SimpleProgress(format='(%(value)d of %(max_value)d)'), ' ', Bar(), ' ', Timer(), ' ', AdaptiveETA()]
from time import sleep
class Download:
......@@ -22,16 +23,19 @@ class Download:
r = requests.get(link, stream=True)
f = open(local_filename, 'wb')
file_size = int(r.headers['Content-Length'])
chunk = 1
num_bars = file_size / chunk
total_length = int(r.headers['Content-Length'].strip())
widgets[0] = 'Downloading databases (' +str(idx+1)+ '/' + str(len(self.database_sources)) +'): '
bar = ProgressBar(widgets=widgets, maxval=num_bars).start()
i = 0
for chunk in r.iter_content():
f.write(chunk)
bar.update(i)
i+=1
bar = ProgressBar(widgets=widgets, maxval=total_length).start()
fbytes = 0
for buf in r.iter_content(1024):
if buf:
f.write(buf)
fbytes += len(buf)
if fbytes < total_length:
bar.update(fbytes)
else:
bar.update(total_length)
f.close()
print("")
......
......@@ -16,7 +16,7 @@ class Versioncheck:
self.packages_uptodate = []
self.packages_notlisted = []
def check_repository_status(packagename):
def check_repository_status(self, packagename):
response = requests.get('https://www.archlinux.org/packages/search/json/?name='+packagename)
try:
for package in response.json()['results']:
......@@ -39,10 +39,10 @@ class Versioncheck:
for idx, package in enumerate(packages_outdated):
bar.update(idx)
status = self.check_repository_status(package['name'])
self.packages_outdated[idx]['status'] = status
packages_outdated[idx]['status'] = status
bar.update(idx+1)
print("")
return self.packages_outdated
return packages_outdated
def get_upstream_version(self, packagename):
response = requests.get('https://release-monitoring.org/api/projects/?pattern='+packagename)
......
......@@ -23,7 +23,7 @@ if __name__ == '__main__':
package_database = Download(config).get_databases()
packages = Database(package_database, config).load_database()
packages = packages[0:20]
packages = packages[0:50]
packages_notlisted, packages_outdated, packages_uptodate = Versioncheck(packages).compare_upstream()
packages_outdated = Versioncheck(packages).get_repository_status(packages_outdated)
Template(PATH, packages_notlisted, packages_outdated, packages_uptodate).write()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment