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 from builtins import str
20 from builtins import object
21 import re
22 import portage
23 
24 SHORT_PARA_PATTERN = '-[CfIOW]\\s+\\S+|-[jl](\\s+[^-]\\S*)?|-[^-]\\S+'
25 LONG_PARA_PATTERN = '--\\S+|--\\S+=\\S+'
26 PARA_PATTERN = re.compile('(%s|%s)\\b' % (SHORT_PARA_PATTERN, LONG_PARA_PATTERN))
27 
28 class MakeOpts(object):
29  def __init__(self, value=None):
30  """
31  >>> m = MakeOpts("-C dir -f file -I dir -o file -W file -j 3 -l 4 -j -j3 -l --always-make")
32  >>> m.get()
33  ['-C dir', '-f file', '-I dir', '-W file', '-j 3', '-l 4', '-j', '-j3', '-l', '--always-make']
34  """
35  if value is None:
36  value = portage.settings['MAKEOPTS']
37  self._makeopts = self._parse(value)
38 
39  def _parse(self, flags):
40  list = []
41  for m in re.finditer(PARA_PATTERN, flags):
42  text = re.sub('\\s{2,}', ' ', m.group()) # Normalize whitespace
43  list.append(text)
44  return list
45 
46  def get(self):
47  return self._makeopts
48 
49  def serialize(self):
50  return self._makeopts
51 
52  def dump(self):
53  print('MAKEOPTS: ' + str(self.get()))
54  print()
55 
56 
57 if __name__ == '__main__':
58  import doctest
59  doctest.testmod(verbose=True)
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts.dump
def dump(self)
Definition: makeopts.py:52
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts._parse
def _parse(self, flags)
Definition: makeopts.py:39
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts._makeopts
_makeopts
Definition: makeopts.py:37
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts.__init__
def __init__(self, value=None)
Definition: makeopts.py:29
print
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)
Definition: vbi608extractor.cpp:29
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts
Definition: makeopts.py:28
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts.serialize
def serialize(self)
Definition: makeopts.py:49
hardwareprofile.distros.mythtv_data.makeopts.MakeOpts.get
def get(self)
Definition: makeopts.py:46