Ejemplo n.º 1
0
def infocalypse_putsite(ui_, repo, **opts):
    """ Insert an update to a freesite.
    """

    if opts['createconfig']:
        if opts['wiki']:
            raise util.Abort("Use fn-wiki --createconfig.")
        params = {'SITE_CREATE_CONFIG': True}
        execute_putsite(ui_, repo, params)
        return

    params, stored_cfg = get_config_info(ui_, opts)
    if opts['key']:  # order important
        params['SITE_KEY'] = opts['key']
        if not (params['SITE_KEY'].startswith('SSK') or
                params['SITE_KEY'] == 'CHK@'):
            raise util.Abort("--key must be a valid SSK "
                             + "insert key or CHK@.")

    params['ISWIKI'] = opts['wiki']
    read_freesite_cfg(ui_, repo, params, stored_cfg)

    try:
        # --index not required for CHK@
        if not params['SITE_KEY'].startswith('CHK'):
            params['SITE_INDEX'] = int(opts['index'])
            if params['SITE_INDEX'] < 0:
                raise ValueError()
        else:
            params['SITE_INDEX'] = -1
    except ValueError:
        raise util.Abort(MSG_BAD_INDEX)
    except TypeError:
        raise util.Abort(MSG_BAD_INDEX)

    params['DRYRUN'] = opts['dryrun']

    if not params.get('SITE_KEY', None):
        insert_uri = stored_cfg.get_dir_insert_uri(repo.root)
        if not insert_uri:
            ui_.warn("You don't have the insert URI for this repo.\n"
                     + "Supply a private key with --key or fn-push "
                     + "the repo.\n")
            return  # REDFLAG: hmmm... abort?
        params['SITE_KEY'] = 'SSK' + insert_uri.split('/')[0][3:]

    execute_putsite(ui_, repo, params)
Ejemplo n.º 2
0
def infocalypse_putsite(ui_, repo, **opts):
    """ Insert an update to a freesite.
    """

    if opts['createconfig']:
        if opts['wiki']:
            raise util.Abort("Use fn-wiki --createconfig.")
        params = {'SITE_CREATE_CONFIG': True}
        execute_putsite(ui_, repo, params)
        return

    params, stored_cfg = get_config_info(ui_, opts)
    if opts['key'] != '':  # order important
        params['SITE_KEY'] = opts['key']
        if not (params['SITE_KEY'].startswith('SSK')
                or params['SITE_KEY'] == 'CHK@'):
            raise util.Abort("--key must be a valid SSK " +
                             "insert key or CHK@.")

    params['ISWIKI'] = opts['wiki']
    read_freesite_cfg(ui_, repo, params, stored_cfg)

    try:
        # --index not required for CHK@
        if not params['SITE_KEY'].startswith('CHK'):
            params['SITE_INDEX'] = int(opts['index'])
            if params['SITE_INDEX'] < 0:
                raise ValueError()
        else:
            params['SITE_INDEX'] = -1
    except ValueError:
        raise util.Abort(MSG_BAD_INDEX)
    except TypeError:
        raise util.Abort(MSG_BAD_INDEX)

    params['DRYRUN'] = opts['dryrun']

    if not params.get('SITE_KEY', None):
        insert_uri = stored_cfg.get_dir_insert_uri(repo.root)
        if not insert_uri:
            ui_.warn("You don't have the insert URI for this repo.\n" +
                     "Supply a private key with --key or fn-push " +
                     "the repo.\n")
            return  # REDFLAG: hmmm... abort?
        params['SITE_KEY'] = 'SSK' + insert_uri.split('/')[0][3:]

    execute_putsite(ui_, repo, params)
