Pylint fixes.
diff --git a/infocalypse/config.py b/infocalypse/config.py
--- a/infocalypse/config.py
+++ b/infocalypse/config.py
@@ -213,6 +213,26 @@ class Config:
ret.append(fms_id)
return ret
+ # Broke this into a seperate func to appease pylint.
+ @classmethod
+ def validate_trust_map_entry(cls, cfg, fields):
+ """ INTERNAL: Raise a ValueError for invalid trust map entries. """
+ if not is_fms_id(fields[0]):
+ raise ValueError("%s doesn't look like an fms id." %
+ fields[0])
+ if len(fields) < 2:
+ raise ValueError("No USK hashes for fms id: %s?" %
+ fields[0])
+ for value in fields[1:]:
+ if not is_hex_string(value):
+ raise ValueError("%s doesn't look like a repo hash." %
+ value)
+
+ if fields[0] in cfg.fmsread_trust_map:
+ raise ValueError(("%s appears more than once in the "
+ + "[fmsread_trust_map] section.") %
+ fields[0])
+
@classmethod
def update_defaults(cls, parser, cfg):
""" INTERNAL: Helper function to simplify from_file. """
@@ -274,25 +294,9 @@ class Config:
for ordinal in parser.options('fmsread_trust_map'):
fields = parser.get('fmsread_trust_map',
ordinal).strip().split('|')
- # REDFLAG: better validation for fms_id, hashes?
- if not is_fms_id(fields[0]):
- raise ValueError("%s doesn't look like an fms id." %
- fields[0])
- if len(fields) < 2:
- raise ValueError("No USK hashes for fms id: %s?" %
- fields[0])
- for value in fields[1:]:
- if not is_hex_string(value):
- raise ValueError("%s doesn't look like a repo hash." %
- value)
-
- if fields[0] in cfg.fmsread_trust_map:
- raise ValueError(("%s appears more than once in the "
- + "[fmsread_trust_map] section.") %
- fields[0])
+ Config.validate_trust_map_entry(cfg, fields)
cfg.fmsread_trust_map[fields[0]] = tuple(fields[1:])
-
Config.update_defaults(parser, cfg)
cfg.file_name = file_name
diff --git a/infocalypse/fms.py b/infocalypse/fms.py
--- a/infocalypse/fms.py
+++ b/infocalypse/fms.py
@@ -252,6 +252,27 @@ def strip_names(trust_map):
+ clean.get(cleaned, [])))
return clean
+# Hmmmm... broke into a separate func to appease pylint.
+def get_changed(max_trusted, max_untrusted, version_table):
+ """ INTERNAL: Helper function used by USKNotificationParser.get_updated. """
+ changed = {}
+ untrusted = {}
+ for usk_hash in version_table:
+ if usk_hash in max_trusted:
+ changed[usk_hash] = max_trusted[usk_hash]
+
+ if usk_hash in max_untrusted:
+ if usk_hash in changed:
+ if max_untrusted[usk_hash][0] > changed[usk_hash]:
+ # There was a trusted update, but the untrusted one
+ # was higher.
+ untrusted[usk_hash] = max_untrusted[usk_hash]
+ else:
+ # No trusted updated
+ untrusted[usk_hash] = max_untrusted[usk_hash]
+
+ return (changed, untrusted)
+
# REDFLAG: Trust map ids are w/o names.
#
# clean_fms_id -> (set(uri,..), hash-> index, set(full_fms_id, ...))
@@ -409,25 +430,9 @@ class USKNotificationParser(IFmsMessageS
elif index > max_untrusted[usk_hash]:
max_untrusted[usk_hash] = (index, fms_id)
- changed = {}
- untrusted = {}
- for usk_hash in version_table:
- if usk_hash in max_trusted:
- changed[usk_hash] = max_trusted[usk_hash]
-
- if usk_hash in max_untrusted:
- if usk_hash in changed:
- if max_untrusted[usk_hash][0] > changed[usk_hash]:
- # There was a trusted update, but the untrusted one
- # was higher.
- untrusted[usk_hash] = max_untrusted[usk_hash]
- else:
- # No trusted updated
- untrusted[usk_hash] = max_untrusted[usk_hash]
-
# changed is usk_hash->index
# untrusted is usk_hash->(index, fms_id)
- return (changed, untrusted)
+ return get_changed(max_trusted, max_untrusted, version_table)
def show_table(parser, out_func):
""" Dump the announcements and updates in a human readable format. """
diff --git a/infocalypse/fmscmds.py b/infocalypse/fmscmds.py
--- a/infocalypse/fmscmds.py
+++ b/infocalypse/fmscmds.py
@@ -93,18 +93,31 @@ def handled_trust_cmd(ui_, params, store
return False
+# To appease pylint
+def show_fms_info(ui_, params, stored_cfg, show_groups=True):
+ """ INTERNAL: Helper function prints fms info. """
+
+ if params['VERBOSITY'] < 2:
+ return
+
+ if show_groups:
+ ui_.status(('Connecting to fms on %s:%i\n'
+ + 'Searching groups: %s\n') %
+ (stored_cfg.defaults['FMS_HOST'],
+ stored_cfg.defaults['FMS_PORT'],
+ ' '.join(stored_cfg.fmsread_groups)))
+ else:
+ ui_.status(('Connecting to fms on %s:%i\n') %
+ (stored_cfg.defaults['FMS_HOST'],
+ stored_cfg.defaults['FMS_PORT']))
+
def execute_fmsread(ui_, params, stored_cfg):
""" Run the fmsread command. """
if handled_trust_cmd(ui_, params, stored_cfg):
return
- if params['VERBOSITY'] >= 2:
- ui_.status(('Connecting to fms on %s:%i\n'
- + 'Searching groups: %s\n') %
- (stored_cfg.defaults['FMS_HOST'],
- stored_cfg.defaults['FMS_PORT'],
- ' '.join(stored_cfg.fmsread_groups)))
+ show_fms_info(ui_, params, stored_cfg)
# Listing announced Repo USKs
if handled_list(ui_, params, stored_cfg):
@@ -213,10 +226,7 @@ def execute_fmsnotify(ui_, repo, params,
subject,
text)
- if params['VERBOSITY'] >= 2:
- ui_.status('Connecting to fms on %s:%i\n' %
- (stored_cfg.defaults['FMS_HOST'],
- stored_cfg.defaults['FMS_PORT']))
+ show_fms_info(ui_, params, stored_cfg, False)
ui_.status('Sender : %s\nGroup : %s\nSubject: %s\n%s\n' %
(stored_cfg.defaults['FMS_ID'],
@@ -282,14 +292,9 @@ def check_trust_map(ui_, stored_cfg, rep
Config.to_file(stored_cfg)
ui_.status("Saved updated config file.\n\n")
-def get_uri_from_hash(ui_, dummy, params, stored_cfg):
- """ Use FMS to get the URI for a repo hash. """
- if params['VERBOSITY'] >= 2:
- ui_.status(('Connecting to fms on %s:%i\n'
- + 'Searching groups: %s\n') %
- (stored_cfg.defaults['FMS_HOST'],
- stored_cfg.defaults['FMS_PORT'],
- ' '.join(stored_cfg.fmsread_groups)))
+# Broke into a separate function to appease pylint.
+def get_trust_map(ui_, params, stored_cfg):
+ """ INTERNAL: Helper function to set up the trust map if required. """
trust_map = None
if params['FMSREAD_ONLYTRUSTED']:
# HACK to deal with spam of the announcement group.'
@@ -299,37 +304,46 @@ def get_uri_from_hash(ui_, dummy, params
ui_.status(("Only using announcements from trusted "
+ "FMS IDs:\n %s\n\n") % '\n '.join(fms_ids))
- parser = USKNotificationParser(trust_map)
+ return trust_map
+
+def get_uri_from_hash(ui_, dummy, params, stored_cfg):
+ """ Use FMS to get the URI for a repo hash. """
+
+ show_fms_info(ui_, params, stored_cfg)
+
+ parser = USKNotificationParser(get_trust_map(ui_, params, stored_cfg))
parser.add_default_repos(KNOWN_REPOS)
+
ui_.status("Raking through fms messages. This may take a while...\n")
recv_msgs(stored_cfg.defaults['FMS_HOST'],
stored_cfg.defaults['FMS_PORT'],
parser,
stored_cfg.fmsread_groups)
- target_hash = params['FMSREAD_HASH']
target_usk = None
fms_id_map, announce_map, update_map = parser.invert_table()
# Find URI
for usk in announce_map:
- if target_hash == get_usk_hash(usk):
+ if params['FMSREAD_HASH'] == get_usk_hash(usk):
# We don't care who announced. The hash matches.
target_usk = usk
break
if target_usk is None:
raise util.Abort(("No announcement found for [%s]. "
- +"Use --uri to set the URI.") % target_hash)
+ +"Use --uri to set the URI.") %
+ params['FMSREAD_HASH'])
if params['VERBOSITY'] >= 2:
ui_.status("Found URI announcement:\n%s\n" % target_usk)
- trusted_notifiers = stored_cfg.trusted_notifiers(target_hash)
+ trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH'])
notifiers = {}
- for clean_id in update_map[target_hash]:
- notifiers[fms_id_map[clean_id]] = parser.table[clean_id][1][target_hash]
+ for clean_id in update_map[params['FMSREAD_HASH']]:
+ notifiers[fms_id_map[clean_id]] = (parser.table[clean_id][1]
+ [params['FMSREAD_HASH']])
fms_ids = notifiers.keys()
fms_ids.sort()
@@ -337,12 +351,12 @@ def get_uri_from_hash(ui_, dummy, params
ui_.status("Found Updates:\n")
for fms_id in fms_ids:
if fms_id in trusted_notifiers:
- value = "trusted"
+ ui_.status(" [trusted]:%i:%s\n" % (notifiers[fms_id], fms_id))
else:
- value = "untrusted"
- ui_.status(" [%s]:%i:%s\n" % (value, notifiers[fms_id], fms_id))
+ ui_.status(" [untrusted]:%i:%s\n" % (notifiers[fms_id], fms_id))
- check_trust_map(ui_, stored_cfg, target_hash, notifiers, trusted_notifiers)
+ check_trust_map(ui_, stored_cfg, params['FMSREAD_HASH'],
+ notifiers, trusted_notifiers)
return target_usk
diff --git a/infocalypse/requestingbundles.py b/infocalypse/requestingbundles.py
--- a/infocalypse/requestingbundles.py
+++ b/infocalypse/requestingbundles.py
@@ -21,7 +21,6 @@
"""
# REDFLAG: reevaluate on failure?
-
import os
import random # Hmmm... good enough?
@@ -163,8 +162,7 @@ class RequestingBundles(RetryingRequestL
last_queued = -1
for index, update in enumerate(updates):
if index < start_index:
- # REDFLAG: do better?
- continue
+ continue # REDFLAG: do better?
if not update[4] or not update[5]:
# Don't attempt to queue updates if we don't know
# full parent/head info.