Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/
Date: Tue, 29 May 2012 17:10:22
Message-Id: 1338310856.033f6e38ee070ee1e71563bbc8d3a308604706e0.dywi@gentoo
1 commit: 033f6e38ee070ee1e71563bbc8d3a308604706e0
2 Author: Andre Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Tue May 29 17:00:56 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Tue May 29 17:00:56 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=033f6e38
7
8 roverlay, fileio: add possibility to ignore packages with unsuitable description data (os type); rename _verify_read_data -> _parse_read_data
9 modified: fileio.py
10
11 ---
12 roverlay/fileio.py | 115 +++++++++++++++++++++++++++++++++++++--------------
13 1 files changed, 83 insertions(+), 32 deletions(-)
14
15 diff --git a/roverlay/fileio.py b/roverlay/fileio.py
16 index 6e905b9..5d13cf8 100644
17 --- a/roverlay/fileio.py
18 +++ b/roverlay/fileio.py
19 @@ -49,7 +49,7 @@ class DescriptionReader:
20 a field listed in DESCRIPTION_FIELD_MAP (any match results in immediate return).
21 Then, a new iteration over the field map compares field_identifier
22 with all aliases until the first case-(in)sensitive match (-> immediate return).
23 - An emptry string will be returned if none of the above searches succeed.
24 + None will be returned if none of the above searches succeed.
25
26 In other words: this method decides whether a field_identifier will be used and if so,
27 with which name.
28 @@ -224,11 +224,13 @@ class DescriptionReader:
29 package_version = package_version,
30 )
31
32 -
33 -
34 @classmethod
35 - def _verify_read_data ( self, read_data ):
36 - """Verifies and fixes (e.g. add default values) read data"""
37 + def _parse_read_data ( self, read_data ):
38 + """Verifies and parses/fixes read data.
39 +
40 + arguments:
41 + * read_data -- data from file, will be modified
42 + """
43
44 def stats ( data ):
45 """Temporary function that prints some info about the given data."""
46 @@ -239,49 +241,92 @@ class DescriptionReader:
47 logging.write ( "=== end of list ===\n" )
48 del field
49
50 + def _value_in_strlist ( _val, _list, case_insensitive=True ):
51 + """Returns true if value is in the given list."""
52 + el = None
53 + if case_insensitive:
54 + lowval = _val.lower()
55 + for el in _list:
56 + if el.lower() == lowval:
57 + return True
58 + del lowval
59 + else:
60 + for el in _list:
61 + if el == _val:
62 + return True
63 +
64 + del el
65 + return False
66 +
67 +
68 stats ( read_data )
69
70 - # "finalize" data
71 - logging.write ( "Fixing data...\n" )
72 field = None
73
74 - # join values to a single str
75 + # insert default values
76 + for field in const.DESCRIPTION_FIELD_MAP.keys():
77 + if not field in read_data and 'default_value' in const.DESCRIPTION_FIELD_MAP [field]:
78 + read_data [field] = const.DESCRIPTION_FIELD_MAP [field] ['default_value']
79 +
80 + # join values to a single string
81 for field in self._get_fields_with_flag ( 'joinValues' ):
82 if field in read_data.keys():
83 read_data [field] = ' ' . join ( read_data [field] )
84
85 - # verify that all necessary fields have been added and are set
86 - missing_fields = dict()
87 + # ensure that all mandatory fields are set
88 + missing_fields = list()
89 +
90 for field in self._get_fields_with_flag ( 'mandatory' ):
91 if field in read_data:
92 if not len (read_data [field]):
93 - missing_fields [field] = 'unset'
94 + missing_fields.append ( field )
95 else:
96 - missing_fields [field] = 'missing'
97 + missing_fields.append ( field )
98
99 - del field
100
101 - if len (missing_fields):
102 +
103 +
104 + # check for fields that allow only certain values
105 + unsuitable_fields = list()
106 +
107 + for field in read_data.keys():
108 + # skip _fileinfo
109 + if field != '_fileinfo':
110 + if 'allowed_values' in const.DESCRIPTION_FIELD_MAP [field]:
111 + if not _value_in_strlist ( read_data [field],
112 + const.DESCRIPTION_FIELD_MAP [field] ['allowed_values']
113 + ): unsuitable_fields.append ( field )
114 +
115 +
116 + stats ( read_data )
117 +
118 +
119 +
120 + valid = True
121 +
122 + if len ( missing_fields ):
123 + valid = False
124 +
125 logging.write (
126 "Verification of mandatory fields failed, the result leading to this was: " +
127 - str (missing_fields) + "\n"
128 + str ( missing_fields ) + "\n"
129 )
130
131 #<raise custom exception>
132 raise Exception ("^^^look above")
133
134 - del missing_fields
135 + if len ( unsuitable_fields ):
136 + valid = False
137
138 - # add/insert default values
139 - for field in const.DESCRIPTION_FIELD_MAP.keys():
140 - if not field in read_data and 'default_value' in const.DESCRIPTION_FIELD_MAP [field]:
141 - read_data [field] = const.DESCRIPTION_FIELD_MAP [field] ['default_value']
142 -
143 -
144 - stats ( read_data )
145 + logging.write (
146 + "Some fields have values that forbid further parsing, the result leading to this was: " +
147 + str ( unsuitable_fields ) + "\n"
148 + )
149
150 - return True
151 + del missing_fields
152 + del field
153
154 + return valid
155
156 @classmethod
157 def readfile ( self, filepath ):
158 @@ -296,18 +341,18 @@ class DescriptionReader:
159 -> split field values
160 -> filter out unwanted/useless fields
161
162 - The return value is a dict "<field name> => <field value[s]>"
163 - with <field value> as str and <field values> as list.
164 + The return value is a dict { fileinfo , description_data } or None if
165 + the read data are "useless" (not suited to create an ebuild for it,
166 + e.g. if OS_TYPE is not unix).
167 """
168
169 - read_data = dict (
170 - _ = DescriptionReader._get_fileinfo ( filepath )
171 - )
172 + read_data = dict ()
173 + fileinfo = DescriptionReader._get_fileinfo ( filepath )
174
175
176 try:
177 desc_lines = DescriptionReader._get_desc_from_file (
178 - filepath, read_data ['_'] ['package_name']
179 + filepath, fileinfo ['package_name']
180 )
181
182
183 @@ -377,8 +422,14 @@ class DescriptionReader:
184 del sline, line, val, field_context
185
186
187 - if self._verify_read_data ( read_data ):
188 - return read_data
189 + if self._parse_read_data ( read_data ):
190 + logging.write ( '## success ##\n' )
191 + logging.write ( ( str ( read_data ) ) )
192 + return dict (
193 + fileinfo = fileinfo,
194 + description_data = read_data
195 + )
196 else:
197 + logging.write ( '## fail ##\n' )
198 return None