MythTV  master
makeopts.py
Go to the documentation of this file.
1 # smolt - Fedora hardware profiler
2 #
3 # Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19 import re
20 import portage
21 
22 SHORT_PARA_PATTERN = '-[CfIOW]\\s+\\S+|-[jl](\\s+[^-]\\S*)?|-[^-]\\S+'
23 LONG_PARA_PATTERN = '--\\S+|--\\S+=\\S+'
24 PARA_PATTERN = re.compile('(%s|%s)\\b' % (SHORT_PARA_PATTERN, LONG_PARA_PATTERN))
25 
26 class MakeOpts:
27  def __init__(self, value=None):
28  """
29  >>> m = MakeOpts("-C dir -f file -I dir -o file -W file -j 3 -l 4 -j -j3 -l --always-make")
30  >>> m.get()
31  ['-C dir', '-f file', '-I dir', '-W file', '-j 3', '-l 4', '-j', '-j3', '-l', '--always-make']
32  """
33  if value is None:
34  value = portage.settings['MAKEOPTS']
35  self._makeopts = self._parse(value)
36 
37  def _parse(self, flags):
38  list = []
39  for m in re.finditer(PARA_PATTERN, flags):
40  text = re.sub('\\s{2,}', ' ', m.group()) # Normalize whitespace
41  list.append(text)
42  return list
43 
44  def get(self):
45  return self._makeopts
46 
47  def serialize(self):
48  return self._makeopts
49 
50  def dump(self):
51  print 'MAKEOPTS: ' + str(self.get())
52  print
53 
54 
55 if __name__ == '__main__':
56  import doctest
57  doctest.testmod(verbose=True)