aboutsummaryrefslogtreecommitdiffstats
path: root/bin/commander/packages.py
blob: 8841ead0f85627797c18a7a16b3842d08b3ab916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: iso8859-15 -*-

from oe import data, event, parse, debug, build, make
import copy, glob, os, sys

class Packages:
    """Provide a higher level API to the OE package data"""
    __instance = None

    def __init__( self, cfg = {} ):
        print "Packages.__init__()"
        make.cfg = cfg
        make.pkgdata = {}
        make.pkgs = {}
        self.valid = False

        try:
            make.cfg = parse.handle("conf/oe.conf", make.cfg )
        except IOError:
            fatal("Unable to open oe.conf")

    def instance():
        if Packages.__instance is None:
            Packages.__instance = Packages()
        return Packages.__instance

    instance = staticmethod( instance )

    def numPackages( self ):
        return len( make.pkgdata )

    def names( self ):
        return make.pkgdata.keys()

    def isVirtual( self, package ):
        return "virtual" in data.getVar( "PROVIDES", make.pkgdata[package], 1 ) # Python 2.3 only

    def data( self, package, key ):
        if package in make.pkgdata and key in make.pkgdata[package]:
            return data.getVar( key, make.pkgdata[package], 1 )
        else:
            return "N/A"

    def getVar( self, key ):
        return data.getVar( key, make.cfg )

    def scan( self, progressCallback ):
        make.collect_oefiles( progressCallback )


#------------------------------------------------------------------------#
# main
#------------------------------------------------------------------------#

if __name__ == "__main__":
    def function( *args, **kwargs ):
        print args, kwargs

    p = Packages( cfg )
    p.scan( function )