23
23
pygtk.require('2.0')
32
from gettext import gettext as _
35
26
from ReleaseNotesViewer import ReleaseNotesViewer
36
27
from Common.utils import *
38
class DistUpgradeFetcher(object):
40
def __init__(self, parent, new_dist):
28
from Core.DistUpgradeFetcherCore import DistUpgradeFetcherCore
29
from gettext import gettext as _
32
class DistUpgradeFetcherGtk(DistUpgradeFetcherCore):
34
def __init__(self, new_dist, progress, parent):
35
DistUpgradeFetcherCore.__init__(self,new_dist,progress)
41
36
self.parent = parent
42
37
self.window_main = parent.window_main
43
self.new_dist = new_dist
39
def error(self, summary, message):
40
return error(self.window_main, summary, message)
45
42
def showReleaseNotes(self):
46
43
# FIXME: care about i18n! (append -$lang or something)
95
def authenticate(self):
96
if self.new_dist.upgradeToolSig:
97
f = self.tmpdir+"/"+os.path.basename(self.new_dist.upgradeTool)
98
sig = self.tmpdir+"/"+os.path.basename(self.new_dist.upgradeToolSig)
99
print "authenticate '%s' against '%s' " % (f,sig)
100
if not self.gpgauthenticate(f, sig):
103
# we may return False here by default if we want to make a sig
107
def gpgauthenticate(self, file, signature,
108
keyring='/etc/apt/trusted.gpg'):
109
""" authenticated a file against a given signature, if no keyring
110
is given use the apt default keyring
112
gpg = GnuPGInterface.GnuPG()
113
gpg.options.extra_args = ['--no-options',
114
'--homedir',self.tmpdir,
115
'--no-default-keyring',
116
'--keyring', keyring]
117
proc = gpg.run(['--verify', signature, file],
118
create_fhs=['status','logger','stderr'])
119
gpgres = proc.handles['status'].read()
123
# gnupg returned a problem (non-zero exit)
124
print "exception from gpg: %s" % e
125
print "Debug information: "
126
print proc.handles['status'].read()
127
print proc.handles['stderr'].read()
128
print proc.handles['logger'].read()
130
if "VALIDSIG" in gpgres:
132
print "invalid result from gpg:"
136
def extractDistUpgrader(self):
138
print "extracting '%s'" % (self.tmpdir+"/"+os.path.basename(self.uri))
139
tar = tarfile.open(self.tmpdir+"/"+os.path.basename(self.uri),"r")
145
def verifyDistUprader(self):
146
# FIXME: check a internal dependency file to make sure
147
# that the script will run correctly
149
# see if we have a script file that we can run
150
self.script = script = "%s/%s" % (self.tmpdir, self.new_dist.name)
151
if not os.path.exists(script):
152
# no script file found in extracted tarbal
153
primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
154
_("Could not run the upgrade tool")
155
secondary = _("This is most likely a bug in the upgrade tool. "
156
"Please report it as a bug")
157
dialog = gtk.MessageDialog(self.window_main,gtk.DIALOG_MODAL,
158
gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,"")
160
dialog.set_markup(primary);
161
dialog.format_secondary_text(secondary);
167
def fetchDistUpgrader(self):
168
# now download the tarball with the upgrade script
169
self.tmpdir = tmpdir = tempfile.mkdtemp()
172
# turn debugging on here (if required)
173
#apt_pkg.Config.Set("Debug::Acquire::http","1")
175
progress = GtkProgress.GtkFetchProgress(self.parent,
176
_("Downloading the upgrade "
178
_("The upgrade tool will "
179
"guide you through the "
181
fetcher = apt_pkg.GetAcquire(progress)
183
if self.new_dist.upgradeToolSig != None:
184
uri = self.new_dist.upgradeToolSig
185
af = apt_pkg.GetPkgAcqFile(fetcher,uri, descr=_("Upgrade tool signature"))
186
if self.new_dist.upgradeTool != None:
187
self.uri = self.new_dist.upgradeTool
188
af = apt_pkg.GetPkgAcqFile(fetcher,self.uri, descr=_("Upgrade tool"))
189
if fetcher.Run() != fetcher.ResultContinue:
194
def runDistUpgrader(self):
195
#print "runing: %s" % script
197
os.execv("/usr/bin/gksu",["gksu",self.script])
199
os.execv(self.script,[self.script])
205
shutil.rmtree(self.tmpdir)
208
# see if we have release notes
209
if not self.showReleaseNotes():
211
if not self.fetchDistUpgrader():
212
error(self.window_main,
213
_("Failed to fetch"),
214
_("Fetching the upgrade failed. There may be a network "
217
if not self.extractDistUpgrader():
218
error(self.window_main,
219
_("Failed to extract"),
220
_("Extracting the upgrade failed. There may be a problem "
221
"with the network or with the server. "))
224
if not self.verifyDistUprader():
225
error(self.window_main,
226
_("Verfication failed"),
227
_("Verifying the upgrade failed. There may be a problem "
228
"with the network or with the server. "))
231
if not self.authenticate():
232
error(self.window_main,
233
_("Authentication failed"),
234
_("Authenticating the upgrade failed. There may be a problem "
235
"with the network or with the server. "))
238
self.runDistUpgrader()
241
92
if __name__ == "__main__":
242
93
error(None, "summary","message")
243
d = DistUpgradeFetcher(None,None)
94
d = DistUpgradeFetcherGtk(None,None)
244
95
print d.authenticate('/tmp/Release','/tmp/Release.gpg')