Commit b2532357 authored by onny's avatar onny
Browse files

code cleanup

parent d1a4a3b9
......@@ -76,7 +76,7 @@ class Database:
content = str(descfile.read())
pkgversion = re.search(r'%VERSION%\\n(?:\d+\:)?(.*?)-',content).group(1)
pkgname = re.search(r'%NAME%\\n(.*?)\\n',content).group(1)
pkglist.append({ 'name' : pkgname, 'version' : pkgversion, 'repository' : '' })
pkglist.append({ 'name' : pkgname, 'version' : pkgversion, 'repository' : '', 'state' : '' })
descfile.close()
tar.close()
return pkglist
......
......@@ -9,10 +9,8 @@ import os
class Template:
def __init__(self, PATH, packages_notlisted, packages_outdated, packages_uptodate):
self.packages_outdated = packages_outdated
self.packages_uptodate = packages_uptodate
self.packages_notlisted = packages_notlisted
def __init__(self, PATH, packages):
self.packages = packages
self.datenow = datetime.datetime.now().strftime("%y/%m/%d %H:%M")
self.PATH = PATH
self.template_environement = Environment(
......@@ -24,9 +22,7 @@ class Template:
widgets[0] = 'Writing template : '
bar = ProgressBar(widgets=widgets, max_value=2)
bar.update(0)
context = { 'packages_outdated' : self.packages_outdated,
'packages_uptodate' : self.packages_uptodate,
'packages_notlisted' : self.packages_notlisted,
context = { 'packages' : self.packages,
'date' : self.datenow}
html = self.template_environement.get_template('upstream.html').render(context)
os.chdir(self.PATH)
......
......@@ -13,9 +13,6 @@ class Versioncheck:
def __init__(self, packages, sqlite_conn):
self.packages = packages
self.packages_outdated = []
self.packages_uptodate = []
self.packages_notlisted = []
self.sqlite_conn = sqlite_conn
def check_repository_status(self, packagename):
......@@ -34,18 +31,18 @@ class Versioncheck:
except:
return "Unknown"
def get_repository_status(self, packages_outdated):
if len(packages_outdated) != 0:
def get_repository_status(self, packages):
if len(packages) != 0:
widgets[0] = 'Checking repository status : '
bar = ProgressBar(widgets=widgets, max_value=len(packages_outdated))
for idx, package in enumerate(packages_outdated):
bar = ProgressBar(widgets=widgets, max_value=len(packages))
for idx, package in enumerate(packages):
bar.update(idx)
if "AUR" not in package['repository']:
if "AUR" not in package['repository'] and package['state'] == "Outdated":
status = self.check_repository_status(package['name'])
packages_outdated[idx]['status'] = status
packages[idx]['status'] = status
bar.update(idx+1)
print("")
return packages_outdated
return packages
def get_upstream_version(self, package_name):
......@@ -77,15 +74,15 @@ class Versioncheck:
upstreamversion = self.get_upstream_version(package['name'])
self.packages[idx]['upstreamversion'] = upstreamversion
if upstreamversion == 'None':
self.packages_notlisted.append(self.packages[idx])
self.packages[idx]['state'] = 'Not listed'
else:
if parse_version(upstreamversion) > parse_version(package['version']):
self.packages_outdated.append(self.packages[idx])
self.packages[idx]['state'] = 'Outdated'
else:
self.packages_uptodate.append(self.packages[idx])
self.packages[idx]['state'] = 'Up to date'
bar.update(idx+1)
print("")
self.sqlite_conn.close()
return self.packages_notlisted, self.packages_outdated, self.packages_uptodate
return self.packages
......@@ -35,7 +35,8 @@ if __name__ == '__main__':
packages = sorted(packages, key=lambda k: k['name'])
packages_notlisted, packages_outdated, packages_uptodate = Versioncheck(packages, sqlite_conn).compare_upstream()
packages_outdated = Versioncheck(packages, sqlite_conn).get_repository_status(packages_outdated)
packages = Versioncheck(packages, sqlite_conn).compare_upstream()
Template(PATH, packages_notlisted, packages_outdated, packages_uptodate).write()
packages = Versioncheck(packages, sqlite_conn).get_repository_status(packages)
Template(PATH, packages).write()
......@@ -24,17 +24,6 @@
</div>
</div>
<div class="content">
<!--
<div class="navbar">
<ul>
<li><a href="https://security.archlinux.org/">issues</a></li>
<li><a href="https://security.archlinux.org/advisory">advisories</a></li>
<li><a href="https://security.archlinux.org/todo">todo</a></li>
<li><a href="https://security.archlinux.org/login">login</a></li>
</ul>
</div>
<hr>
-->
<h1>Packages</h1>
<div class="navbar">
<ul>
......@@ -53,23 +42,25 @@
</tr>
</thead>
<tbody>
{% for package in packages_notlisted %}
<tr>
{% if package['repository'] == "AUR" %}
<td><a target=new href=https://aur.archlinux.org/packages/{{ package['name'] }}>{{ package['name'] }}</a></td>
{% else %}
<td><a target=new href=https://www.archlinux.org/packages/?name={{ package['name'] }}>{{ package['name'] }}</a></td>
{% for package in packages %}
{% if package['state'] == "Not listed" %}
<tr>
{% if package['repository'] == "AUR" %}
<td><a target=new href=https://aur.archlinux.org/packages/{{ package['name'] }}>{{ package['name'] }}</a></td>
{% else %}
<td><a target=new href=https://www.archlinux.org/packages/?name={{ package['name'] }}>{{ package['name'] }}</a></td>
{% endif %}
<td>{{ package['version'] }}</td>
<td><a target=new href=https://release-monitoring.org/projects/search/?pattern={{ package['name'] }}>{{ package['upstreamversion'] }}</a></td>
<td>Unknown</td>
</tr>
{% endif %}
<td>{{ package['version'] }}</td>
<td><a target=new href=https://release-monitoring.org/projects/search/?pattern={{ package['name'] }}>{{ package['upstreamversion'] }}</a></td>
<td>Unknown</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<i>{{ packages_notlisted|count }} packages not listed. Page last updated: {{ date }} UTC</i>
<i>{{ packages|count }} packages not listed. Page last updated: {{ date }} UTC</i>
<br><br>
</div>
......
......@@ -24,17 +24,6 @@
</div>
</div>
<div class="content">
<!--
<div class="navbar">
<ul>
<li><a href="https://security.archlinux.org/">issues</a></li>
<li><a href="https://security.archlinux.org/advisory">advisories</a></li>
<li><a href="https://security.archlinux.org/todo">todo</a></li>
<li><a href="https://security.archlinux.org/login">login</a></li>
</ul>
</div>
<hr>
-->
<h1>Packages</h1>
<div class="navbar">
<ul>
......@@ -53,31 +42,33 @@
</tr>
</thead>
<tbody>
{% for package in packages_outdated %}
<tr>
{% if package['repository'] == "AUR" %}
<td><a target=new href=https://aur.archlinux.org/packages/{{ package['name'] }}>{{ package['name'] }}</a></td>
{% else %}
<td><a target=new href=https://www.archlinux.org/packages/?name={{ package['name'] }}>{{ package['name'] }}</a></td>
{% for package in packages %}
{% if package['state'] == "Outdated" %}
<tr>
{% if package['repository'] == "AUR" %}
<td><a target=new href=https://aur.archlinux.org/packages/{{ package['name'] }}>{{ package['name'] }}</a></td>
{% else %}
<td><a target=new href=https://www.archlinux.org/packages/?name={{ package['name'] }}>{{ package['name'] }}</a></td>
{% endif %}
<td>{{ package['version'] }}</td>
<td><a target=new href=https://release-monitoring.org/projects/search/?pattern={{ package['name'] }}>{{ package['upstreamversion'] }}</a></td>
{% if package['status'] == "Unknown" %}
<td><span class="red">{{ package['status'] }}</span></td>
{% endif %}
{% if package['status'] == "Testing" %}
<td><span class="light_orange">{{ package['status'] }}</span></td>
{% endif %}
{% if package['status'] == "Flagged" %}
<td><span class="orange">{{ package['status'] }}</span></td>
{% endif %}
</tr>
{% endif %}
<td>{{ package['version'] }}</td>
<td><a target=new href=https://release-monitoring.org/projects/search/?pattern={{ package['name'] }}>{{ package['upstreamversion'] }}</a></td>
{% if package['status'] == "Unknown" %}
<td><span class="red">{{ package['status'] }}</span></td>
{% endif %}
{% if package['status'] == "Testing" %}
<td><span class="light_orange">{{ package['status'] }}</span></td>
{% endif %}
{% if package['status'] == "Flagged" %}
<td><span class="orange">{{ package['status'] }}</span></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
<i>{{ packages_outdated|count }} packages outdated. Page last updated: {{ date }} UTC</i>
<i>{{ packages|count }} packages outdated. Page last updated: {{ date }} UTC</i>
<br><br>
</div>
......
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