Commit 952d6769 authored by David Boddie's avatar David Boddie 💬
Browse files

Show license details, make GUI smoother and tidy up afterwards

parent b8e47763
......@@ -129,9 +129,9 @@ class Application(Gtk.Application):
except StopIteration:
self.progress.set_fraction(1.0)
self.progress.set_fraction(0.0)
self.state = 'listing'
self.lines.append(_('Listing packages'))
self.lines = [_('Listing packages')]
self.lines.append('')
self.update_label()
self.iter = self.worker.list_packages()
......@@ -141,15 +141,17 @@ class Application(Gtk.Application):
def list_package(self):
try:
for i in range(100):
name = self.iter.__next__()
for i in range(10):
name, i, total = self.iter.__next__()
self.lines[-1] = name
self.progress.set_fraction(i/total)
self.update_label()
except StopIteration:
self.lines.pop()
self.lines = []
self.update_label()
self.progress.set_fraction(1.0)
self.button = Gtk.Button(label=_('Open Package List'),
halign=Gtk.Align.CENTER)
......
......@@ -12,7 +12,7 @@ import glob
import os
import subprocess
from debian import deb822
from debian import copyright, deb822
class Worker:
......@@ -25,6 +25,13 @@ class Worker:
def html_escape(self, text):
return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt')
def make_link(self, href, text):
if href:
return '<a href="file://%s">%s</a>' % (href, self.html_escape(text))
else:
return self.html_escape(text)
def read_sources(self):
lists_dir = os.path.join(self.root_dir, 'var', 'lib', 'apt', 'lists')
......@@ -76,15 +83,54 @@ class Worker:
except KeyError:
return None
def get_copyright(self, prefix, name):
def get_copyright(self, name):
path = os.path.join(prefix, 'usr', 'share', 'doc', name, 'copyright')
path = os.path.join(self.root_dir, 'usr', 'share', 'doc', name, 'copyright')
if os.path.exists(path):
return os.path.join('/', 'usr', 'share', 'doc', name, 'copyright')
return None
def get_licenses(self, file_name):
try:
c = copyright.Copyright(open(os.path.join(file_name)))
except copyright.Error:
# Some copyright files aren't machine readable.
return None
# Obtain the main or overall license.
if c.header.license:
main_license = (c.header.license.synopsis,
self.find_license(c.header.license.synopsis))
else:
main_license = None
# Obtain all the mentioned licenses.
licenses = set()
for para in c.all_license_paragraphs():
try:
licenses.add((para.license.synopsis,
self.find_license(para.license.synopsis)))
except copyright.Error:
# Some license paragraphs aren't machine readable.
pass
return main_license, licenses
def find_license(self, name):
name = name.rstrip('+')
path = os.path.join(self.root_dir, 'usr', 'share', 'common-licenses', name)
if os.path.exists(path):
return os.path.join('/', 'usr', 'share', 'common-licenses', name)
else:
return None
def list_packages(self):
index_file = os.path.join(self.output_dir, 'index.html')
......@@ -104,9 +150,11 @@ class Worker:
status_file = os.path.join(self.root_dir, 'var', 'lib', 'dpkg', 'status')
deb_host = 'https://repo.pureos.net/pureos/'
index_text += '<h1>Package Information</h1>\n\n'
total = open(status_file).read().count('\n\n')
index_text += '<h1>Package Information</h1>\n\n'
current = None
i = 0
links_text = '<p class="links">'
index_list_text = '<dl>\n'
......@@ -129,7 +177,8 @@ class Worker:
'<span class="version">%s</span></dd>\n') % (
name, name, version)
yield name
i += 1
yield name, i, total
output_text = ('<html>\n<head>\n<title>%s</title>\n'
'<style type="text/css">\n'
......@@ -166,12 +215,30 @@ class Worker:
homepage, self.html_escape(homepage))
# Use the package name to find the copyright file.
copyright_file = self.get_copyright(self.root_dir, name)
copyright_file = self.get_copyright(name)
if copyright_file:
if copyright_file != None:
output_text += '<tr><th>Copyright</th><td><a href="file://%s">%s</a></td></tr>\n' % (
copyright_file, self.html_escape(copyright_file))
licenses = self.get_licenses(copyright_file)
if licenses:
main_license, licenses = licenses
if main_license:
output_text += '<tr><th>Overall License</th>\n<td>'
license_name, license_file = main_license
output_text += self.make_link(license_file, license_name)
output_text += '</td></tr>\n'
if licenses:
output_text += '<tr><th>Licenses</th>\n<td>'
for license_name, license_file in licenses:
output_text += self.make_link(license_file, license_name) + ' '
output_text += '</td></tr>\n'
output_text += '</table>\n'
# Read source files.
......
Supports Markdown
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