def execute(self, cmd, response='pickle'): """\ Execute a command. @param cmd: The command string to execute. @type cmd: C{str} @param response: Response format for client (see commands.py). @type response: C{str} @return: The return string of the command. @rtype: C{str} """ cmd, args = cmd.split()[0], cmd.split()[1:] if cmd not in commands.commands: raise commands.CommandError('invalid command') try: return commands.commands[cmd](self, args, response=response) except commands.CommandError as e: es = str(e) if commands.commands[cmd].__doc__: for line in commands.commands[cmd].__doc__.split('\n'): line = line.strip(' ') if line.startswith('usage'): es += '\n' + line % cmd break raise commands.CommandError(es)
def cmd_activate(self, args): if args: if len(args.split()) > 1: raise commands.CommandError( "Too many arguments, only one needed") try: pos = int(args) - 1 if pos < 0 or pos > len(self.body): raise ValueError except ValueError: raise commands.CommandError("valid playlist position required") else: pos = self.get_focus()[1] if pos is not None: self.xs.playlist_play(playlist=self.view_pls, pos=pos)
def diagnose_build_ext_error(build_ext, error, formatted): diagnostic = _ERROR_DIAGNOSES.get(type(error)) if diagnostic is None: raise commands.CommandError( "\n\nWe could not diagnose your build failure. Please file an issue at " "http://www.github.com/grpc/grpc with `[Python install]` in the title." "\n\n{}".format(formatted)) else: diagnostic(build_ext, error)
def diagnose_compile_error(build_ext, error): """Attempt to run a few test files through the compiler to see if we can diagnose the reason for the compile failure.""" for c_check, message in C_CHECKS.items(): _expect_compile(build_ext.compiler, c_check, message) raise commands.CommandError( "\n\nWe could not diagnose your build failure. Please file an issue at " "http://www.github.com/grpc/grpc with `[Python install]` in the title." )
def diagnose_build_ext_error(build_ext, error, formatted): diagnostic = _ERROR_DIAGNOSES.get(type(error)) if diagnostic is None: raise commands.CommandError( "\n\nWe could not diagnose your build failure. If you are unable to " "proceed, please file an issue at http://www.github.com/grpc/grpc " "with `[Python install]` in the title; please attach the whole log " "(including everything that may have appeared above the Python " "backtrace).\n\n{}".format(formatted)) else: diagnostic(build_ext, error)
def cmd_tab(self, args): if not args: raise commands.CommandError("need an argument") arg = args.strip() try: n = int(arg) self.load_tab(n - 1) return except ValueError: pass if arg == 'next': self.load_tab(self.cur_tab + 1, wrap=True) elif arg == 'prev': self.load_tab(self.cur_tab - 1, wrap=True) elif arg == 'lastfocus': pass # TODO else: raise commands.CommandError("not a valid argument: %s" % arg)
def cmd_toggle(self, args): if args: try: pos = int(args) if pos < 0 or pos >= len(self.body): raise ValueError except ValueError: raise commands.CommandError("valid playlist position required") else: w, pos = self.get_focus() if pos is not None: self.toggle_mark(pos, self.get_mark_data(pos, w))
def diagnose_compile_error(build_ext, error): """Attempt to diagnose an error during compilation.""" for c_check, message in C_CHECKS.items(): _expect_compile(build_ext.compiler, c_check, message) python_sources = [ source for source in build_ext.get_source_files() if source.startswith('./src/python') and source.endswith('c') ] for source in python_sources: if not os.path.isfile(source): raise commands.CommandError(( "Diagnostics found a missing Python extension source file:\n{}\n\n" "This is usually because the Cython sources haven't been transpiled " "into C yet and you're building from source.\n" "Try setting the environment variable " "`GRPC_PYTHON_BUILD_WITH_CYTHON=1` when invoking `setup.py` or " "when using `pip`, e.g.:\n\n" "pip install -rrequirements.txt\n" "GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .").format(source))
def insert_by_field(self, field, pos=None): w, p = self.get_focus() if w is None: return info = self.xs.medialib_get_info(w.mid) if field not in info: raise commands.CommandError( "the song doesn't have a value for '%s'" % field) c = coll.Equals(field=field, value=info[field].encode('utf-8')) if pos is None: self.xs.playlist_add_collection(c, ['id'], sync=False) else: self.xs.playlist_insert_collection(int(pos), c, ['id'], sync=False) pos_s = pos is not None and "at position %d" % (pos + 1) or '' msg = 'added songs matching %s="%s" to playlist %s' % ( field, info[field], pos_s) signals.emit('show-message', msg)
def _expect_compile(compiler, source_string, error_message): if _compile(compiler, source_string) is not None: sys.stderr.write(error_message) raise commands.CommandError( "Diagnostics found a compilation environment issue:\n{}".format( error_message))
def diagnose_attribute_error(build_ext, error): if any('_needs_stub' in arg for arg in error.args): raise commands.CommandError( "We expect a missing `_needs_stub` attribute from older versions of " "setuptools. Consider upgrading setuptools.")