3
# Copyright (c) 2004,2005 Canonical
5
# Author: Michael Vogt <michael.vogt@ubuntu.com>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29
from subprocess import Popen,PIPE
32
def __init__(self, name, version, date, supported):
34
self.version = version
36
self.supported = supported
37
self.releaseNotesURI = None
38
self.upgradeTool = None
39
self.upgradeToolSig = None
41
class MetaReleaseCore(object):
44
METARELEASE_URI = "http://changelogs.ubuntu.com/meta-release"
45
METARELEASE_URI_UNSTABLE = "http://changelogs.ubuntu.com/meta-release-development"
46
METARELEASE_URI_PROPOSED = "http://changelogs.ubuntu.com/meta-release-proposed"
47
METARELEASE_FILE = "/var/lib/update-manager/meta-release"
49
def __init__(self, useDevelopmentRelease=False, useProposed=False):
50
# check what uri to use
51
if useDevelopmentRelease:
52
self.METARELEASE_URI = self.METARELEASE_URI_UNSTABLE
54
self.METARELEASE_URI = self.METARELEASE_URI_PROPOSED
55
# check if we can access the METARELEASE_FILE
56
if not os.access(self.METARELEASE_FILE, os.F_OK|os.W_OK|os.R_OK):
57
path = os.path.expanduser("~/.update-manager/")
58
if not os.path.exists(path):
60
self.METARELEASE_FILE = os.path.join(path,"meta-release")
61
self.metarelease_information = None
62
self.downloading = True
63
# information about the available dists
65
self.no_longer_supported = None
66
# we start the download thread here and we have a timeout
67
t=thread.start_new_thread(self.download, ())
68
#t=thread.start_new_thread(self.check, ())
70
def dist_no_longer_supported(self, dist):
71
""" virtual function that is called when the distro is no longer
74
self.no_longer_supported = dist
75
def new_dist_available(self, dist):
76
""" virtual function that is called when a new distro release
82
" return the codename of the current runing distro "
83
p = Popen(["lsb_release","-c","-s"],stdout=PIPE)
86
sys.stderr.write("lsb_release returned exitcode: %i\n" % res)
87
dist = string.strip(p.stdout.readline())
92
current_dist_name = self.get_dist()
96
# parse the metarelease_information file
97
index_tag = apt_pkg.ParseTagFile(self.metarelease_information)
98
step_result = index_tag.Step()
100
if index_tag.Section.has_key("Dist"):
101
name = index_tag.Section["Dist"]
103
rawdate = index_tag.Section["Date"]
104
date = time.mktime(rfc822.parsedate(rawdate))
105
supported = bool(index_tag.Section["Supported"])
106
version = index_tag.Section["Version"]
107
# add the information to a new date object
108
dist = Dist(name, version, date,supported)
109
if index_tag.Section.has_key("ReleaseNotes"):
110
dist.releaseNotesURI = index_tag.Section["ReleaseNotes"]
111
if index_tag.Section.has_key("UpgradeTool"):
112
dist.upgradeTool = index_tag.Section["UpgradeTool"]
113
if index_tag.Section.has_key("UpgradeToolSignature"):
114
dist.upgradeToolSig = index_tag.Section["UpgradeToolSignature"]
116
if name == current_dist_name:
118
step_result = index_tag.Step()
120
# first check if the current runing distro is in the meta-release
121
# information. if not, we assume that we run on something not
122
# supported and silently return
123
if current_dist == None:
124
print "current dist not found in meta-release file"
127
# then see what we can upgrade to (only upgrade to supported dists)
130
if dist.date > current_dist.date and dist.supported == True:
132
#print "new dist: %s" % upgradable_to
135
# only warn if unsupported and a new dist is available (because
136
# the development version is also unsupported)
137
if upgradable_to != "" and not current_dist.supported:
138
self.dist_no_longer_supported(upgradabl_to)
139
elif upgradable_to != "":
140
self.new_dist_available(upgradable_to)
142
# parsing done and sucessfully
145
# the network thread that tries to fetch the meta-index file
146
# can't touch the gui, runs as a thread
150
req = urllib2.Request(self.METARELEASE_URI)
151
if os.access(self.METARELEASE_FILE, os.W_OK):
152
lastmodified = os.stat(self.METARELEASE_FILE).st_mtime
154
req.add_header("If-Modified-Since", lastmodified)
156
uri=urllib2.urlopen(req)
157
if (os.path.exists(self.METARELEASE_FILE) and
158
not os.access(self.METARELEASE_FILE,os.W_OK)):
159
os.unlink(self.METARELEASE_FILE)
160
f=open(self.METARELEASE_FILE,"w+")
161
for line in uri.readlines():
165
self.metarelease_information=f
167
except urllib2.URLError:
168
if os.path.exists(self.METARELEASE_FILE):
169
f=open(self.METARELEASE_FILE,"r")
170
# now check the information we have
171
self.downloading = False
172
if self.metarelease_information != None: