Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Depends:
python3-pycurl,
python3-setproctitle,
synaptic,
mint-common (>= 2),
mint-mirrors,
mint-upgrade-info,
python3-xapp (>= 1.0.1),
Expand Down
1 change: 1 addition & 0 deletions usr/lib/linuxmint/mintUpdate/Classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get_release_dates():
class Update():

def __init__(self, package=None, input_string=None, source_name=None):
self.changelog = None
self.package_names = []
if package is not None:
self.package_names.append(package.name)
Expand Down
238 changes: 59 additions & 179 deletions usr/lib/linuxmint/mintUpdate/mintUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import threading
import time
import gettext
import io
import json
import tarfile
import urllib.request
import proxygsettings
import subprocess
import pycurl
from datetime import datetime
Expand All @@ -28,6 +24,7 @@
from gi.repository import AppIndicator3 as AppIndicator

from Classes import Update, PRIORITY_UPDATES, get_release_dates
from mintcommon import apt_changelog

# import AUTOMATIONS dict
with open("/usr/share/linuxmint/mintupdate/automation/index.json") as f:
Expand Down Expand Up @@ -144,185 +141,20 @@ def get_apt_config(config_option):
class ChangelogRetriever(threading.Thread):
def __init__(self, package_update, application):
threading.Thread.__init__(self)
self.source_package = package_update.real_source_name
self.version = package_update.new_version
self.origin = package_update.origin
self.application = application
# get the proxy settings from gsettings
self.ps = proxygsettings.get_proxy_settings()


# Remove the epoch if present in the version
if ":" in self.version:
self.version = self.version.split(":")[-1]

def get_ppa_info(self):
ppa_sources_file = "/etc/apt/sources.list"
ppa_sources_dir = "/etc/apt/sources.list.d/"
ppa_words = self.origin.lstrip("LP-PPA-").split("-")

source = ppa_sources_file
if os.path.exists(ppa_sources_dir):
for filename in os.listdir(ppa_sources_dir):
if filename.startswith(self.origin.lstrip("LP-PPA-")):
source = os.path.join(ppa_sources_dir, filename)
break
if not os.path.exists(source):
return None, None
try:
with open(source) as f:
for line in f:
if (not line.startswith("#") and all(word in line for word in ppa_words)):
ppa_info = line.split("ppa.launchpad.net/")[1]
break
else:
return None, None
except EnvironmentError as e:
print ("Error encountered while trying to get PPA owner and name: %s" % e)
return None, None
ppa_owner, ppa_name, ppa_x = ppa_info.split("/", 2)
return ppa_owner, ppa_name

def get_ppa_changelog(self, ppa_owner, ppa_name):
max_tarball_size = 1000000
print ("\nFetching changelog for PPA package %s/%s/%s ..." % (ppa_owner, ppa_name, self.source_package))
if self.source_package.startswith("lib"):
ppa_abbr = self.source_package[:4]
else:
ppa_abbr = self.source_package[0]
deb_dsc_uri = "http://ppa.launchpad.net/%s/%s/ubuntu/pool/main/%s/%s/%s_%s.dsc" % (ppa_owner, ppa_name, ppa_abbr, self.source_package, self.source_package, self.version)
try:
deb_dsc = urllib.request.urlopen(deb_dsc_uri, None, 10).read().decode("utf-8")
except Exception as e:
print ("Could not open Launchpad URL %s - %s" % (deb_dsc_uri, e))
return
for line in deb_dsc.split("\n"):
if "debian.tar" not in line:
continue
tarball_line = line.strip().split(" ", 2)
if len(tarball_line) == 3:
deb_checksum, deb_size, deb_filename = tarball_line
break
else:
deb_filename = None
if not deb_filename or not deb_size or not deb_size.isdigit():
print ("Unsupported debian .dsc file format. Skipping this package.")
return
if (int(deb_size) > max_tarball_size):
print ("Tarball size %s B exceeds maximum download size %d B. Skipping download." % (deb_size, max_tarball_size))
return
deb_file_uri = "http://ppa.launchpad.net/%s/%s/ubuntu/pool/main/%s/%s/%s" % (ppa_owner, ppa_name, ppa_abbr, self.source_package, deb_filename)
try:
deb_file = urllib.request.urlopen(deb_file_uri, None, 10).read().decode("utf-8")
except Exception as e:
print ("Could not download tarball from %s - %s" % (deb_file_uri, e))
return
if deb_filename.endswith(".xz"):
cmd = ["xz", "--decompress"]
try:
xz = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
xz.stdin.write(deb_file)
xz.stdin.close()
deb_file = xz.stdout.read()
xz.stdout.close()
except EnvironmentError as e:
print ("Error encountered while decompressing xz file: %s" % e)
return
deb_file = io.BytesIO(deb_file)
try:
with tarfile.open(fileobj = deb_file) as f:
deb_changelog = f.extractfile("debian/changelog").read()
except tarfile.TarError as e:
print ("Error encountered while reading tarball: %s" % e)
return