Ejemplo n.º 3
0
def execute_wiki_apply(ui_, repo, params, stored_cfg):
    """ Fetch a wiki change submission CHK and apply it to a local
        directory. """
    update_sm = None
    try:
        assert 'REQUEST_URI' in params
        # Get version, i.e. just the hg parent == hg head
        version = get_hg_version(repo)

        # Get target directory.
        params['ISWIKI'] = True
        read_freesite_cfg(ui_, repo, params, stored_cfg)

        update_sm = setup(ui_, repo, params, stored_cfg)

        # Make an FCP download request which will run on the
        # on the state machine.
        request = StatefulRequest(update_sm)
        request.tag = 'submission_zip_request'
        request.in_params.definition = GET_DEF  # To RAM.
        request.in_params.fcp_params = update_sm.params.copy()
        request.in_params.fcp_params['URI'] = params['REQUEST_URI']
        # Knee high barrier against abuse.
        request.in_params.fcp_params['MaxSize'] = FREENET_BLOCK_LEN

        ui_.status("Requesting wiki submission from...\n%s\n" %
                   params['REQUEST_URI'])
        update_sm.start_single_request(request)
        run_until_quiescent(update_sm, params['POLL_SECS'])

        if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))):
            raw_bytes = update_sm.get_state(RUNNING_SINGLE_REQUEST).\
                        final_msg[2]
            assert request.response[0] == 'AllData'
            ui_.status("Fetched %i byte submission.\n" % len(raw_bytes))
            base_ver, submitter = get_info(StringIO.StringIO(raw_bytes))
            ui_.status("Base version: %s, Submitter: %s (unverifiable!)\n" %
                       (base_ver[:12], submitter))

            #print "H_ACKING base_ver to test exception!"
            #base_ver = 'da2f653c5c47b7ee7a814e668aa1d63c50c3a4f3'
            if not has_version(repo, base_ver):
                ui_.warn("That version isn't in the local repo.\n" +
                         "Try running hg fn-pull --aggressive.\n")
                raise util.Abort("%s not in local repo" % base_ver[:12])

            if base_ver != version:
                ui_.warn("Version mismatch! You might have to " +
                         "manually merge.\n")

            # Set up an IFileFunctions that reads the correct versions of
            # the unpatched files out of Mercurial.
            overlay = HgFileOverlay(
                ui_,
                repo,
                # i.e. "<>/wiki_root" NOT "
                # <>/wiki_root/wikitext"
                os.path.join(repo.root, params['WIKI_ROOT']),
                # cleanup() in finally deletes this.
                make_temp_file(update_sm.ctx.bundle_cache.base_dir))
            overlay.version = base_ver
            validate_wikitext(overlay)
            updates = unbundle_wikitext(overlay, StringIO.StringIO(raw_bytes))
            for index, label in enumerate(
                ('CREATED', 'MODIFIED', 'REMOVED', 'ALREADY PATCHED')):
                if len(updates[index]) > 0:
                    values = list(updates[index])
                    values.sort()
                    ui_.status('%s:\n%s\n' % (label, '\n'.join(values)))

    finally:
        cleanup(update_sm)
