def execute_arc_push(ui_, params, stored_cfg): """ Push an update into an incremental archive in Freenet. """ assert params.get('REQUEST_URI', None) is None # REDFLAG: why ? update_sm = None top_key_state = None try: update_sm = setup(ui_, None, params, stored_cfg) request_uri, dummy_is_keypair = do_key_setup(ui_, update_sm, params, stored_cfg) create_dirs(ui_, params['ARCHIVE_CACHE_DIR'], request_uri) ui_.debug("%sInsert URI:\n%s\n" % (is_redundant(params['INSERT_URI']), params['INSERT_URI'])) # Update the local archive. files, top_key = local_update(params['ARCHIVE_CACHE_DIR'], request_uri, params['FROM_DIR']) if files is None: raise util.Abort("There are no local changes to add.") for block in top_key[0]: if block[1][0] == 'CHK@': ui_.status("Created new %i byte block.\n" % block[0]) # Insert them into Freenet. ctx = ArchiveUpdateContext(update_sm, ui_) ctx.update({'REQUEST_URI':request_uri, 'INSERT_URI':params['INSERT_URI'], 'ARCHIVE_CACHE_DIR':params['ARCHIVE_CACHE_DIR'], 'PROVISIONAL_TOP_KEY':top_key, 'ARCHIVE_BLOCK_FILES':files}) start_inserting_blocks(update_sm, ctx) run_until_quiescent(update_sm, params['POLL_SECS']) if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING,))): ui_.status("Inserted to:\n%s\n" % '\n'.join(update_sm.get_state(ARC_INSERTING_URI). get_request_uris())) top_key_state = ARC_INSERTING_URI else: ui_.status("Push to archive failed.\n") arc_handle_updating_config(update_sm, params, stored_cfg) finally: arc_cleanup(update_sm, top_key_state)
def execute_arc_push(ui_, params, stored_cfg): """ Push an update into an incremental archive in Freenet. """ assert params.get('REQUEST_URI', None) is None # REDFLAG: why ? update_sm = None top_key_state = None try: update_sm = setup(ui_, None, params, stored_cfg) request_uri, dummy_is_keypair = do_key_setup(ui_, update_sm, params, stored_cfg) create_dirs(ui_, params['ARCHIVE_CACHE_DIR'], request_uri) ui_.status("%sInsert URI:\n%s\n" % (is_redundant(params['INSERT_URI']), params['INSERT_URI'])) # Update the local archive. files, top_key = local_update(params['ARCHIVE_CACHE_DIR'], request_uri, params['FROM_DIR']) if files is None: raise util.Abort("There are no local changes to add.") for block in top_key[0]: if block[1][0] == 'CHK@': ui_.status("Created new %i byte block.\n" % block[0]) # Insert them into Freenet. ctx = ArchiveUpdateContext(update_sm, ui_) ctx.update({ 'REQUEST_URI': request_uri, 'INSERT_URI': params['INSERT_URI'], 'ARCHIVE_CACHE_DIR': params['ARCHIVE_CACHE_DIR'], 'PROVISIONAL_TOP_KEY': top_key, 'ARCHIVE_BLOCK_FILES': files }) start_inserting_blocks(update_sm, ctx) run_until_quiescent(update_sm, params['POLL_SECS']) if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))): ui_.status("Inserted to:\n%s\n" % '\n'.join( update_sm.get_state(ARC_INSERTING_URI).get_request_uris())) top_key_state = ARC_INSERTING_URI else: ui_.status("Push to archive failed.\n") arc_handle_updating_config(update_sm, params, stored_cfg) finally: arc_cleanup(update_sm, top_key_state)
def execute_arc_reinsert(ui_, params, stored_cfg): """ Reinsert the archive into Freenet. """ assert not params.get('REQUEST_URI', None) is None assert params.get('REINSERT_LEVEL', 0) > 0 update_sm = None try: update_sm = setup(ui_, None, params, stored_cfg) request_uri, dummy_is_keypair = do_key_setup(ui_, update_sm, params, stored_cfg) create_dirs(ui_, params['ARCHIVE_CACHE_DIR'], request_uri) ui_.status("%sRequest URI:\n%s\n" % (is_redundant(request_uri), request_uri)) # Get the blocks to re-insert. files, top_key = local_reinsert(params['ARCHIVE_CACHE_DIR'], request_uri) # Tell the user about them. for block in top_key[0]: if block[1][0] == 'CHK@': ui_.status("Re-inserting %i byte block.\n" % block[0]) # Start re-inserting them. ctx = ArchiveUpdateContext(update_sm, ui_) ctx.update({ 'REQUEST_URI': request_uri, 'INSERT_URI': params['INSERT_URI'], 'ARCHIVE_CACHE_DIR': params['ARCHIVE_CACHE_DIR'], 'PROVISIONAL_TOP_KEY': top_key, 'ARCHIVE_BLOCK_FILES': files, 'REINSERT': params['REINSERT_LEVEL'] }) start_inserting_blocks(update_sm, ctx) run_until_quiescent(update_sm, params['POLL_SECS']) if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))): ui_.status("Re-insert finished.\n") else: ui_.status("Re-insert failed.\n") arc_handle_updating_config(update_sm, params, stored_cfg) finally: arc_cleanup(update_sm, None) # Don't prune cache.
def execute_arc_create(ui_, params, stored_cfg): """ Create a new incremental archive. """ update_sm = None top_key_state = None try: assert 'ARCHIVE_CACHE_DIR' in params assert 'FROM_DIR' in params update_sm = setup(ui_, None, params, stored_cfg) request_uri, dummy = do_key_setup(ui_, update_sm, params, stored_cfg) create_dirs(ui_, params['ARCHIVE_CACHE_DIR'], request_uri) ui_.status("%sInsert URI:\n%s\n" % (is_redundant(params['INSERT_URI']), params['INSERT_URI'])) # Create the local blocks. files, top_key = local_create(params['ARCHIVE_CACHE_DIR'], request_uri, params['FROM_DIR']) for block in top_key[0]: if block[1][0] == 'CHK@': ui_.status("Created new %i byte block.\n" % block[0]) # Insert them into Freenet. ctx = ArchiveUpdateContext(update_sm, ui_) ctx.update({ 'REQUEST_URI': request_uri, 'INSERT_URI': params['INSERT_URI'], 'ARCHIVE_CACHE_DIR': params['ARCHIVE_CACHE_DIR'], 'PROVISIONAL_TOP_KEY': top_key, 'ARCHIVE_BLOCK_FILES': files }) start_inserting_blocks(update_sm, ctx) run_until_quiescent(update_sm, params['POLL_SECS']) if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))): ui_.status("Inserted to:\n%s\n" % '\n'.join( update_sm.get_state(ARC_INSERTING_URI).get_request_uris())) top_key_state = ARC_INSERTING_URI else: ui_.status("Archive create failed.\n") arc_handle_updating_config(update_sm, params, stored_cfg) finally: arc_cleanup(update_sm, top_key_state)
def execute_arc_reinsert(ui_, params, stored_cfg): """ Reinsert the archive into Freenet. """ assert not params.get('REQUEST_URI', None) is None assert params.get('REINSERT_LEVEL', 0) > 0 update_sm = None try: update_sm = setup(ui_, None, params, stored_cfg) request_uri, dummy_is_keypair = do_key_setup(ui_, update_sm, params, stored_cfg) create_dirs(ui_, params['ARCHIVE_CACHE_DIR'], request_uri) ui_.status("%sRequest URI:\n%s\n" % (is_redundant(request_uri), request_uri)) # Get the blocks to re-insert. files, top_key = local_reinsert(params['ARCHIVE_CACHE_DIR'], request_uri) # Tell the user about them. for block in top_key[0]: if block[1][0] == 'CHK@': ui_.status("Re-inserting %i byte block.\n" % block[0]) # Start re-inserting them. ctx = ArchiveUpdateContext(update_sm, ui_) ctx.update({'REQUEST_URI':request_uri, 'INSERT_URI':params['INSERT_URI'], 'ARCHIVE_CACHE_DIR':params['ARCHIVE_CACHE_DIR'], 'PROVISIONAL_TOP_KEY':top_key, 'ARCHIVE_BLOCK_FILES':files, 'REINSERT':params['REINSERT_LEVEL']}) start_inserting_blocks(update_sm, ctx) run_until_quiescent(update_sm, params['POLL_SECS']) if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING,))): ui_.status("Re-insert finished.\n") else: ui_.status("Re-insert failed.\n") arc_handle_updating_config(update_sm, params, stored_cfg) finally: arc_cleanup(update_sm, None) # Don't prune cache.
def execute_arc_create(ui_, params, stored_cfg): """ Create a new incremental archive. """ update_sm = None top_key_state = None try: assert 'ARCHIVE_CACHE_DIR' in params assert 'FROM_DIR' in params update_sm = setup(ui_, None, params, stored_cfg) request_uri, dummy = do_key_setup(ui_, update_sm, params, stored_cfg) create_dirs(ui_, params['ARCHIVE_CACHE_DIR'], request_uri) ui_.debug("%sInsert URI:\n%s\n" % (is_redundant(params['INSERT_URI']), params['INSERT_URI'])) # Create the local blocks. files, top_key = local_create(params['ARCHIVE_CACHE_DIR'], request_uri, params['FROM_DIR']) for block in top_key[0]: if block[1][0] == 'CHK@': ui_.status("Created new %i byte block.\n" % block[0]) # Insert them into Freenet. ctx = ArchiveUpdateContext(update_sm, ui_) ctx.update({'REQUEST_URI':request_uri, 'INSERT_URI':params['INSERT_URI'], 'ARCHIVE_CACHE_DIR':params['ARCHIVE_CACHE_DIR'], 'PROVISIONAL_TOP_KEY':top_key, 'ARCHIVE_BLOCK_FILES':files}) start_inserting_blocks(update_sm, ctx) run_until_quiescent(update_sm, params['POLL_SECS']) if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING,))): ui_.status("Inserted to:\n%s\n" % '\n'.join(update_sm.get_state(ARC_INSERTING_URI). get_request_uris())) top_key_state = ARC_INSERTING_URI else: ui_.status("Archive create failed.\n") arc_handle_updating_config(update_sm, params, stored_cfg) finally: arc_cleanup(update_sm, top_key_state)
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)