/usr/share/pyshared/plasTeX/ConfigManager/Counted.py is in python-plastex 0.9.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 62 63 64 | from Generic import GenericArgument
from Boolean import BooleanOption
from plasTeX.ConfigManager import InvalidOptionError, COMMANDLINE
class CountedOption(BooleanOption):
"""
Counted configuration option
This option is just like a boolean option except that the value
of the option is the number of times that the option has been
specified. This is commonly used to set a verbosity or debugging
level.
"""
def cast(self, data):
if data is None: return
values = {'on':1,'off':0,'true':1,'false':0,'yes':1,'no':0}
# If this is from the command-line, increment or decrement
if self.source & COMMANDLINE:
initdata = self.data
if self.data is None:
initdata = 0
if data:
return max(0, initdata + 1)
else:
return max(0, initdata - 1)
# If this is from any other source, set explicitly
try:
return max(0,int(data))
except:
try: return values[str(data).lower()]
except: pass
name = self.name
if self.actual: name = self.actual
raise InvalidOptionError(name, data, type='counted')
def __str__(self):
""" Return string representation of the current option value """
value = self.getValue()
if value == 1:
return 'on'
elif value == 0:
return 'off'
return str(value)
def __repr__(self):
""" Return command-line syntax as entered """
if self.actual: return self.actual
options = self.getPossibleOptions()
negative = [x.replace('!','',1) for x in options if x.startswith('!')]
positive = [x for x in options if not x.startswith('!')]
if self.data and positive:
return ' '.join(self.data*[positive[0]])
elif not(self.data) and negative:
return negative[0]
return ''
class CountedArgument(GenericArgument, CountedOption):
""" Counted command-line argument """
|