def handled_list(ui_, params, stored_cfg): """ INTERNAL: HACKED""" if params['FMSREAD'] != 'listall' and params['FMSREAD'] != 'list': return False trust_map = None if params['FMSREAD'] == 'list': trust_map = stored_cfg.fmsread_trust_map.copy() # paranoid copy fms_ids = trust_map.keys() fms_ids.sort() ui_.status(("Only listing repo USKs from trusted " + "FMS IDs:\n %s\n\n") % '\n '.join(fms_ids)) parser = USKNotificationParser(trust_map) parser.add_default_repos(KNOWN_REPOS) recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'], stored_cfg.defaults['FMS_PORT'], None), parser, stored_cfg.fmsread_groups) show_table(parser, ui_.status) return True
def execute_fmsnotify(ui_, repo, params, stored_cfg): """ Run fmsnotify command. """ update_sm = None try: # Insert URI MUST be stored. update_sm = setup(ui_, repo, params, stored_cfg) request_uri, dummy = do_key_setup(ui_, update_sm, params, stored_cfg) if request_uri is None: # Just assert? ui_.warn("Only works for USK file URIs.\n") return check_fms_cfg(ui_, params, stored_cfg) usk_hash = get_usk_hash(request_uri) index = stored_cfg.get_index(usk_hash) if index is None and not (params.get('SUBMIT_BUNDLE', False) or params.get('SUBMIT_WIKI', False)): ui_.warn("Can't notify because there's no stored index " + "for %s.\n" % usk_hash) return group = stored_cfg.defaults.get('FMSNOTIFY_GROUP', None) subject = 'Update:' + '/'.join(request_uri.split('/')[1:]) if params['ANNOUNCE']: text = to_msg_string(None, (request_uri, )) elif params['SUBMIT_BUNDLE']: params['REQUEST_URI'] = request_uri # REDFLAG: Think through. text = execute_insert_patch(ui_, repo, params, stored_cfg) subject = 'Patch:' + '/'.join(request_uri.split('/')[1:]) elif params['SUBMIT_WIKI']: params['REQUEST_URI'] = request_uri # REDFLAG: Think through. text, group = execute_wiki_submit(ui_, repo, params, stored_cfg) subject = 'Submit:' + '/'.join(request_uri.split('/')[1:]) else: text = to_msg_string(((usk_hash, index), )) msg_tuple = (stored_cfg.defaults['FMS_ID'], group, subject, text) show_fms_info(ui_, params, stored_cfg, False) ui_.status('Sender : %s\nGroup : %s\nSubject: %s\n%s\n' % (stored_cfg.defaults['FMS_ID'], group, subject, text)) if params['VERBOSITY'] >= 5: ui_.status('--- Raw Message ---\n%s\n---\n' % ( MSG_TEMPLATE % (msg_tuple[0], msg_tuple[1], msg_tuple[2], msg_tuple[3]))) if params['DRYRUN']: ui_.status('Exiting without sending because --dryrun was set.\n') return # REDFLAG: for testing! if 'MSG_SPOOL_DIR' in params: ui_.warn("DEBUG HACK!!! Writing fms msg to local spool:\n%s\n" % params['MSG_SPOOL_DIR']) import fmsstub # LATER: fix config file to store full fmsid? # grrrr... hacks piled upon hacks. lut = {'djk':'djk@isFiaD04zgAgnrEC5XJt1i4IE7AkNPqhBG5bONi6Yks'} fmsstub.FMSStub(params['MSG_SPOOL_DIR'], group, lut).send_msgs( get_connection(stored_cfg.defaults['FMS_HOST'], stored_cfg.defaults['FMS_PORT'], None), (msg_tuple, ), True) else: send_msgs(get_connection(stored_cfg.defaults['FMS_HOST'], stored_cfg.defaults['FMS_PORT'], None), (msg_tuple, ), True) ui_.status('Notification message sent.\n' 'Be patient. It may take up to a day to show up.\n') finally: cleanup(update_sm)
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(get_connection(stored_cfg.defaults['FMS_HOST'], stored_cfg.defaults['FMS_PORT'], None), parser, stored_cfg.fmsread_groups, None, True) target_usk = None fms_id_map, announce_map, update_map = parser.invert_table() # Find URI for usk in announce_map: 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.") % params['FMSREAD_HASH']) if params['VERBOSITY'] >= 2: ui_.status("Found URI announcement:\n%s\n" % target_usk) trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH']) notifiers = {} 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() ui_.status("Found Updates:\n") for fms_id in fms_ids: if fms_id in trusted_notifiers: ui_.status(" [trusted]:%i:%s\n" % (notifiers[fms_id], fms_id)) else: ui_.status(" [untrusted]:%i:%s\n" % (notifiers[fms_id], fms_id)) check_trust_map(ui_, stored_cfg, params['FMSREAD_HASH'], notifiers, trusted_notifiers) # Check for updates against the updated trust map. trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH']) for fms_id in fms_ids: if fms_id in trusted_notifiers: if (notifiers[fms_id] > stored_cfg.get_index(params['FMSREAD_HASH'])): stored_cfg.update_index(params['FMSREAD_HASH'], notifiers[fms_id]) return target_usk
def execute_fmsread(ui_, params, stored_cfg): """ Run the fmsread command. """ if handled_trust_cmd(ui_, params, stored_cfg): return show_fms_info(ui_, params, stored_cfg) # Listing announced Repo USKs if handled_list(ui_, params, stored_cfg): return # Updating Repo USK indices for repos which are # listed in the fmsread_trust_map section of the # config file. trust_map = stored_cfg.fmsread_trust_map.copy() # paranoid copy dump_trust_map(ui_, params, trust_map) ui_.status("Raking through fms messages. This may take a while...\n") parser = USKNotificationParser() recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'], stored_cfg.defaults['FMS_PORT'], None), parser, stored_cfg.fmsread_groups) # IMPORTANT: Must include versions that are in the trust map # but which we haven't seen before. full_version_table = stored_cfg.version_table.copy() for usk_hash in known_hashes(trust_map): if not usk_hash in full_version_table: full_version_table[usk_hash] = None # works changed, untrusted = parser.get_updated(trust_map, full_version_table) if params['VERBOSITY'] >= 2 and len(untrusted) > 0: text = 'Skipped untrusted updates:\n' for usk_hash in untrusted: text += " %i:%s\n" % (untrusted[usk_hash][0], usk_hash) text += '\n' ui_.status(text) if len(changed) == 0: ui_.status('No updates found.\n') return # Back map to uris ? Can't always do it. if len(changed) > 0: text = 'Updates:\n' for usk_hash in changed: text += '%s:%i\n' % (usk_hash, changed[usk_hash]) ui_.status(text) if ((not params['REQUEST_URI'] is None) and get_usk_hash(params['REQUEST_URI']) in changed): ui_.status("Current repo has update to index %s.\n" % changed[get_usk_hash(params['REQUEST_URI'])]) if params['DRYRUN']: ui_.status('Exiting without saving because --dryrun was set.\n') return for usk_hash in changed: stored_cfg.update_index(usk_hash, changed[usk_hash]) Config.to_file(stored_cfg) ui_.status('Saved updated indices.\n')