Deteled some code not need any more, because off, processTransaction is now
[yumguicore.git] / testgui2.py
blob30f9c27f0010c8e9c5a3e519addfce68276646dc
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 import sys
16 import logging
17 import gtk
18 import gtk.glade
20 import time
22 from yum.Errors import YumBaseError
23 from yum.rpmtrans import RPMTransaction
26 from yumguicore import YumGuiBase,YumGuiPackageQueue, YumGuiDownloadError,\
27 YumGuiDepsolveError,YumGuiDepsolveError, YumGuiTransactionError
29 from yumguicore.gui import UI,Controller,TextViewConsole,\
30 TextViewLogHandler,doLoggerSetup,doGtkEvents,Progress
32 from yumguicore.views import YumGuiPackageView, YumGuiTransactionView,YumGuiGroupView
33 from yumguicore.callback import YumGuiDownloadCallback,YumGuiRPMCallback
34 from yumguicore.dialogs import questionDialog
35 import tests
38 class MyYumGuiApp(Controller):
39 ''' This class contains all glade signal callbacks '''
42 def __init__( self ):
43 # Create and ui object contains the widgets.
44 ui = UI( 'testgui2.glade' , 'main', 'yumex' )
45 # init the Controller Class to connect signals.
46 Controller.__init__( self, ui )
47 self.logger = logging.getLogger('yum.verbose.MyYumGuiApp')
48 self.firstRun = True
49 self.packages = None
50 self.main()
52 #****************** Glade callback methods ********************
53 def onQuit(self,widget,data=None):
54 '''
55 Quit the application
56 '''
57 gtk.main_quit() # Exit gtk
58 sys.exit(0)
60 def on_gotoPage1_clicked(self,widget,data=None):
61 '''
62 Quit the application
63 '''
64 self.ui.notebook.set_current_page(1)
66 def on_gotoPage0_clicked(self,widget,data=None):
67 '''
68 Quit the application
69 '''
70 self.ui.notebook.set_current_page(0)
73 #**************************************************************
74 def setupGUI(self):
75 ''' Setup the GUI & logging '''
76 self.ui.main.connect( "delete_event", self.onQuit )
77 self.ui.notebook.set_show_tabs( False )
78 self.ui.main.present()
79 self.progress = Progress(self.ui.progressbar,self.ui.progresslabel,self.ui.vboxProgress)
80 self.ui.TransactionLabel.set_markup('<big><b>Current Transaction</b></big>')
81 self.rpmCallback = YumGuiRPMCallback(self.progress)
84 def processTransaction(self):
85 '''
86 Perform the yum transaction
87 - Resolve Dependencies
88 - Download Packages.
89 - Check GPG Signature.
90 - Run Test Transaction
91 - Run Transaction
92 '''
93 try:
94 self.progress.show()
95 self.logger.info('Resolve Dependencies')
96 self.ui.book.set_current_page(OUTPUT_VIEW)
97 self.yumbase.doDepSolve()
98 self.ui.book.set_current_page(TRANSACTION_VIEW)
99 self.transView.refresh()
100 self.logger.info(self.queue.list())
101 if not questionDialog(self.ui.main,'Do you want to continue with the transaction'):
102 return
103 self.ui.book.set_current_page(OUTPUT_VIEW)
104 self.logger.info('Download Packages and check signatures')
105 self.yumbase.downloadPackages()
106 self.logger.info('Run Test Transaction')
107 self.yumbase.testTransaction()
108 self.logger.info('Run Transaction')
109 self.yumbase.runTransaction(self.rpmCallback)
110 # Catch depsolve errors
111 except YumGuiDepsolveError, msgs:
112 mstrs = '\n'.join(msgs)
113 msg = _( "Error in Dependency Resolution" )
114 self.logger.error(msg)
115 self.logger.error(mstrs)
116 # catch download errors
117 except YumGuiDownloadError, msgs:
118 mstrs = '\n'.join(msgs)
119 msg = _( "Error in Download" )
120 self.logger.error(msg)
121 self.logger.error(mstrs)
122 # catch Transaction errors
123 except YumGuiTransactionError, msgs:
124 mstrs = '\n'.join(msgs)
125 self.logger.error(mstrs)
126 # catch other yum errors.
127 except YumBaseError, msgs:
128 mstrs = '\n'.join(msgs)
129 self.logger.error(mstrs)
130 self.progress.hide()
132 def setupYum(self):
133 self.ui.notebook.set_current_page(1)
134 self.progress.show()
135 if not self.firstRun: # Dont do reset the first time
136 self.yumbase.reset()
137 else:
138 self.firstRun = False
139 self.yumbase.setup(doUpdates=True, doUpdateMetaData=False)
140 # Get a list of all packages (installed + available)
141 pkgs = self.yumbase.getPackages(sort=True)
142 # Get a list of all packages (installed + available)
143 updates = self.yumbase.getPackages(pkgTypes=['updates'],sort=True)
144 # show the packages in the package view, use po.name for typeahead search
145 #self.pkgView.populate(updates,'name')
146 self.packages = pkgs
147 self.ui.notebook.set_current_page(0)
148 self.progress.hide()
150 def doTests(self):
152 Do some testing.
154 #tests.testProgress(self.progress)
155 #tests.testTextViewConsole(self.output)
156 #tests.testRPMCallback(self.rpmCallback)
157 #time.sleep(5)
159 def main(self):
160 self.setupGUI()
161 self.yumbase = YumGuiBase(debuglevel= 4)
162 # Setup a PackageQueue an interface to yumbase.tsInfo
163 self.queue = YumGuiPackageQueue(self.yumbase,debug=False)
164 # Setup a PackageView to display packages.
165 dlCb = YumGuiDownloadCallback(self.progress)
166 self.yumbase.setDownloadCallback(dlCb)
167 # setup yum (load repo metadata etc)
168 self.setupYum()
170 if __name__ == "__main__":
171 mainApp = MyYumGuiApp()
172 gtk.main()