Ejemplo n.º 4
0
def execute_wiki_submit(ui_, repo, params, stored_cfg):
    """ Insert and overlayed wiki change submission CHK into freenet and
        return a notification message string. """
    update_sm = None
    try:
        # Read submitter out of stored_cfg
        submitter = stored_cfg.defaults.get('FMS_ID', None)
        assert not submitter is None
        assert submitter.find('@') == -1

        # Get version, i.e. just the hg parent == hg head
        version = get_hg_version(repo)

        params['ISWIKI'] = True
        read_freesite_cfg(ui_, repo, params, stored_cfg)
        if not params.get('OVERLAYED', False):
            raise util.Abort("Can't submit from non-overlayed wiki edits!")
        if not params.get('CLIENT_WIKI_GROUP', None):
            # DCI: test code path
            raise util.Abort("No wiki_group in fnwiki.cfg. Don't " +
                             "know where to post to!")

        ui_.status("\nPreparing to submit to %s FMS group as %s.\n" %
                   (params['CLIENT_WIKI_GROUP'], submitter))

        # Create submission zip file in RAM.
        overlay = get_file_funcs(os.path.join(repo.root, params['WIKI_ROOT']),
                                 True)
        try:
            raw_bytes = bundle_wikitext(overlay, version, submitter)
        except NoChangesError:
            raise util.Abort("There are no overlayed changes to submit.")
        # Punt if it's too big.
        if len(raw_bytes) >= FREENET_BLOCK_LEN:
            raise util.Abort("Too many changes. Change .zip must be <32K")

        update_sm = setup(ui_, repo, params, stored_cfg)

        # Make an FCP file insert request which will run on the
        # on the state machine.
        request = StatefulRequest(update_sm)
        request.tag = 'submission_zip_insert'
        request.in_params.definition = PUT_FILE_DEF
        request.in_params.fcp_params = update_sm.params.copy()
        request.in_params.fcp_params['URI'] = 'CHK@'
        request.in_params.send_data = raw_bytes

        ui_.status("Inserting %i byte submission CHK...\n" % len(raw_bytes))
        update_sm.start_single_request(request)
        run_until_quiescent(update_sm, params['POLL_SECS'])

        heads = [hexlify(head) for head in repo.heads()]
        heads.sort()
        if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))):
            chk = update_sm.get_state(RUNNING_SINGLE_REQUEST).\
                  final_msg[1]['URI']
            ui_.status("Patch CHK:\n%s\n" % chk)
            # ':', '|' not in freenet base64
            # DCI: why normalize???
            # (usk_hash, base_version, chk, length)
            ret = ':'.join(
                ('W', normalize(params['REQUEST_URI']), version[:12], chk,
                 str(len(raw_bytes))))

            ui_.status("\nNotification:\n%s\n" % ret + '\n')

            return ret, params['CLIENT_WIKI_GROUP']

        raise util.Abort("Submission CHK insert failed.")

    finally:
        # Cleans up out file.
        cleanup(update_sm)
Ejemplo n.º 5
0
def execute_wiki_submit(ui_, repo, params, stored_cfg):
    """ Insert and overlayed wiki change submission CHK into freenet and
        return a notification message string. """
    update_sm = None
    try:
        # Read submitter out of stored_cfg
        submitter = stored_cfg.defaults.get('FMS_ID', None)
        assert not submitter is None
        assert submitter.find('@') == -1

        # Get version, i.e. just the hg parent == hg head
        version = get_hg_version(repo)

        params['ISWIKI'] = True
        read_freesite_cfg(ui_, repo, params, stored_cfg)
        if not params.get('OVERLAYED', False):
            raise util.Abort("Can't submit from non-overlayed wiki edits!")
        if not params.get('CLIENT_WIKI_GROUP', None):
            # DCI: test code path
            raise util.Abort("No wiki_group in fnwiki.cfg. Don't " +
                             "know where to post to!")

        ui_.status("\nPreparing to submit to %s FMS group as %s.\n" %
                   (params['CLIENT_WIKI_GROUP'], submitter))

        # Create submission zip file in RAM.
        overlay = get_file_funcs(os.path.join(repo.root, params['WIKI_ROOT']),
                                 True)
        try:
            raw_bytes = bundle_wikitext(overlay, version, submitter)
        except NoChangesError:
            raise util.Abort("There are no overlayed changes to submit.")
        # Punt if it's too big.
        if len(raw_bytes) >= FREENET_BLOCK_LEN:
            raise util.Abort("Too many changes. Change .zip must be <32K")

        update_sm = setup(ui_, repo, params, stored_cfg)

        # Make an FCP file insert request which will run on the
        # on the state machine.
        request = StatefulRequest(update_sm)
        request.tag = 'submission_zip_insert'
        request.in_params.definition = PUT_FILE_DEF
        request.in_params.fcp_params = update_sm.params.copy()
        request.in_params.fcp_params['URI'] = 'CHK@'
        request.in_params.send_data = raw_bytes

        ui_.status("Inserting %i byte submission CHK...\n" % len(raw_bytes))
        update_sm.start_single_request(request)
        run_until_quiescent(update_sm, params['POLL_SECS'])

        heads = [hexlify(head) for head in repo.heads()]
        heads.sort()
        if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING,))):
            chk = update_sm.get_state(RUNNING_SINGLE_REQUEST).\
                  final_msg[1]['URI']
            ui_.status("Patch CHK:\n%s\n" %
                       chk)
            # ':', '|' not in freenet base64
            # DCI: why normalize???
            # (usk_hash, base_version, chk, length)
            ret = ':'.join(('W',
                            normalize(params['REQUEST_URI']),
                            version[:12],
                            chk,
                            str(len(raw_bytes))))

            ui_.status("\nNotification:\n%s\n" % ret
                        + '\n')

            return ret, params['CLIENT_WIKI_GROUP']

        raise util.Abort("Submission CHK insert failed.")

    finally:
        # Cleans up out file.
        cleanup(update_sm)
