def completer(text, iteration): global repo global _last_line global _last_res global rl_completion_suppress_append if rl_completion_suppress_append is not None: rl_completion_suppress_append.value = 1 try: line = readline.get_line_buffer()[:readline.get_endidx()] if _last_line != line: _last_res = _completer_get_subs(repo, line) _last_line = line (dir, name, qtype, lastword, subs) = _last_res if iteration < len(subs): path = subs[iteration] leaf_name, leaf_item = path[-1] res = vfs.try_resolve(repo, leaf_name, parent=path[:-1]) leaf_name, leaf_item = res[-1] fullname = os.path.join(*(name for name, item in res)) if stat.S_ISDIR(vfs.item_mode(leaf_item)): ret = shquote.what_to_add(qtype, lastword, fullname+'/', terminate=False) else: ret = shquote.what_to_add(qtype, lastword, fullname, terminate=True) + ' ' return text + ret except Exception as e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) except Exception as e2: log('Error printing traceback: %s\n' % e2) log('\nError in completion: %s\n' % e)
def enter_completion(text, iteration): global repo global _attempt_end global _last_line global _last_res try: line = _helpers.get_line_buffer()[:_attempt_end] if _last_line != line: _last_res = _completer_get_subs(repo, line) _last_line = line qtype, lastword, subs = _last_res if iteration < len(subs): path = subs[iteration] leaf_name, leaf_item = path[-1] res = vfs.try_resolve(repo, leaf_name, parent=path[:-1]) leaf_name, leaf_item = res[-1] fullname = os.path.join(*(name for name, item in res)) if stat.S_ISDIR(vfs.item_mode(leaf_item)): ret = shquote.what_to_add(qtype, lastword, fullname + b'/', terminate=False) else: ret = shquote.what_to_add( qtype, lastword, fullname, terminate=True) + b' ' return text + ret except Exception as e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) except Exception as e2: log('Error printing traceback: %s\n' % e2) log('\nError in completion: %s\n' % e)
def _dir_contents(repo, resolution, show_hidden=False): """Yield the display information for the contents of dir_item.""" url_query = '?hidden=1' if show_hidden else '' def display_info(name, item, resolved_item, display_name=None): # link should be based on fully resolved type to avoid extra # HTTP redirect. if stat.S_ISDIR(vfs.item_mode(resolved_item)): link = urllib.quote(name) + '/' else: link = urllib.quote(name) size = vfs.item_size(repo, item) if opt.human_readable: display_size = format_filesize(size) else: display_size = size if not display_name: mode = vfs.item_mode(item) if stat.S_ISDIR(mode): display_name = name + '/' elif stat.S_ISLNK(mode): display_name = name + '@' else: display_name = name return display_name, link + url_query, display_size dir_item = resolution[-1][1] for name, item in vfs.contents(repo, dir_item): if not show_hidden: if (name not in ('.', '..')) and name.startswith('.'): continue if name == '.': yield display_info(name, item, item, '.') parent_item = resolution[-2][1] if len( resolution) > 1 else dir_item yield display_info('..', parent_item, parent_item, '..') continue res = vfs.try_resolve(repo, name, parent=resolution, want_meta=False) res_name, res_item = res[-1] yield display_info(name, item, res_item)
def _dir_contents(repo, resolution, show_hidden=False): """Yield the display information for the contents of dir_item.""" url_query = '?hidden=1' if show_hidden else '' def display_info(name, item, resolved_item, display_name=None): # link should be based on fully resolved type to avoid extra # HTTP redirect. if stat.S_ISDIR(vfs.item_mode(resolved_item)): link = urllib.quote(name) + '/' else: link = urllib.quote(name) size = vfs.item_size(repo, item) if opt.human_readable: display_size = format_filesize(size) else: display_size = size if not display_name: mode = vfs.item_mode(item) if stat.S_ISDIR(mode): display_name = name + '/' elif stat.S_ISLNK(mode): display_name = name + '@' else: display_name = name return display_name, link + url_query, display_size dir_item = resolution[-1][1] for name, item in vfs.contents(repo, dir_item): if not show_hidden: if (name not in ('.', '..')) and name.startswith('.'): continue if name == '.': yield display_info(name, item, item, '.') parent_item = resolution[-2][1] if len(resolution) > 1 else dir_item yield display_info('..', parent_item, parent_item, '..') continue res = vfs.try_resolve(repo, name, parent=resolution, want_meta=False) res_name, res_item = res[-1] yield display_info(name, item, res_item)
def show_paths(repo, opt, paths, out, pwd, should_columnate, prefix=b''): def item_line(item, name): return item_info(item, prefix + name, show_hash=opt.hash, commit_hash=opt.commit_hash, long_fmt=opt.long_listing, classification=opt.classification, numeric_ids=opt.numeric_ids, human_readable=opt.human_readable) ret = 0 want_meta = bool(opt.long_listing or opt.classification) pending = [] last_n = len(paths) - 1 for n, printpath in enumerate(paths): path = posixpath.join(pwd, printpath) try: if last_n > 0: out.write(b'%s:\n' % printpath) if opt.directory: resolved = vfs.resolve(repo, path, follow=False) else: resolved = vfs.try_resolve(repo, path, want_meta=want_meta) leaf_name, leaf_item = resolved[-1] if not leaf_item: log('error: cannot access %r in %r\n' % ('/'.join(path_msg(name) for name, item in resolved), path_msg(path))) ret = 1 continue if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)): items = vfs.contents(repo, leaf_item, want_meta=want_meta) if opt.show_hidden == 'all': # Match non-bup "ls -a ... /". parent = resolved[-2] if len(resolved) > 1 else resolved[0] items = chain(items, ((b'..', parent[1]), )) for sub_name, sub_item in sorted(items, key=lambda x: x[0]): if opt.show_hidden != 'all' and sub_name == b'.': continue if sub_name.startswith(b'.') and \ opt.show_hidden not in ('almost', 'all'): continue # always skip . and .. in the subfolders - already printed it anyway if prefix and sub_name in (b'.', b'..'): continue if opt.l: sub_item = vfs.ensure_item_has_metadata( repo, sub_item, include_size=True) elif want_meta: sub_item = vfs.augment_item_meta(repo, sub_item, include_size=True) line = item_line(sub_item, sub_name) if should_columnate: pending.append(line) else: out.write(line) out.write(b'\n') # recurse into subdirectories (apart from . and .., of course) if opt.recursive and S_ISDIR( vfs.item_mode(sub_item)) and sub_name not in ( b'.', b'..'): show_paths(repo, opt, [path + b'/' + sub_name], out, pwd, should_columnate, prefix=prefix + sub_name + b'/') else: if opt.long_listing: leaf_item = vfs.augment_item_meta(repo, leaf_item, include_size=True) line = item_line(leaf_item, os.path.normpath(path)) if should_columnate: pending.append(line) else: out.write(line) out.write(b'\n') except vfs.IOError as ex: log('bup: %s\n' % ex) ret = 1 if pending: out.write(columnate(pending, b'')) pending = [] if n < last_n: out.write(b'\n') return ret
def within_repo(repo, opt): if opt.commit_hash: opt.hash = True def item_line(item, name): return item_info(item, name, show_hash=opt.hash, commit_hash=opt.commit_hash, long_fmt=opt.long_listing, classification=opt.classification, numeric_ids=opt.numeric_ids, human_readable=opt.human_readable) ret = 0 pending = [] for path in opt.paths: try: if opt.directory: resolved = vfs.resolve(repo, path, follow=False) else: resolved = vfs.try_resolve(repo, path) leaf_name, leaf_item = resolved[-1] if not leaf_item: log('error: cannot access %r in %r\n' % ('/'.join(name for name, item in resolved), path)) ret = 1 continue if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)): items = vfs.contents(repo, leaf_item) if opt.show_hidden == 'all': # Match non-bup "ls -a ... /". parent = resolved[-2] if len(resolved) > 1 else resolved[0] items = chain(items, (('..', parent[1]),)) for sub_name, sub_item in sorted(items, key=lambda x: x[0]): if opt.show_hidden != 'all' and sub_name == '.': continue if sub_name.startswith('.') and \ opt.show_hidden not in ('almost', 'all'): continue if opt.l: sub_item = vfs.ensure_item_has_metadata(repo, sub_item, include_size=True) else: sub_item = vfs.augment_item_meta(repo, sub_item, include_size=True) line = item_line(sub_item, sub_name) if not opt.long_listing and istty1: pending.append(line) else: print(line) else: leaf_item = vfs.augment_item_meta(repo, leaf_item, include_size=True) line = item_line(leaf_item, os.path.normpath(path)) if not opt.long_listing and istty1: pending.append(line) else: print(line) except vfs.IOError as ex: log('bup: %s\n' % ex) ret = 1 if pending: sys.stdout.write(columnate(pending, '')) return ret
def _dir_contents(repo, resolution, args): """Yield the display information for the contents of dir_item.""" def display_info(name, item, resolved_item, display_name=None, omitsize=False): # link should be based on fully resolved type to avoid extra # HTTP redirect. link = tornado.escape.url_escape(name, plus=False) if stat.S_ISDIR(vfs.item_mode(resolved_item)): link += '/' link = link.encode('ascii') if not omitsize: size = vfs.item_size(repo, item) if args.hsizes: display_size = format_filesize(size) else: display_size = size else: display_size = None if not display_name: mode = vfs.item_mode(item) if stat.S_ISDIR(mode): display_name = name + b'/' display_size = None elif stat.S_ISLNK(mode): display_name = name + b'@' display_size = None else: display_name = name meta = resolved_item.meta if not isinstance(meta, Metadata): meta = None try: oidx = hexlify(resolved_item.oid) except AttributeError: oidx = '' return display_name, link + args, display_size, meta, oidx dir_item = resolution[-1][1] for name, item in vfs.contents(repo, dir_item): if not args.hidden: if (name not in (b'.', b'..')) and name.startswith(b'.'): continue if name == b'.': if len(resolution) > 1: parent_item = resolution[-2][1] if len( resolution) > 1 else dir_item yield display_info(b'..', parent_item, parent_item, b'..', omitsize=True) continue res = vfs.try_resolve(repo, name, parent=resolution, want_meta=args.meta) res_name, res_item = res[-1] yield display_info(name, item, res_item)
def within_repo(repo, opt): if opt.commit_hash: opt.hash = True def item_line(item, name): return item_info(item, name, show_hash=opt.hash, commit_hash=opt.commit_hash, long_fmt=opt.long_listing, classification=opt.classification, numeric_ids=opt.numeric_ids, human_readable=opt.human_readable) ret = 0 pending = [] for path in opt.paths: try: if opt.directory: resolved = vfs.resolve(repo, path, follow=False) else: resolved = vfs.try_resolve(repo, path) leaf_name, leaf_item = resolved[-1] if not leaf_item: log('error: cannot access %r in %r\n' % ('/'.join(name for name, item in resolved), path)) ret = 1 continue if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)): items = vfs.contents(repo, leaf_item) if opt.show_hidden == 'all': # Match non-bup "ls -a ... /". parent = resolved[-2] if len(resolved) > 1 else resolved[0] items = chain(items, (('..', parent[1]), )) for sub_name, sub_item in sorted(items, key=lambda x: x[0]): if opt.show_hidden != 'all' and sub_name == '.': continue if sub_name.startswith('.') and \ opt.show_hidden not in ('almost', 'all'): continue if opt.l: sub_item = vfs.ensure_item_has_metadata( repo, sub_item, include_size=True) else: sub_item = vfs.augment_item_meta(repo, sub_item, include_size=True) line = item_line(sub_item, sub_name) if not opt.long_listing and istty1: pending.append(line) else: print(line) else: leaf_item = vfs.augment_item_meta(repo, leaf_item, include_size=True) line = item_line(leaf_item, os.path.normpath(path)) if not opt.long_listing and istty1: pending.append(line) else: print(line) except vfs.IOError as ex: log('bup: %s\n' % ex) ret = 1 if pending: sys.stdout.write(columnate(pending, '')) return ret