def run_safe(self, command, *args): name, cmd = self._get(command) if not (ARGS.yes or cmd.safe): confirm = raw_input('OK to execute "rl %s %s"? (y/N) ' % (name, ' '.join(args))) if not confirm.lower().startswith('y'): Log.error('Cancelled.') return cmd.function(*args)
def get_ledger(self, name, is_full=False): cmd = ['ledger', str(name)] if is_full: cmd.append('full') response = self._command(*cmd) result = response.get('ledger') if result: return result error = response['error'] etext = _ERROR_TEXT.get(error) if etext: error = '%s (%s)' % (etext, error) Log.fatal(_ERROR_TEXT.get(error, error))
def search(server): """Yields a stream of ledger numbers that match the given condition.""" condition = lambda number: ARGS.condition(server, number) ledgers = server.ledgers if ARGS.binary: try: position = Search.FIRST if ARGS.position == 'first' else Search.LAST yield Search.binary_search(ledgers[0], ledgers[-1], condition, position) except: Log.fatal('No ledgers matching condition "%s".' % condition, file=sys.stderr) else: for x in Search.linear_search(ledgers, condition): yield x
def search(server): """Yields a stream of ledger numbers that match the given condition.""" condition = lambda number: ARGS.condition(server, number) ledgers = server.ledgers if ARGS.binary: try: position = Search.FIRST if ARGS.position == 'first' else Search.LAST yield Search.binary_search( ledgers[0], ledgers[-1], condition, position) except: Log.fatal('No ledgers matching condition "%s".' % condition, file=sys.stderr) else: for x in Search.linear_search(ledgers, condition): yield x
def cache(server, clear=False): cache = server.cache(ARGS.full) name = ['summary', 'full'][ARGS.full] files = cache.file_count() if not files: Log.error('No files in %s cache.' % name) elif clear: if not clear.strip() == 'clear': raise Exception("Don't understand 'clear %s'." % clear) if not ARGS.yes: yes = raw_input('OK to clear %s cache? (y/N) ' % name) if not yes.lower().startswith('y'): Log.out('Cancelled.') return cache.clear(ARGS.full) Log.out('%s cache cleared - %d file%s deleted.' % (name.capitalize(), files, '' if files == 1 else 's')) else: caches = (int(c) for c in cache.cache_list()) Log.out(Range.to_string(caches))
Log.VERBOSE = ARGS.verbose # Now remove any items that look like ledger numbers from the command line. _command = ARGS.command _parts = (ARGS.command, ARGS.ledgers) = ([], []) for c in _command: _parts[Range.is_range(c, *LedgerNumber.LEDGERS)].append(c) ARGS.command = ARGS.command or ['print' if ARGS.ledgers else 'info'] ARGS.cache = File.normalize(ARGS.cache) if not ARGS.ledgers: if ARGS.condition: Log.warn('--condition needs a range of ledgers') if ARGS.display: Log.warn('--display needs a range of ledgers') ARGS.condition = Function(ARGS.condition or 'all_ledgers', 'ripple.ledger.conditions') ARGS.display = Function(ARGS.display or 'ledger_number', 'ripple.ledger.displays') if ARGS.window < 0: raise ValueError('Window cannot be negative: --window=%d' % ARGS.window) PrettyPrint.INDENT = (ARGS.indent * ' ') _loaders = (ARGS.database != NONE) + bool(ARGS.rippled) + bool(ARGS.server)
Log.VERBOSE = ARGS.verbose # Now remove any items that look like ledger numbers from the command line. _command = ARGS.command _parts = (ARGS.command, ARGS.ledgers) = ([], []) for c in _command: _parts[Range.is_range(c, *LedgerNumber.LEDGERS)].append(c) ARGS.command = ARGS.command or ['print' if ARGS.ledgers else 'info'] ARGS.cache = File.normalize(ARGS.cache) if not ARGS.ledgers: if ARGS.condition: Log.warn('--condition needs a range of ledgers') if ARGS.display: Log.warn('--display needs a range of ledgers') ARGS.condition = Function( ARGS.condition or 'all_ledgers', 'ripple.ledger.conditions') ARGS.display = Function( ARGS.display or 'ledger_number', 'ripple.ledger.displays') if ARGS.window < 0: raise ValueError('Window cannot be negative: --window=%d' % ARGS.window) PrettyPrint.INDENT = (ARGS.indent * ' ') _loaders = (ARGS.database != NONE) + bool(ARGS.rippled) + bool(ARGS.server)
def info(server): Log.out('first =', server.first) Log.out('last =', server.last) Log.out('closed =', server.closed) Log.out('current =', server.current) Log.out('validated =', server.validated) Log.out('complete =', Range.to_string(server.complete)) if ARGS.full: Log.out(pretty_print(server.info()))
def info(server): Log.out('first = ', server.first) Log.out('last = ', server.last) Log.out('closed =', server.closed) Log.out('current =', server.current) Log.out('validated =', server.validated) Log.out('complete =', Range.to_string(server.complete)) if ARGS.full: Log.out(pretty_print(server.info()))