From 57f4315c9a572ef0f5e5b418d4b01fe82b27dc91 Mon Sep 17 00:00:00 2001 From: Martinez Date: Sun, 15 Mar 2015 21:46:39 +0100 Subject: [PATCH] Main._print -> Main.print, removed deprecated things --- core/app.py | 66 ++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/core/app.py b/core/app.py index 5aea227..bd9f6b2 100644 --- a/core/app.py +++ b/core/app.py @@ -197,10 +197,10 @@ class CfgAccessor: if len(matches) == 1: return matches[0].value 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 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 # -------------------------------------------------- @@ -235,7 +235,7 @@ class Main: self.license = license self.cmdline = cmdline 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) file.File(os.path.join(self.data_dir, '.keep')) @@ -261,7 +261,7 @@ class Main: ''' %(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: self.cfg_file = None @@ -275,7 +275,7 @@ class Main: def __repr__(self): 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 bool silent don't mention it @@ -284,7 +284,7 @@ class Main: ''' if not silent: - self._print('exiting with §B%d§/' %(retval), prefix.info) + self.print('exiting with §B%d§/' %(retval), prefix.info) sys.exit(retval) @@ -386,22 +386,22 @@ class Main: for option in self.options: 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 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 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 if callback: use_cfg_file = False 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 v = _verify_type(default, dtype, plural) @@ -415,7 +415,7 @@ class Main: else: 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 o = Option(name, dtype, default, description, short_name, plural, use_cfg_file, callback, hidden) @@ -489,14 +489,14 @@ class Main: o.value = bool_on else: 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 # 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 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 got_something = False @@ -511,13 +511,13 @@ class Main: try: arg = int(arg) 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': try: arg = float(arg) 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 o.source = 'cmdline' @@ -529,7 +529,7 @@ class Main: break #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: self.unknowns.append(w) @@ -537,7 +537,7 @@ class Main: self.targets = [u for u in unparsed if u != '--'] 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 # parse the config file @@ -568,18 +568,18 @@ class Main: try: opt.value.append(_parse(element, opt.dtype)) 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 else: try: opt.value = _parse(d, opt.dtype) 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 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(text.paragraph(text.render(opt.description, colors=False), prefix='#', width=80)) new_lines.append('# *** data type: %s' %(opt.dtype)) @@ -609,32 +609,6 @@ class Main: for callback in callbacks: 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): ''' Enable --help, --over-help and --help-over. If a short name is provided, it will be used for --help.