+ nodedir = options["node-directory"]
+ with open(os.path.join(nodedir, u"private", u"magic_folder_dircap")) as f:
+ dmd_cap = f.read().strip()
+ with open(os.path.join(nodedir, u"private", u"collective_dircap")) as f:
+ collective_readcap = f.read().strip()
+
+ try:
+ captype, dmd = _get_json_for_cap(options, dmd_cap)
+ if captype != 'dirnode':
+ print >>stderr, "magic_folder_dircap isn't a directory capability"
+ return 2
+ except RuntimeError as e:
+ print >>stderr, str(e)
+ return 1
+
+ now = datetime.now()
+
+ print "Local files:"
+ for (name, child) in dmd['children'].items():
+ captype, meta = child
+ status = 'good'
+ size = meta['size']
+ created = datetime.fromtimestamp(meta['metadata']['tahoe']['linkcrtime'])
+ version = meta['metadata']['version']
+ nice_size = humanize.naturalsize(size)
+ nice_created = humanize.naturaltime(now - created)
+ if captype != 'filenode':
+ print "%20s: error, should be a filecap" % name
+ continue
+ print " %s (%s): %s, version=%s, created %s" % (name, nice_size, status, version, nice_created)
+
+ captype, collective = _get_json_for_cap(options, collective_readcap)
+ print
+ print "Remote files:"
+ for (name, data) in collective['children'].items():
+ if data[0] != 'dirnode':
+ print "Error: '%s': expected a dirnode, not '%s'" % (name, data[0])
+ print " %s's remote:" % name
+ dmd = _get_json_for_cap(options, data[1]['ro_uri'])
+ if dmd[0] != 'dirnode':
+ print "Error: should be a dirnode"
+ continue
+ for (n, d) in dmd[1]['children'].items():
+ if d[0] != 'filenode':
+ print "Error: expected '%s' to be a filenode." % (n,)
+
+ meta = d[1]
+ status = 'good'
+ size = meta['size']
+ created = datetime.fromtimestamp(meta['metadata']['tahoe']['linkcrtime'])
+ version = meta['metadata']['version']
+ nice_size = humanize.naturalsize(size)
+ nice_created = humanize.naturaltime(now - created)
+ print " %s (%s): %s, version=%s, created %s" % (n, nice_size, status, version, nice_created)
+
+ magicdata = _get_json_for_fragment(options, 'magic_folder?t=json')
+ if len(magicdata):
+ uploads = [item for item in magicdata if item['kind'] == 'upload']
+ downloads = [item for item in magicdata if item['kind'] == 'download']
+ longest = max([len(item['path']) for item in magicdata])
+
+ if True: # maybe --show-completed option or something?
+ uploads = [item for item in uploads if item['status'] != 'success']
+ downloads = [item for item in downloads if item['status'] != 'success']
+
+ if len(uploads):
+ print
+ print "Uploads:"
+ for item in uploads:
+ _print_item_status(item, now, longest)
+
+ if len(downloads):
+ print
+ print "Downloads:"
+ for item in downloads:
+ _print_item_status(item, now, longest)
+
+ for item in magicdata:
+ if item['status'] == 'failure':
+ print "Failed:", item
+