Main._print -> Main.print, removed deprecated things
This commit is contained in:
parent
b29823c322
commit
57f4315c9a
1 changed files with 20 additions and 46 deletions
66
core/app.py
66
core/app.py
|
@ -197,10 +197,10 @@ class CfgAccessor:
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
return matches[0].value
|
return matches[0].value
|
||||||
else:
|
else:
|
||||||
self.main._print('game over, lights out! over.core internal buggaroo', prefix.fail)
|
self.main.print('game over, lights out! over.core internal buggaroo', prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
else:
|
else:
|
||||||
self.main._print('option §r%s§/ doesn\'t exist' %(opt_name), prefix.fail)
|
self.main.print('option §r%s§/ doesn\'t exist' %(opt_name), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
@ -235,7 +235,7 @@ class Main:
|
||||||
self.license = license
|
self.license = license
|
||||||
self.cmdline = cmdline
|
self.cmdline = cmdline
|
||||||
self.help_texts = [] # (chapter, [paragraphs])
|
self.help_texts = [] # (chapter, [paragraphs])
|
||||||
self._print = text.Output('over.core.app.Main')
|
self.print = text.Output(self.name + '.main')
|
||||||
|
|
||||||
self.data_dir = os.path.join(xdg.BaseDirectory.xdg_data_home, self.name)
|
self.data_dir = os.path.join(xdg.BaseDirectory.xdg_data_home, self.name)
|
||||||
file.File(os.path.join(self.data_dir, '.keep'))
|
file.File(os.path.join(self.data_dir, '.keep'))
|
||||||
|
@ -261,7 +261,7 @@ class Main:
|
||||||
|
|
||||||
''' %(self.name, self.license)
|
''' %(self.name, self.license)
|
||||||
|
|
||||||
self._print('creating configuration file §B%s§/' %(self.cfg_file.path), prefix.start)
|
self.print('creating configuration file §B%s§/' %(self.cfg_file.path), prefix.start)
|
||||||
else:
|
else:
|
||||||
self.cfg_file = None
|
self.cfg_file = None
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ class Main:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'over.Main(name=%s)' %(self.name)
|
return 'over.Main(name=%s)' %(self.name)
|
||||||
|
|
||||||
def exit(self, retval=0, silent=False):
|
def exit(self, retval=0, silent=True):
|
||||||
'''
|
'''
|
||||||
int retval return value
|
int retval return value
|
||||||
bool silent don't mention it
|
bool silent don't mention it
|
||||||
|
@ -284,7 +284,7 @@ class Main:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
self._print('exiting with §B%d§/' %(retval), prefix.info)
|
self.print('exiting with §B%d§/' %(retval), prefix.info)
|
||||||
|
|
||||||
sys.exit(retval)
|
sys.exit(retval)
|
||||||
|
|
||||||
|
@ -386,22 +386,22 @@ class Main:
|
||||||
|
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
if name == option.name:
|
if name == option.name:
|
||||||
self._print('option §B--§r%s§/ already exists' %(name), prefix.fail)
|
self.print('option §B--§r%s§/ already exists' %(name), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if option.short_name and short_name == option.short_name:
|
if option.short_name and short_name == option.short_name:
|
||||||
self._print('option §B--§r%s§/\'s short name §r%s§/ is already taken by §B--§y%s§/' %(name, short_name, option.name), prefix.fail)
|
self.print('option §B--§r%s§/\'s short name §r%s§/ is already taken by §B--§y%s§/' %(name, short_name, option.name), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if short_name and len(short_name) > 1:
|
if short_name and len(short_name) > 1:
|
||||||
self._print('short name must be a single character; option §B--§r%s§/ has §r%s§/'%(name, short_name), prefix.fail)
|
self.print('short name must be a single character; option §B--§r%s§/ has §r%s§/'%(name, short_name), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
use_cfg_file = False
|
use_cfg_file = False
|
||||||
|
|
||||||
if dtype not in ['bool', 'str', 'int', 'float']:
|
if dtype not in ['bool', 'str', 'int', 'float']:
|
||||||
self._print('option §B--§r%s§/\'s dtype is not of a supported type' %(name), prefix.fail)
|
self.print('option §B--§r%s§/\'s dtype is not of a supported type' %(name), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
v = _verify_type(default, dtype, plural)
|
v = _verify_type(default, dtype, plural)
|
||||||
|
@ -415,7 +415,7 @@ class Main:
|
||||||
else:
|
else:
|
||||||
type_desc = 'a %s' %(dtype)
|
type_desc = 'a %s' %(dtype)
|
||||||
|
|
||||||
self._print('option §B--§r%s§/\'s default must be §y%s§/' %(name, type_desc), prefix.fail)
|
self.print('option §B--§r%s§/\'s default must be §y%s§/' %(name, type_desc), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
o = Option(name, dtype, default, description, short_name, plural, use_cfg_file, callback, hidden)
|
o = Option(name, dtype, default, description, short_name, plural, use_cfg_file, callback, hidden)
|
||||||
|
@ -489,14 +489,14 @@ class Main:
|
||||||
o.value = bool_on
|
o.value = bool_on
|
||||||
else:
|
else:
|
||||||
if not bool_on:
|
if not bool_on:
|
||||||
self._print('§B--no-§r%s§/ makes no sense because this option is of type §y%s§/' %(name, o.dtype), prefix.fail)
|
self.print('§B--no-§r%s§/ makes no sense because this option is of type §y%s§/' %(name, o.dtype), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
# This option takes arguments. These are all words at ptr and higher that don't begin with '--'.
|
# This option takes arguments. These are all words at ptr and higher that don't begin with '--'.
|
||||||
# If this option is part of a shortgroup it must be at its end.
|
# If this option is part of a shortgroup it must be at its end.
|
||||||
|
|
||||||
if to_parse.index(w) + 1 != len(to_parse):
|
if to_parse.index(w) + 1 != len(to_parse):
|
||||||
self._print('option §B{0[0]}§r{1.short_name}§/ needs to be at the end of group §y{0}§/'.format(word, o), prefix.fail)
|
self.print('option §B{0[0]}§r{1.short_name}§/ needs to be at the end of group §y{0}§/'.format(word, o), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
got_something = False
|
got_something = False
|
||||||
|
@ -511,13 +511,13 @@ class Main:
|
||||||
try:
|
try:
|
||||||
arg = int(arg)
|
arg = int(arg)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._print('argument §r%s§/ passed to integer option §B--§y%s§/' %(arg, o.name), prefix.fail, exc=ValueError)
|
self.print('argument §r%s§/ passed to integer option §B--§y%s§/' %(arg, o.name), prefix.fail, exc=ValueError)
|
||||||
|
|
||||||
elif o.dtype == 'float':
|
elif o.dtype == 'float':
|
||||||
try:
|
try:
|
||||||
arg = float(arg)
|
arg = float(arg)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._print('argument §r%s§/ passed to float option §B--§y%s§/' %(arg, o.name), prefix.fail, exc=ValueError)
|
self.print('argument §r%s§/ passed to float option §B--§y%s§/' %(arg, o.name), prefix.fail, exc=ValueError)
|
||||||
|
|
||||||
got_something = True
|
got_something = True
|
||||||
o.source = 'cmdline'
|
o.source = 'cmdline'
|
||||||
|
@ -529,7 +529,7 @@ class Main:
|
||||||
break
|
break
|
||||||
|
|
||||||
#if not got_something:
|
#if not got_something:
|
||||||
# self._print('option §B--§r%s§/ needs at least one argument' %(o.name), prefix.fail, exc=GeneralError)
|
# self.print('option §B--§r%s§/ needs at least one argument' %(o.name), prefix.fail, exc=GeneralError)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.unknowns.append(w)
|
self.unknowns.append(w)
|
||||||
|
@ -537,7 +537,7 @@ class Main:
|
||||||
self.targets = [u for u in unparsed if u != '--']
|
self.targets = [u for u in unparsed if u != '--']
|
||||||
|
|
||||||
if self.unknowns:
|
if self.unknowns:
|
||||||
self._print('unknown options on the command line: §r%s§/' %('§/, §r'.join(self.unknowns)), prefix.fail)
|
self.print('unknown options on the command line: §r%s§/' %('§/, §r'.join(self.unknowns)), prefix.fail)
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
# parse the config file
|
# parse the config file
|
||||||
|
@ -568,18 +568,18 @@ class Main:
|
||||||
try:
|
try:
|
||||||
opt.value.append(_parse(element, opt.dtype))
|
opt.value.append(_parse(element, opt.dtype))
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
self._print('config file syntax error for option §B--§r%s§/' %(opt.name), prefix.fail)
|
self.print('config file syntax error for option §B--§r%s§/' %(opt.name), prefix.fail)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
opt.value = _parse(d, opt.dtype)
|
opt.value = _parse(d, opt.dtype)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
self._print('config file syntax error for option §B--§r%s§/' %(opt.name), prefix.fail)
|
self.print('config file syntax error for option §B--§r%s§/' %(opt.name), prefix.fail)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._print('updating config file with option §B--§y%s§/' %(opt.name))
|
self.print('updating config file with option §B--§y%s§/' %(opt.name))
|
||||||
new_lines.append('')
|
new_lines.append('')
|
||||||
new_lines.append(text.paragraph(text.render(opt.description, colors=False), prefix='#', width=80))
|
new_lines.append(text.paragraph(text.render(opt.description, colors=False), prefix='#', width=80))
|
||||||
new_lines.append('# *** data type: %s' %(opt.dtype))
|
new_lines.append('# *** data type: %s' %(opt.dtype))
|
||||||
|
@ -609,32 +609,6 @@ class Main:
|
||||||
for callback in callbacks:
|
for callback in callbacks:
|
||||||
callback(self)
|
callback(self)
|
||||||
|
|
||||||
def dump_cfg(self):
|
|
||||||
'''
|
|
||||||
Print a summary of the current cfg state.
|
|
||||||
|
|
||||||
DEPRECATED by --help
|
|
||||||
'''
|
|
||||||
|
|
||||||
self._print('state dump', prefix.start)
|
|
||||||
|
|
||||||
for opt in self.options:
|
|
||||||
if opt.source == 'cmdline':
|
|
||||||
src = '§mcmdline§/'
|
|
||||||
elif opt.source == 'config':
|
|
||||||
src = '§yconfig§/'
|
|
||||||
else:
|
|
||||||
src = 'default'
|
|
||||||
|
|
||||||
if opt.plural:
|
|
||||||
self._print('--§g%s§/ (%s): §b%s§/' %(opt.name, src, '§/, §b'.join(str(x) for x in opt.value)))
|
|
||||||
else:
|
|
||||||
self._print('--§g%s§/ (%s): §b%s§/' %(opt.name, src, opt.value))
|
|
||||||
|
|
||||||
self._print('Targets: §B%s§/' %('§/, §B'.join(self.targets)))
|
|
||||||
|
|
||||||
self._print('state dump', prefix.done)
|
|
||||||
|
|
||||||
def enable_help(self, short_name=None):
|
def enable_help(self, short_name=None):
|
||||||
'''
|
'''
|
||||||
Enable --help, --over-help and --help-over. If a short name is provided, it will be used for --help.
|
Enable --help, --over-help and --help-over. If a short name is provided, it will be used for --help.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue