improve keyboard error handling
[bitbake.git] / bin / commander / provideritem.py
1 #!/usr/bin/env python
2 # -*- coding: iso8859-15 -*-
3
4 import os
5 from qt import *
6 from appinfo import *
7 from packages import Packages
8
9 class ProviderItem( QListViewItem ): #QCheckListItem
10
11     columns = { "PROVIDES":     0,
12                 "CHECK":        1,
13                 "unpack":2, "patch":3, "configure":4, "compile":5, "stage":6, "install":7,
14                 "STATUS":       8,
15                 "CATEGORY":     9,
16                 "SECTION":      10,
17                 "PRIORITY":     11,
18                 "MAINTAINER":   12,
19                 "SRC_URI":      13,
20                 "HOMEPAGE":     14,
21                 "DEPENDS":      15,
22                 "RDEPENDS":     16,
23                 "SHORTNAME":    17 }
24
25     icons = {}
26
27     def __init__( self, parent, provider, virtual = False ):
28
29         if not ProviderItem.icons:
30             ProviderItem.icons =  { "unpack"    : QPixmap( imageDir + "do_unpack.png" ),
31                "patch"     : QPixmap( imageDir + "do_patch.png" ),
32                "configure" : QPixmap( imageDir + "do_configure.png" ),
33                "compile"   : QPixmap( imageDir + "do_compile.png" ),
34                "stage"     : QPixmap( imageDir + "do_stage.png" ),
35                "install"   : QPixmap( imageDir + "do_install.png" ) }
36
37         self.parent = parent
38         self.virtual = virtual
39         self.p = Packages.instance()
40         self.fullname = provider
41         self.shortname = provider.split( "/" )[-1]
42         # <HACK>
43         # Caution! I have absolutely no idea if it is correct to assume, that
44         # the last provider is the most unspecific one... for now this seems to work :)
45         # </HACK>
46         self.mup = self.mupValue()
47         self.virtualp = self.virtualValue()
48
49         print "ProviderItemInit: FN='%s' SN='%s', VP='%s', MUP='%s'" % ( self.fullname, self.shortname, self.virtualp, self.mup )
50
51         if self.mup == "N/A":
52             print "Warning: MUP of '%s' seems to be not available." % provider
53
54         if virtual:
55             QListViewItem.__init__( self, parent, provider )
56             return
57
58         if self.virtualp:
59             #
60             # check if a corresponding virtual parent element already has been added
61             #
62             vparent = parent.findItem( self.virtualp, 0 )
63             if not vparent:
64                 vparent = ProviderItem( parent, self.virtualp, True )
65                 vparent.setPixmap( 0, QPixmap( imageDir + "virtual.png" ) )
66
67             QListViewItem.__init__( self, vparent, provider )
68             #QCheckListItem.__init__( self, vparent, provider, QCheckListItem.CheckBox )
69
70         else:
71             #
72             # check if a corresponding mup parent element already has been added
73             #
74             vparent = parent.findItem( self.mup, 0 )
75             if not vparent:
76                 vparent = ProviderItem( parent, self.mup, True )
77                 vparent.setPixmap( 0, QPixmap( imageDir + "virtual.png" ) )
78             QListViewItem.__init__( self, vparent, provider )
79
80         self.decorate()
81         self.syncStatus()
82         self.setPixmap( 0, QPixmap( imageDir + "package.png" ) )
83         self.setCheckStatus( False )
84
85     def getVar( self, value ):
86         return self.p.data( self.fullname, value )
87
88     def virtualValue( self ):
89         #print self.p.data(self.fullname, "PROVIDES" )
90         providers = self.p.data(self.fullname, "PROVIDES" ).split()
91         for p in providers:
92             if p.split( '/' )[0] == "virtual": return p
93
94     def mupValue( self ):
95         providers = self.p.data( self.fullname, "PROVIDES" ).split()
96         return providers[-1]
97
98     def setCheckStatus( self, checked ):
99         self.checked = checked
100         if self.checked:
101             self.setPixmap( 1, QPixmap( imageDir + "checked.png" ) )
102         else:
103             self.setPixmap( 1, QPixmap( imageDir + "unchecked.png" ) )
104
105     def setBuildStatus( self, *args, **kwargs ):
106         for el in kwargs:
107             if el in ProviderItem.columns:
108                 self.setPixmap( ProviderItem.columns[el], ( QPixmap(), ProviderItem.icons[el] )[ kwargs[el] ] )
109         if "status" in kwargs:
110             self.setText( ProviderItem.columns["STATUS"], kwargs["status"] )
111
112     def decorate( self ):
113         if self.fullname.startswith( "virtual" ):
114             return
115         self.st( "PROVIDES", self.fullname.split('/')[-1] )
116         self.st( "CATEGORY", self.p.data(self.fullname, "CATEGORY") )
117         self.st( "SECTION", self.p.data(self.fullname, "SECTION") )
118         self.st( "PRIORITY", self.p.data(self.fullname, "PRIORITY") )
119         self.st( "MAINTAINER", self.p.data(self.fullname, "MAINTAINER") )
120         self.st( "SRC_URI", self.p.data(self.fullname, "SRC_URI") )
121         self.st( "HOMEPAGE", self.p.data(self.fullname, "HOMEPAGE") )
122         self.st( "DEPENDS", self.p.data(self.fullname, "DEPENDS") )
123         self.st( "RDEPENDS", self.p.data(self.fullname, "RDEPENDS") )
124         self.st( "SHORTNAME", self.shortname )
125
126     def syncStatus( self ):
127         if self.virtual:
128             return
129
130         status = {}
131         for el in "unpack patch configure compile stage install".split():
132             statname = "%s/stamps/%s-%s-%s.do_%s" % ( self.p.getVar( "TMPDIR" ),
133                                                       self.getVar( "PN" ),
134                                                       self.getVar( "PV" ),
135                                                       self.getVar( "PR" ),
136                                                       el )
137             #print "stat'ing", statname,
138             try:
139                 os.stat( statname )
140             except OSError:
141                 status[el] = False
142                 #print "not found."
143             else:
144                 status[el] = True
145                 #print "found."
146
147         print "status for package", self.shortname, "=", status
148         apply( self.setBuildStatus, (), status )
149
150     def st( self, column, value ):
151         self.setText( ProviderItem.columns[column], value )
152
153     def toggleCheck( self ):
154         self.setCheckStatus( not self.checked )
155
156     def selectToBuild( self, honorDeps = True ):
157         pass
158
159 #------------------------------------------------------------------------#
160 # main
161 #------------------------------------------------------------------------#
162
163 if __name__ == "__main__":
164     import sys
165     from qt import *
166     app = QApplication( sys.argv )
167     mw = QListView()
168     app.setMainWidget( mw )
169     app.exec_loop()
170