Ejemplo n.º 6
0
def execute_wiki_apply(ui_, repo, params, stored_cfg):
    """ Fetch a wiki change submission CHK and apply it to a local
        directory. """
    update_sm = None
    try:
        assert 'REQUEST_URI' in params
        # Get version, i.e. just the hg parent == hg head
        version = get_hg_version(repo)

        # Get target directory.
        params['ISWIKI'] = True
        read_freesite_cfg(ui_, repo, params, stored_cfg)

        update_sm = setup(ui_, repo, params, stored_cfg)

        # Make an FCP download request which will run on the
        # on the state machine.
        request = StatefulRequest(update_sm)
        request.tag = 'submission_zip_request'
        request.in_params.definition = GET_DEF # To RAM.
        request.in_params.fcp_params = update_sm.params.copy()
        request.in_params.fcp_params['URI'] = params['REQUEST_URI']
        # Knee high barrier against abuse.
        request.in_params.fcp_params['MaxSize'] = FREENET_BLOCK_LEN

        ui_.status("Requesting wiki submission from...\n%s\n" %
                   params['REQUEST_URI'])
        update_sm.start_single_request(request)
        run_until_quiescent(update_sm, params['POLL_SECS'])

        if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING,))):
            raw_bytes = update_sm.get_state(RUNNING_SINGLE_REQUEST).\
                        final_msg[2]
            assert request.response[0] == 'AllData'
            ui_.status("Fetched %i byte submission.\n" % len(raw_bytes))
            base_ver, submitter = get_info(StringIO.StringIO(raw_bytes))
            ui_.status("Base version: %s, Submitter: %s (unverifiable!)\n"
                       % (base_ver[:12], submitter))

            #print "H_ACKING base_ver to test exception!"
            #base_ver = 'da2f653c5c47b7ee7a814e668aa1d63c50c3a4f3'
            if not has_version(repo, base_ver):
                ui_.warn("That version isn't in the local repo.\n" +
                         "Try running hg fn-pull --aggressive.\n")
                raise util.Abort("%s not in local repo" % base_ver[:12])

            if base_ver != version:
                ui_.warn("Version mismatch! You might have to " +
                         "manually merge.\n")

            # Set up an IFileFunctions that reads the correct versions of
            # the unpatched files out of Mercurial.
            overlay = HgFileOverlay(ui_, repo,
                                    # i.e. "<>/wiki_root" NOT "
                                    # <>/wiki_root/wikitext"
                                    os.path.join(repo.root,
                                                 params['WIKI_ROOT']),
                                    # cleanup() in finally deletes this.
                                    make_temp_file(update_sm.ctx.
                                                   bundle_cache.base_dir))
            overlay.version = base_ver
            validate_wikitext(overlay)
            updates = unbundle_wikitext(overlay,
                                        StringIO.StringIO(raw_bytes))
            for index, label in enumerate(('CREATED', 'MODIFIED', 'REMOVED',
                                           'ALREADY PATCHED')):
                if len(updates[index]) > 0:
                    values = list(updates[index])
                    values.sort()
                    ui_.status('%s:\n%s\n' % (label, '\n'.join(values)))

    finally:
        cleanup(update_sm)