(Steve Dougherty)
2013-07-26: Fix overcomplication in finding a local truster. Fix overcomplication in finding a local truster. Returning a default when an explicit WoT identity was not set required more complex code to use a non-default, as was desired in most circumstances. Also fixes fn-pull incorrectly resolving WoT identity by insert URI. (It is actually keyed by request URI hash / "repo id".)
diff --git a/infocalypse/commands.py b/infocalypse/commands.py --- a/infocalypse/commands.py +++ b/infocalypse/commands.py @@ -189,12 +189,7 @@ def infocalypse_pull(ui_, repo, **opts): request_uri = get_uri_from_hash(ui_, repo, params, stored_cfg) elif opts['wot']: import wot - if opts['truster']: - local_id = wot.resolve_local_identity(ui_, opts['truster']) - truster = local_id['Identity'] - else: - truster = stored_cfg.get_wot_identity( - stored_cfg.get_dir_insert_uri(repo.root)) + truster = get_truster(ui_, repo, opts) request_uri = wot.resolve_pull_uri(ui_, opts['wot'], truster) @@ -263,11 +258,12 @@ def infocalypse_push(ui_, repo, **opts): # params['REQUEST_URI'] = opts['requesturi'] inserted_to = execute_push(ui_, repo, params, stored_cfg) - # TODO: Messy. Is there a better way to check what repos are under WoT? + request_uri = stored_cfg.get_request_uri(repo.root) - if inserted_to is not None and stored_cfg.has_wot_identity(request_uri): + associated_wot_id = stored_cfg.get_wot_identity(request_uri) + if inserted_to and associated_wot_id: import wot - wot.update_repo_listing(ui_, stored_cfg.get_wot_identity(request_uri)) + wot.update_repo_listing(ui_, associated_wot_id) def infocalypse_info(ui_, repo, **opts): @@ -505,12 +501,22 @@ def infocalypse_setupfreemail(ui, repo, def get_truster(ui, repo, opts): + """ + Return a local WoT ID. + + TODO: Check that it actually is local? Classes would be nice for this. + Being stringly typed as present requires a lot of checking and re-checking. + """ if opts['truster']: return opts['truster'] else: cfg = Config().from_ui(ui) - # TODO: What about if there's no request URI set? - return '@' + cfg.get_wot_identity(cfg.get_request_uri(repo.root)) + + identity = cfg.get_wot_identity(cfg.get_request_uri(repo.root)) + if not identity: + identity = cfg.defaults['DEFAULT_TRUSTER'] + + return '@' + identity #----------------------------------------------------------" diff --git a/infocalypse/config.py b/infocalypse/config.py --- a/infocalypse/config.py +++ b/infocalypse/config.py @@ -214,24 +214,13 @@ class Config: def get_wot_identity(self, for_usk_or_id): """ Return the WoT identity associated with the request USK, - or the default if none is set. - - TODO: Is falling back to the default sane behavior? Has caused - problems with unexpected associations. + or None if one is not set. """ if for_usk_or_id is not None: repo_id = normalize(for_usk_or_id) if repo_id in self.wot_identities: return self.wot_identities[repo_id] - return self.defaults['DEFAULT_TRUSTER'] - - def has_wot_identity(self, for_usk_or_id): - """ - Return whether the given repo has a WoT identity associated with it. - """ - return normalize(for_usk_or_id) in self.wot_identities - def set_freemail_password(self, wot_identity, password): """ Set the password for the given WoT identity. diff --git a/infocalypse/wot.py b/infocalypse/wot.py --- a/infocalypse/wot.py +++ b/infocalypse/wot.py @@ -319,10 +319,7 @@ def build_repo_list(ui, wot_id): # Add request URIs associated with the given identity. for request_uri in config.request_usks.itervalues(): - # TODO: Getting the default WoT ID instead of an explicit association - # (as in get_wot_identity()) is not desirable. - if config.has_wot_identity(request_uri) and \ - config.get_wot_identity(request_uri) == local_id['Identity']: + if config.get_wot_identity(request_uri) == local_id['Identity']: repos.append(request_uri) return repos