2 # vim: ai ts=4 sts=4 et sw=4
4 # Copyright (c) 2007 Intel Corporation
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; version 2 of the License
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc., 59
17 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 An FSet object represents a functional set of packages to install in a
31 target filesystem. An FSet contains an array of package names in
32 FSet.packages, an array of additional debug packages in
33 FSet.debug_packages, and an array of dependant FSet names in FSet.deps.
39 def addFile(self
, filename
):
40 """Add a config file to the FSet"""
41 filename
= os
.path
.realpath(os
.path
.abspath(os
.path
.expanduser(filename
)))
42 self
.filenames
.append(filename
)
43 self
.__parseFile
(filename
)
46 def __parseFile(self
, filename
):
47 valid_values
= { 'desc' : '', 'pkgs' : [], 'debug_pkgs' : [],
49 if not os
.path
.isfile(filename
):
51 p
= ConfigParser
.ConfigParser()
52 filenames
= p
.read(filename
)
53 for section
in p
.sections():
54 orig_section
= section
55 section
= section
.lower()
56 if section
in self
.__fsets
:
57 raise ValueError, _("Error: Already have a section called: %s") % section
59 work_dict
['filename'] = filename
60 fset
= FsetInstance(section
)
61 for name
, value
in p
.items(orig_section
):
63 self
.__fsets
[section
] = fset
66 def __getitem__(self
, key
):
67 return self
.__fsets
[key
.lower()]
69 return self
.__fsets
.__iter
__()
71 return self
.__fsets
.iterkeys()
73 return len(self
.__fsets
)
80 class FsetInstance(object):
81 valid_values
= { 'desc' : '', 'pkgs' : [], 'debug_pkgs' : [], 'deps' : [] }
82 def __init__(self
, name
):
83 self
.name
= name
.lower()
85 def add(self
, key
, value
):
87 if key
not in FsetInstance
.valid_values
:
88 print _("Found unsupported value, ignoring: %s = %s") % (key
, value
)
90 work_type
= type(FsetInstance
.valid_values
[key
])
91 if work_type
== type([]):
93 elif work_type
== type(''):
96 print _("Error: Unsupported type specified in FsetInstance.valid_values")
97 print _("Type was: %s") % work_type
99 self
.data
[key
] = value
102 if key
not in FsetInstance
.valid_values
:
105 return self
.data
[key
]
107 return FsetInstance
.valid_values
[key
]
108 def __getitem__(self
, key
):
110 def __getattr__(self
, key
):
113 return ('FsetInstance("%s", %s)' % (self
.name
, self
.data
))
115 return ('<fset name="%s" data="%s">' % (self
.name
, self
.data
))
117 if __name__
== '__main__':
118 if len(sys
.argv
) == 1:
119 print >> sys
.stderr
, _("USAGE: %s FSET_FILE ...") % (sys
.argv
[0])
122 for filename
in sys
.argv
[1:]:
123 fset
.addFile(filename
)
125 for key
in fset
.fsets
:
128 print fset
[key
].filename
, fset
[key
]['filename']