Added fn-info command to dump repository information.
diff --git a/infocalypse/__init__.py b/infocalypse/__init__.py
--- a/infocalypse/__init__.py
+++ b/infocalypse/__init__.py
@@ -154,7 +154,8 @@ from binascii import hexlify
from mercurial import commands, util
from infcmds import get_config_info, execute_create, execute_pull, \
- execute_push, execute_setup, execute_copy, execute_reinsert
+ execute_push, execute_setup, execute_copy, execute_reinsert, \
+ execute_info
def set_target_version(ui_, repo, opts, params, msg_fmt):
""" INTERNAL: Update TARGET_VERSION in params. """
@@ -282,6 +283,24 @@ def infocalypse_push(ui_, repo, **opts):
execute_push(ui_, repo, params, stored_cfg)
+def infocalypse_info(ui_, repo, **opts):
+ """ Display information about an Infocalypse repository.
+ """
+ # FCP not required. Hmmm... Hack
+ opts['fcphost'] = ''
+ opts['fcpport'] = 0
+ params, stored_cfg = get_config_info(ui_, opts)
+ request_uri = opts['uri']
+ if request_uri == '':
+ request_uri = stored_cfg.get_request_uri(repo.root)
+ if not request_uri:
+ ui_.warn("There is no stored request URI for this repo.\n"
+ "Please set one with the --uri option.\n")
+ return
+
+ params['REQUEST_URI'] = request_uri
+ execute_info(ui_, repo, params, stored_cfg)
+
def infocalypse_setup(ui_, **opts):
""" Setup the extension for use for the first time. """
@@ -337,6 +356,10 @@ cmdtable = {
+ NOSEARCH_OPT,
"[options]"),
+ "fn-info": (infocalypse_info,
+ [('', 'uri', '', 'request URI'),],
+ "[options]"),
+
"fn-setup": (infocalypse_setup,
[('', 'tmpdir', '~/infocalypse_tmp', 'temp directory'),]
+ FCP_OPTS,
diff --git a/infocalypse/infcmds.py b/infocalypse/infcmds.py
--- a/infocalypse/infcmds.py
+++ b/infocalypse/infcmds.py
@@ -44,7 +44,7 @@ from updatesm import UpdateStateMachine,
REQUESTING_URI_4_INSERT, INSERTING_BUNDLES, INSERTING_GRAPH, \
INSERTING_URI, FAILING, REQUESTING_URI_4_COPY, CANCELING, CleaningUp
-from config import Config, DEFAULT_CFG_PATH
+from config import Config, DEFAULT_CFG_PATH, normalize
DEFAULT_PARAMS = {
# FCP params
@@ -671,6 +671,39 @@ def execute_pull(ui_, repo, params, stor
finally:
cleanup(update_sm)
+NO_INFO_FMT = """There's no stored information about that USK.
+USK hash: %s
+"""
+
+INFO_FMT ="""USK hash: %s
+index : %i
+
+Request URI:
+%s
+Insert URI:
+%s
+"""
+
+def execute_info(ui_, repo, params, stored_cfg):
+ request_uri = params['REQUEST_URI']
+ if request_uri is None or not is_usk_file(request_uri):
+ ui_.status("Only works with USK file URIs.\n")
+ return
+
+ usk_hash = normalize(request_uri)
+ max_index = stored_cfg.get_index(request_uri)
+ if max_index is None:
+ ui_.status(NO_INFO_FMT % usk_hash)
+ return
+
+ insert_uri = str(stored_cfg.get_insert_uri(usk_hash))
+
+ # fix index
+ request_uri = get_usk_for_usk_version(request_uri, max_index)
+
+ ui_.status(INFO_FMT %
+ (usk_hash, max_index or -1, request_uri, insert_uri))
+
def setup_tmp_dir(ui_, tmp):
""" INTERNAL: Setup the temp directory. """
tmp = os.path.expanduser(tmp)