def join_keys(self, command_only=True, load=True): words = [] for key, entry in self._registry.items(): load and entry.resolve_function() if (not command_only) or entry.function: words.append(key) return Join.join_words(words)
def usage(): result = ['Valid commands are:', REGISTRY.join_keys()] aliases = Aliases.instance() if aliases: result.append('\nand aliases are:') result.append(Join.join_words(aliases)) return ' '.join(result)
def usage(): result = ['Valid commands are:', Registry.registry().join_keys()] aliases = Aliases.instance() if aliases: result.append('\nand aliases are:') result.append(Join.join_words(aliases)) return ' '.join(result)
def save(log=True): if get('execution', 'autosave'): files = MERGE_SETTINGS.save() if log and files: print('Settings automatically saved to', Join.join_file_names(files)) return files
def save(log=True): if get('execution', 'autosave'): files = MERGE_SETTINGS.save() if log and files: print( 'Settings automatically saved to', Join.join_file_names(files)) return files
def save(_, *values): if values: SetConfig.set_config(_, *values) files = Config.save(False) if files: LOGGER.info('Configuration saved to %s.', Join.join_file_names(files)) else: LOGGER.error('There are no configuration changes to save.')
def save(_, *values): if values: SetSettings.set_settings(_, *values) files = Settings.save(False) if files: LOGGER.info('Settings saved to %s.', Join.join_file_names(files)) else: LOGGER.error('There are no settings changes to save.')
def not_accessed(logger, element, not_accessed_items, element_type): if not_accessed_items: score = element.get_root().get_property('score') or '' if len(not_accessed_items) == 1: err = _NOT_ACCESSED_ERROR_SINGLE else: err = _NOT_ACCESSED_ERROR logger.error( err, element_type, score, Join.join_words(not_accessed_items))
def not_accessed(logger, element, not_accessed_items, element_type): if not_accessed_items: score = element.get_root().get_property('score') or '' if len(not_accessed_items) == 1: err = _NOT_ACCESSED_ERROR_SINGLE else: err = _NOT_ACCESSED_ERROR logger.error(err, element_type, score, Join.join_words(not_accessed_items))
def help(self): help = self.help_text if self.name == 'commands': # HACK. help += self.registry.join_keys() help = help or self.name if self.see_also: also = Join.join_words('"help %s"' % h for h in self.see_also) help = '%s\n\nSee also: %s\n' % (help, also) return help
def get_help(self, name): full_name, (_, help_text, see_also) = self._get(name) if full_name == 'commands': # HACK. help_text += self.join_keys() help_text = help_text or full_name if see_also: also = Join.join_words('"help %s"' % h for h in see_also) return '%s\n\nSee also: %s\n' % (help_text, also) else: return help_text
def get_prefix(table, name, allow_prefixes=True): """ Looks up an entry in a table where unique prefixes are allowed. """ result = table.get(name, _NONE) if result is not _NONE: return name, result if allow_prefixes: results = [(k, v) for (k, v) in table.iteritems() if k.startswith(name)] if len(results) == 1: return results[0] elif len(results) > 1: words = sorted(x[0] for x in results) cmds = Join.join_words(words) raise PrefixException('"%s" matches more than one: %s.' % (name, cmds)) raise PrefixException('"%s" is not valid.' % (name))
def get_prefix(table, key, allow_prefixes=True, exception_prefix=''): """ Looks up an entry in a table where unique prefixes are allowed. """ result = table.get(key, _NONE) if result is not _NONE: return key, result if allow_prefixes: results = [(k, v) for (k, v) in six.iteritems(table) if k.startswith(key)] if len(results) == 1: return results[0] elif len(results) > 1: words = sorted(x[0] for x in results) cmds = Join.join_words(words) raise PrefixException(key, exception_prefix, '"%s" matches more than one:' % key, cmds) raise PrefixException(key, exception_prefix, '"%s" is not valid' % key)
def make_one(parent, description): description = Dict.Access(_resolve_extensions(description)) t = description.get('type', '').lower() if not t: raise Exception('No type field in element %s' % description) element_class = _REGISTRY.get(t) if not element_class: _REGISTRY.dump() raise Exception('No element class for type %s' % t) element = element_class(parent, description) not_accessed = description.not_accessed() if not_accessed: score = element.get_root().get_property('score') or '' if len(not_accessed) == 1: error = NOT_ACCESSED_ERROR_SINGLE else: error = NOT_ACCESSED_ERROR LOGGER.error(error, t, score, Join.join_words(not_accessed)) return element
def get_settings(_, *items): failures = [] if items: successes = [] for i in items: parts = i.split('.') try: value = Settings.get(*parts) except: failures.append(i) else: successes.append([i, value]) else: assignments = Settings.assignments().items() successes = [('.'.join(s), v) for s, v in assignments] if successes or failures: for value, result in successes: LOGGER.info('%s=%s', value, result) if failures: LOGGER.error('Didn\'t understand %s', Join.join_words(failures)) LOGGER.info('') else: LOGGER.info('No settings variables have been set.\n')
def test_three(self): self.assertEqual(Join.join_words(['apples', 'oranges', 'pears']), 'apples, oranges, and pears')
def test_two(self): self.assertEqual(Join.join_words(['hello', 'goodbye']), 'goodbye and hello')
def _perform(action, echomesh_instance, parts): names = echomesh_instance.score_master.perform(action, parts) if names: LOGGER.info('%s %s.', action.capitalize(), Join.join_words(names)) else: LOGGER.error('%s: no results.', action)
def test_empty(self): self.assertEqual(Join.join_words([]), '')
def join_keys(self, command_only=True): w = (k for (k, v) in self.registry.iteritems() if (not command_only) or v[0]) return Join.join_words(w)
def test_one(self): self.assertEqual(Join.join_words(['hello']), 'hello')
def save(log=True): if get('autosave'): files = _MERGE_CONFIG.save() if log and files: print('Configuration automatically saved to', Join.join_file_names(files)) return files
def keys(self): return self._registry.keys() return Join.join_words(words)