Пример #1
0
    def get_write_overlay(cls, repo):
        base_dir = os.path.join(repo.root, DEFAULT_WIKI_ROOT)
        base_dir = os.path.join(repo.root, base_dir)
        filefuncs = get_file_funcs(base_dir, True)
        text_dir = os.path.join(base_dir, 'wikitext')
        full_path = filefuncs.overlay_path(text_dir)
        if not os.path.exists(full_path):
            os.makedirs(full_path)

        return filefuncs
Пример #2
0
def reset_root_dir(root_dir, overlayed=False):
    global data_dir, text_dir, filefuncs
    if not os.path.exists(root_dir) or not os.path.isdir(root_dir):
        raise IOError("Base wiki dir doesn't exist: %s" % root_dir)

    data_dir = root_dir
    text_dir = path.join(root_dir, 'wikitext')
    if not os.path.exists(text_dir) or not os.path.isdir(text_dir):
        raise IOError("Wikitext dir doesn't exist: %s" % text_dir)

    cgi.logfile = path.join(data_dir, 'cgi_log')
    filefuncs = fileoverlay.get_file_funcs(root_dir, overlayed)
    if overlayed:
        # Only overlay 'wikitext', not 'www'
        full_path = filefuncs.overlay_path(text_dir)
        if not os.path.exists(full_path):
            os.makedirs(full_path)
Пример #3
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)
Пример #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)