]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/ls.py
Support remote listings: bup ls -r ...
[bup.git] / lib / bup / ls.py
index 4c4d614d37bceaaa5f0b2d69e02895dbd3b077d0..8968d1fddfaca62b091d7af29f5695b7ec4c6ef3 100644 (file)
@@ -6,7 +6,7 @@ from stat import S_ISDIR, S_ISLNK
 import copy, locale, os.path, stat, sys, xstat
 
 from bup import metadata, options, vfs2 as vfs
-from bup.repo import LocalRepo
+from bup.repo import LocalRepo, RemoteRepo
 from helpers import columnate, istty1, last, log
 
 def item_hash(item, tree_for_commit):
@@ -45,14 +45,15 @@ def item_info(item, name,
     else:
         result += name
         if classification:
-            result += xstat.classification_str(item.meta.mode,
+            result += xstat.classification_str(vfs.item_mode(item),
                                                classification == 'all')
     return result
 
 
 optspec = """
-%sls [-a] [path...]
+%sls [-r host:path] [-l] [-d] [-F] [-a] [-A] [-s] [-n] [path...]
 --
+r,remote=   remote repository path
 s,hash   show hash for each file
 commit-hash show commit hash instead of tree for commits (implies -s)
 a,all    show hidden files
@@ -106,7 +107,7 @@ def do_ls(args, default='.', onabort=None, spec_prefix=''):
                          numeric_ids = opt.numeric_ids,
                          human_readable = opt.human_readable)
 
-    repo = LocalRepo()
+    repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo()
     ret = 0
     pending = []
     for path in (extra or [default]):
@@ -114,8 +115,7 @@ def do_ls(args, default='.', onabort=None, spec_prefix=''):
             if opt.directory:
                 resolved = vfs.lresolve(repo, path)
             else:
-                # FIXME: deal with invalid symlinks i.e. old vfs try_resolve
-                resolved = vfs.resolve(repo, path)
+                resolved = vfs.try_resolve(repo, path)
 
             leaf_name, leaf_item = resolved[-1]
             if not leaf_item:
@@ -130,16 +130,18 @@ def do_ls(args, default='.', onabort=None, spec_prefix=''):
                     # Match non-bup "ls -a ... /".
                     parent = resolved[-2] if len(resolved) > 1 else resolved[0]
                     items = chain(items, (('..', parent[1]),))
-
-                items = ((x[0], vfs.augment_item_meta(repo, x[1],
-                                                      include_size=True))
-                         for x in items)
                 for sub_name, sub_item in sorted(items, key=lambda x: x[0]):
                     if show_hidden != 'all' and sub_name == '.':
                         continue
                     if sub_name.startswith('.') and \
                        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)
                     pending.append(line) if not opt.l and istty1 else print(line)
             else: