summaryrefslogtreecommitdiff
path: root/UpdateManager
diff options
context:
space:
mode:
authorMichael Vogt <egon@top>2005-11-30 22:35:20 +0100
committerMichael Vogt <egon@top>2005-11-30 22:35:20 +0100
commit1e0aee98a02ef0220038bc2c22080191882a9c3e (patch)
treea33fe6927da5daa763d888bfbe0b1b4d75a65788 /UpdateManager
parent8d81801fa5371feeab82aebfc72a7000ff0f3c78 (diff)
downloadpython-apt-1e0aee98a02ef0220038bc2c22080191882a9c3e.tar.gz
* move the MetaRelease code into it's own class/file
* use a gobject as base for the meta-release and make it emit proper signals
Diffstat (limited to 'UpdateManager')
-rw-r--r--UpdateManager/MetaRelease.py133
-rw-r--r--UpdateManager/UpdateManager.py114
2 files changed, 147 insertions, 100 deletions
diff --git a/UpdateManager/MetaRelease.py b/UpdateManager/MetaRelease.py
new file mode 100644
index 00000000..5127029a
--- /dev/null
+++ b/UpdateManager/MetaRelease.py
@@ -0,0 +1,133 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+import thread
+import urllib2
+import os
+import string
+import apt_pkg
+import time
+import rfc822
+from subprocess import Popen,PIPE
+
+class Dist(object):
+ def __init__(self, name, date, supported):
+ self.name = name
+ self.date = date
+ self.supported = supported
+
+class MetaRelease(gobject.GObject):
+
+ # some constants
+ #METARELEASE_URI = "http://changelogs.ubuntu.com/meta-release"
+ METARELEASE_URI = "http://people.ubuntu.com/~mvo/meta-release-test"
+ METARELEASE_FILE = "/var/lib/update-manager/meta-release"
+
+ __gsignals__ = {
+ 'new_dist_available' : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT,)),
+ 'dist_no_longer_supported' : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ())
+
+ }
+
+ def __init__(self):
+ gobject.GObject.__init__(self)
+ self.metarelease_information = None
+ self.downloading = True
+ t=thread.start_new_thread(self.download, ())
+
+ def get_dist(self):
+ " return the codename of the current runing distro "
+ p = Popen(["/bin/lsb_release","-c","-s"],stdout=PIPE)
+ res = p.wait()
+ if res != 0:
+ sys.stderr.write("lsb_release returned exitcode: %i\n" % res)
+ dist = string.strip(p.stdout.readline())
+ return dist
+
+ def check(self):
+ print "check"
+ # check if we have a metarelease_information file
+ if self.metarelease_information != None:
+ self.parse()
+ # return False makes g_timeout() stop
+ return False
+ # no information yet, keep runing
+ return True
+
+ def parse(self):
+ print "parse"
+ current_dist_name = self.get_dist()
+ current_dist = None
+ dists = []
+
+ # parse the metarelease_information file
+ index_tag = apt_pkg.ParseTagFile(self.metarelease_information)
+ step_result = index_tag.Step()
+ while step_result:
+ if index_tag.Section.has_key("Dist"):
+ name = index_tag.Section["Dist"]
+ rawdate = index_tag.Section["Date"]
+ date = time.mktime(rfc822.parsedate(rawdate))
+ supported = index_tag.Section["Supported"]
+ # add the information to a new date object
+ dist = Dist(name,date,supported)
+ dists.append(dist)
+ if name == current_dist_name:
+ current_dist = dist
+ step_result = index_tag.Step()
+
+ # first check if the current runing distro is in the meta-release
+ # information. if not, we assume that we run on something not
+ # supported and silently return
+ if current_dist == None:
+ print "current dist not found in meta-release file"
+ return False
+
+ # then see what we can upgrade to
+ upgradable_to = ""
+ for dist in dists:
+ if dist.date > current_dist.date:
+ upgradable_to = dist
+ print "new dist: %s" % upgradable_to
+ break
+
+ # only warn if unsupported and a new dist is available (because
+ # the development version is also unsupported)
+ if upgradable_to != "" and not current_dist.supported:
+ #self.current_dist_not_supported(upgradable_to)
+ self.emit("dist_no_longer_supported",upgradable_to)
+ elif upgradable_to != "":
+ #self.new_dist_available(upgradable_to)
+ self.emit("new_dist_available",upgradable_to)
+
+ # parsing done and sucessfully
+ return True
+
+ # the network thread that tries to fetch the meta-index file
+ # can't touch the gui, runs as a thread
+ def download(self):
+ print "download"
+ lastmodified = 0
+ req = urllib2.Request(self.METARELEASE_URI)
+ if os.access(self.METARELEASE_FILE, os.W_OK):
+ lastmodified = os.stat(self.METARELEASE_FILE).st_mtime
+ if lastmodified > 0:
+ req.add_header("If-Modified-Since", lastmodified)
+ try:
+ uri=urllib2.urlopen(req)
+ f=open(self.METARELEASE_FILE,"w+")
+ for line in uri.readlines():
+ f.write(line)
+ f.flush()
+ f.seek(0,0)
+ self.metarelease_information=f
+ uri.close()
+ except urllib2.URLError:
+ if os.path.exits(self.METARELEASE_FILE):
+ f=open(self.METARELEASE_FILE,"r")
+
+
diff --git a/UpdateManager/UpdateManager.py b/UpdateManager/UpdateManager.py
index 0693dfe2..d13d226f 100644
--- a/UpdateManager/UpdateManager.py
+++ b/UpdateManager/UpdateManager.py
@@ -15,10 +15,7 @@ import os
import os.path
import urllib2
import re
-import thread
import tempfile
-import time
-import rfc822
import gconf
import pango
import subprocess
@@ -30,6 +27,8 @@ from Common.utils import *
from Common.SimpleGladeApp import SimpleGladeApp
import GtkProgress
+from MetaRelease import Dist, MetaRelease
+
# FIXME:
# - cary a reference to the update-class around in the ListStore
# - kill "all_changes" and move the changes into the "Update" class
@@ -43,10 +42,6 @@ import GtkProgress
SYNAPTIC_PINFILE = "/var/lib/synaptic/preferences"
-METARELEASE_URI = "http://changelogs.ubuntu.com/meta-release"
-#METARELEASE_URI = "http://people.ubuntu.com/~mvo/meta-release-test"
-METARELEASE_FILE = "/var/lib/update-manager/meta-release"
-
CHANGELOGS_URI="http://changelogs.ubuntu.com/changelogs/pool/%s/%s/%s/%s_%s/changelog"
@@ -61,8 +56,7 @@ class MyCache(apt.Cache):
self.clean()
assert self._depcache.BrokenCount == 0 and self._depcache.DelCount == 0
self._depcache.Upgrade()
-
-
+
class UpdateList:
def __init__(self, parent_window):
@@ -150,7 +144,6 @@ class UpdateManager(SimpleGladeApp):
self.packages = []
self.dl_size = 0
self.all_changes = {}
- self.dist = self.get_dist()
# create text view
changes_buffer = self.textview_changes.get_buffer()
@@ -605,18 +598,7 @@ class UpdateManager(SimpleGladeApp):
self.update_count()
return False
- # FIXME: use lsb-release binary and cache the result
- def get_dist(self):
- f = open("/etc/lsb-release", "r")
- lines = f.readlines()
- for line in lines:
- key, value = line.split("=")
- if (key == "DISTRIB_CODENAME"):
- return value[:-1]
- f.close()
-
- def current_dist_not_supported(self, name):
- #print name
+ def dist_no_longer_supported(self, meta_release):
msg = "<big><b>%s</b></big>\n\n%s" % (_("Your distribution is no longer supported"), _("Please upgrade to a newer version of Ubuntu Linux. The version you are running will no longer get security fixes or other critical updates. Please see http://www.ubuntulinux.org for upgrade information."))
dialog = gtk.MessageDialog(self.window_main, 0, gtk.MESSAGE_WARNING,
gtk.BUTTONS_OK,"")
@@ -628,9 +610,8 @@ class UpdateManager(SimpleGladeApp):
print "on_button_dist_upgrade_clicked"
-
- def new_dist_available(self, name):
- print "new_dist_available: %s" % name
+ def new_dist_available(self, meta_release, upgradable_to):
+ print "new_dist_available: %s" % upgradable_to.name
# check if the user already knowns about this dist
#seen = self.gconfclient.get_string("/apps/update-manager/seen_dist")
#if name == seen:
@@ -648,76 +629,8 @@ class UpdateManager(SimpleGladeApp):
# self.gconfclient.set_string("/apps/update-manager/seen_dist",name)
#dialog.destroy()
self.frame_new_release.show()
- self.label_new_release.set_markup("<b>New distibution release codename '%s' available</b>" % name)
+ self.label_new_release.set_markup("<b>New distibution release codename '%s' available</b>" % upgradable_to.name)
- # code that does the meta release file checking
- def check_meta_release(self):
- #print "check_meta_release"
- current_dist = self.dist
- dists = {}
- if self.metarelease_information != None:
- #print "meta_release found (current_dist: %s)" % (current_dist)
- # we have a meta-release file
- current_dist_date = 0
- current_dist_supported = False
- new_dist_available = False
- # parse it
- index_tag = apt_pkg.ParseTagFile(self.metarelease_information)
- step_result = index_tag.Step()
- while step_result:
- if index_tag.Section.has_key("Dist"):
- dist = index_tag.Section["Dist"]
- date = time.mktime(rfc822.parsedate(index_tag.Section["Date"]))
- dists[dist] = date
- if dist == current_dist:
- current_dist_supported = str_to_bool(index_tag.Section["Supported"])
- current_dist_date = time.mktime(rfc822.parsedate(index_tag.Section["Date"]))
- step_result = index_tag.Step()
- # check for newer dists
- new_dist = ""
- found = False
- for dist in dists:
- if dist == current_dist:
- found = True
- if dists[dist] > current_dist_date and not dist == current_dist:
- new_dist = dist
- current_dist_date = dists[dist]
-
- # we know nothing about the installed distro, so we just return
- # silently
- if not found:
- return False
-
- # only warn if unsupported and a new dist is available (because
- # the development version is also unsupported)
- if new_dist != "" and not current_dist_supported:
- self.current_dist_not_supported(new_dist)
- elif new_dist != "":
- self.new_dist_available(new_dist)
- # don't run this event again
- return False
- # we have no information about the meta-release, so run it again
- return True
-
- # the network thread that tries to fetch the meta-index file
- def get_meta_release(self):
- lastmodified = 0
- req = urllib2.Request(METARELEASE_URI)
- if os.access(METARELEASE_FILE, os.W_OK):
- lastmodified = os.stat(METARELEASE_FILE).st_mtime
- if lastmodified > 0:
- req.add_header("If-Modified-Since", lastmodified)
- try:
- uri=urllib2.urlopen(req)
- f=open(METARELEASE_FILE,"w+")
- for line in uri.readlines():
- f.write(line)
- f.flush()
- f.seek(0,0)
- self.metarelease_information=f
- uri.close()
- except urllib2.URLError:
- pass
# fixme: we should probably abstract away all the stuff from libapt
def initCache(self):
@@ -747,10 +660,13 @@ class UpdateManager(SimpleGladeApp):
self.cache._depcache.Init()
def main(self):
- # FIXME: stat a check update thread
- self.metarelease_information = None
- t=thread.start_new_thread(self.get_meta_release, ())
- gobject.timeout_add(1000, self.check_meta_release)
+ self.meta = MetaRelease()
+ # FIXME: this callback seting sucks!
+ #self.meta.current_dist_not_supported = self.current_dist_not_supported
+ #self.meta.new_dist_available = self.new_dist_available
+ self.meta.connect("new_dist_available",self.new_dist_available)
+ self.meta.connect("dist_no_longer_supported",self.dist_no_longer_supported)
+ gobject.timeout_add(1000, self.meta.check)
#self.get_meta_release()
self.store.append([True, _("Initializing and getting list of updates..."),
@@ -759,7 +675,5 @@ class UpdateManager(SimpleGladeApp):
while gtk.events_pending():
gtk.main_iteration()
- # global init of apt, FIXME: move all the apt details in it's own class
- apt_pkg.init()
self.fillstore()
gtk.main()