return deb_changelog
self.pkg = package_update

def run(self):
Gdk.threads_enter()
self.application.textview_changes.set_text(_("Downloading changelog..."))
Gdk.threads_leave()

if self.ps == {}:
# use default urllib.request proxy mechanisms (possibly *_proxy environment vars)
proxy = urllib.request.ProxyHandler()
else:
# use proxy settings retrieved from gsettings
proxy = urllib.request.ProxyHandler(self.ps)

opener = urllib.request.build_opener(proxy)
urllib.request.install_opener(opener)

changelog = [_("No changelog available")]

changelog_sources = []
if self.origin == "linuxmint":
changelog_sources.append("http://packages.linuxmint.com/dev/" + self.source_package + "_" + self.version + "_amd64.changes")
changelog_sources.append("http://packages.linuxmint.com/dev/" + self.source_package + "_" + self.version + "_i386.changes")
elif self.origin == "ubuntu":
if (self.source_package.startswith("lib")):
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/main/%s/%s/%s_%s/changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/multiverse/%s/%s/%s_%s/changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/universe/%s/%s/%s_%s/changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/restricted/%s/%s/%s_%s/changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
else:
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/main/%s/%s/%s_%s/changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/multiverse/%s/%s/%s_%s/changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/universe/%s/%s/%s_%s/changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
changelog_sources.append("http://changelogs.ubuntu.com/changelogs/pool/restricted/%s/%s/%s_%s/changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
elif self.origin == "debian":
if (self.source_package.startswith("lib")):
changelog_sources.append("http://metadata.ftp-master.debian.org/changelogs/main/%s/%s/%s_%s_changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
changelog_sources.append("http://metadata.ftp-master.debian.org/changelogs/contrib/%s/%s/%s_%s_changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
changelog_sources.append("http://metadata.ftp-master.debian.org/changelogs/non-free/%s/%s/%s_%s_changelog" % (self.source_package[0:4], self.source_package, self.source_package, self.version))
else:
changelog_sources.append("http://metadata.ftp-master.debian.org/changelogs/main/%s/%s/%s_%s_changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
changelog_sources.append("http://metadata.ftp-master.debian.org/changelogs/contrib/%s/%s/%s_%s_changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
changelog_sources.append("http://metadata.ftp-master.debian.org/changelogs/non-free/%s/%s/%s_%s_changelog" % (self.source_package[0], self.source_package, self.source_package, self.version))
elif self.origin.startswith("LP-PPA"):
ppa_owner, ppa_name = self.get_ppa_info()
if ppa_owner and ppa_name:
deb_changelog = self.get_ppa_changelog(ppa_owner, ppa_name)
if not deb_changelog:
changelog_sources.append("https://launchpad.net/~%s/+archive/ubuntu/%s/+files/%s_%s_source.changes" % (ppa_owner, ppa_name, self.source_package, self.version))
else:
changelog = "%s\n" % deb_changelog
else:
print ("PPA owner or name could not be determined")

for changelog_source in changelog_sources:
try:
print("Trying to fetch the changelog from: %s" % changelog_source)
url = urllib.request.urlopen(changelog_source, None, 10)
source = url.read().decode("utf-8")
url.close()

changelog = ""
if "linuxmint.com" in changelog_source:
changes = source.split("\n")
for change in changes:
stripped_change = change.strip()
if stripped_change == ".":
change = ""
if change == "" or stripped_change.startswith("*") or stripped_change.startswith("["):
changelog = changelog + change + "\n"
elif "launchpad.net" in changelog_source:
changes = source.split("Changes:")[1].split("Checksums")[0].split("\n")
for change in changes:
stripped_change = change.strip()
if stripped_change != "":
if stripped_change == ".":
stripped_change = ""
changelog = changelog + stripped_change + "\n"
else:
changelog = source
changelog = changelog.split("\n")
break
except:
pass
if not self.pkg.changelog and self.pkg.package_names[0]:
Gdk.threads_enter()
self.application.textview_changes.set_text(_("Downloading changelog..."))
Gdk.threads_leave()
self.pkg.changelog = apt_changelog.get_changelog(self.pkg.package_names[0])
if not self.pkg.changelog:
self.pkg.changelog = _("No changelog available")

Gdk.threads_enter()
self.application.textview_changes.set_text("\n".join(changelog))
self.application.textview_changes.set_text(self.pkg.changelog)
Gdk.threads_leave()

class AutomaticRefreshThread(threading.Thread):
Expand Down Expand Up @@ -1674,6 +1506,7 @@ def save_window_size(self):
def hide_main_window(self, widget):
self.window.hide()
self.app_hidden = True
apt_changelog.drop_cache()

def setVisibleColumn(self, checkmenuitem, column, key):
state = checkmenuitem.get_active()
Expand Down Expand Up @@ -1947,9 +1780,11 @@ def open_history(self, widget):
column_old_version = Gtk.TreeViewColumn(_("Old Version"), Gtk.CellRendererText(), text=2)
column_old_version.set_sort_column_id(2)
column_old_version.set_resizable(True)
column_old_version.set_max_width(300)
column_new_version = Gtk.TreeViewColumn(_("New Version"), Gtk.CellRendererText(), text=3)
column_new_version.set_sort_column_id(3)
column_new_version.set_resizable(True)
column_new_version.set_max_width(300)
treeview.append_column(column_date)
treeview.append_column(column_package)
treeview.append_column(column_old_version)
Expand All @@ -1958,7 +1793,6 @@ def open_history(self, widget):
treeview.set_reorderable(False)
treeview.set_search_column(0)
treeview.set_enable_search(True)
treeview.show()

model = Gtk.TreeStore(str, str, str, str) # (packageName, date, oldVersion, newVersion)
if os.path.isfile("/var/log/dpkg.log"):
Expand All @@ -1984,12 +1818,58 @@ def open_history(self, widget):

# model.set_sort_column_id( 1, Gtk.SortType.DESCENDING )
treeview.set_model(model)

def show_changelog(parent, package_name):
def on_key_press_event(widget, event):
if event.keyval == Gdk.KEY_Escape or \
event.keyval == Gdk.KEY_Return or \
event.keyval == Gdk.KEY_KP_Enter:
widget.destroy()

window = Gtk.Window()
window.set_transient_for(parent)
window.set_default_size(500, 500)
window.set_icon_name("mintupdate")
window.set_title(_("Changelog for %s") % package_name)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.set_border_width(12)
box.set_spacing(12)
box.set_hexpand(True)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scrolled_window.set_hexpand(True)
scrolled_window.set_propagate_natural_width(True)
scrolled_window.set_min_content_width(500)
output_box = Gtk.TextView()
output_box.set_editable(False)
output_box.set_right_margin(scrolled_window.get_vscrollbar().get_preferred_width().natural_width)
scrolled_window.add(output_box)
box.pack_start(scrolled_window, True, True, 0)
window.add(box)
window.connect("key-press-event", on_key_press_event)

if package_name:
changelog = apt_changelog.get_changelog(package_name)
if not changelog:
changelog = _("No changelog available")
output_box.get_buffer().set_text(changelog)
window.show_all()

def on_click(widget, event, model, parent):
if event.button == 3: # right click
path, _, _, _ = widget.get_path_at_pos(int(event.x), int(event.y))
package_name = model.get_value(model.get_iter(path), 0)
show_changelog(parent, package_name)

treeview.connect('button-release-event' , on_click, model, window)

del model
def destroy_window(widget):
self.history_window_showing = False
window.destroy()
window.connect("destroy", destroy_window)
builder.get_object("button_close").connect("clicked", destroy_window)
window.show_all()
self.history_window_showing = True

######### HELP/ABOUT/SHORTCUTS/SOURCES SCREEN #########
Expand Down
Loading