Ejemplo n.º 1
0
def build_page(queue_entry, async_write=False):
    try:
        fileinfo = FileInfo.get(FileInfo.id == queue_entry.data_integer)
        blog = queue_entry.blog
        page_tags = generate_page_tags(fileinfo, blog)
        file_page_text = generate_page_text(fileinfo, page_tags)
        if async_write:
            if not t.is_alive:
                t.target = write_file_queue
                t.args = (write_queue, )
                t.start()
            write_queue.put_nowait(
                (file_page_text, blog.path, fileinfo.file_path))
        else:
            write_file(file_page_text, blog.path, fileinfo.file_path)

    except FileInfo.DoesNotExist as e:
        raise Exception('''Fileinfo {} could not be found in the system.
It may refer to a fileinfo that was deleted by another action. ({})'''.format(
            queue_entry.data_integer, e))

    except NoArchiveForFileInfo:
        logger.info(
            "Fileinfo {} has no corresponding pages. File {} removed.".format(
                fileinfo.id, fileinfo.file_path))
        delete_fileinfo_files((fileinfo, ))
        # fileinfo.delete_instance(recursive=True)
        # FIXME: for now we leave this out
        # because deletes do not coalesce properly in the queue (I think)

    except Exception as e:
        context_list = [(f.object, f.ref) for f in fileinfo.context]
        raise Exception('Error building fileinfo {} ({},{},{}): {}'.format(
            fileinfo.id, fileinfo.page, context_list, fileinfo.file_path, e))
Ejemplo n.º 2
0
def build_page(q):
    '''
    Builds the file for a single blog page, q, based on its fileinfo data.
    '''
    fileinfo = FileInfo.get(FileInfo.id == q.data_integer)
    try:
        build_file(fileinfo, q.blog)
    except BaseException:
        raise
Ejemplo n.º 3
0
def preview(path):

    page = FileInfo.get(FileInfo.url == path)

    # return template mapping if no page found

    # prefix urls in preview for virtual filesystem movement

    return ui.page_preview(page.page.id)
Ejemplo n.º 4
0
def push_to_queue(**ka):
    '''
    Inserts a single job item into the work queue.

    :param job_type:
        A string representing the type of job to be inserted.
        'Page','Index', eventually 'Fileinfo'

    :param data_integer:
        Any integer data passed along with the job. For a job control item, this
        is the number of items remaining for that particular job.

    :param blog:
        The blog object associated with the job.

    :param site:
        The site object associated with the job.

    :param priority:
        An integer, from 0-9, representing the processing priority associated with the job.
        Higher-priority jobs are processed first. Most individual pages are given a high
        priority; indexes are lower.
    '''

    try:
        queue_job = Queue.get(Queue.job_type == ka['job_type'],
                              Queue.data_integer == ka['data_integer'],
                              Queue.blog == ka['blog'],
                              Queue.site == ka['site'])
    except Queue.DoesNotExist:
        queue_job = Queue()
    else:
        return

    queue_job.job_type = ka['job_type']
    queue_job.data_integer = int(ka.get('data_integer', None))
    queue_job.blog = ka.get('blog', Blog()).id
    queue_job.site = ka.get('site', Site()).id
    queue_job.priority = ka.get('priority', 9)
    queue_job.is_control = ka.get('is_control', False)

    if queue_job.is_control:
        queue_job.data_string = (queue_job.job_type +
                                 ": Blog {}".format(queue_job.blog.for_log))
    else:
        queue_job.data_string = (
            queue_job.job_type + ": " +
            FileInfo.get(FileInfo.id == queue_job.data_integer).file_path)

    queue_job.date_touched = datetime.datetime.now()
    queue_job.save()
Ejemplo n.º 5
0
def queue_page_archive_actions(page):
    '''
    Pushes to the publishing queue all the page archives for a given page object.
    '''

    archive_templates = page.blog.archive_templates
    tags = template_tags(page_id=page.id)

    for n in archive_templates:
        for m in n.mappings:

            file_path = (page.blog.path + '/' + generate_date_mapping(
                page.publication_date.date(), tags, m.path_string))

            fileinfo_mapping = FileInfo.get(
                FileInfo.sitewide_file_path == file_path)

            push_to_queue(job_type=job_type.archive,
                          blog=page.blog,
                          site=page.blog.site,
                          data_integer=fileinfo_mapping.id)
Ejemplo n.º 6
0
def add_page_fileinfo(page,
                      template_mapping,
                      file_path,
                      url,
                      sitewide_file_path,
                      mapping_sort=None):
    '''
    Add a given page (could also be an index) to the fileinfo index.
    Called by the page builder routines.
    '''
    try:
        existing_fileinfo = FileInfo.get(
            FileInfo.sitewide_file_path == sitewide_file_path,
            FileInfo.template_mapping == template_mapping)

    except FileInfo.DoesNotExist:

        new_fileinfo = FileInfo.create(page=page,
                                       template_mapping=template_mapping,
                                       file_path=file_path,
                                       sitewide_file_path=sitewide_file_path,
                                       url=url,
                                       mapping_sort=mapping_sort)

        fileinfo = new_fileinfo

    else:

        existing_fileinfo.file_path = file_path
        existing_fileinfo.sitewide_file_path = sitewide_file_path
        existing_fileinfo.url = url
        existing_fileinfo.modified_date = datetime.datetime.now()
        existing_fileinfo.mapping_sort = mapping_sort
        existing_fileinfo.save()

        fileinfo = existing_fileinfo

    return fileinfo
Ejemplo n.º 7
0
def build_page(queue_entry, async_write=False):
    try:
        fileinfo = FileInfo.get(FileInfo.id == queue_entry.data_integer)
        blog = queue_entry.blog
        page_tags = generate_page_tags(fileinfo, blog)
        file_page_text = generate_page_text(fileinfo, page_tags)
        if async_write:
            if not t.is_alive:
                t.target = write_file_queue
                t.args = (write_queue,)
                t.start()
            write_queue.put_nowait((file_page_text, blog.path, fileinfo.file_path))
        else:
            write_file(file_page_text, blog.path, fileinfo.file_path)

    except FileInfo.DoesNotExist as e:
        raise Exception('''Fileinfo {} could not be found in the system.
It may refer to a fileinfo that was deleted by another action. ({})'''.format(queue_entry.data_integer, e))

    except NoArchiveForFileInfo:
        logger.info("Fileinfo {} has no corresponding pages. File {} removed.".format(
            fileinfo.id,
            fileinfo.file_path)
            )
        delete_fileinfo_files((fileinfo,))
        # fileinfo.delete_instance(recursive=True)
        # FIXME: for now we leave this out
        # because deletes do not coalesce properly in the queue (I think)

    except Exception as e:
        context_list = [(f.object, f.ref) for f in fileinfo.context]
        raise Exception('Error building fileinfo {} ({},{},{}): {}'.format(
            fileinfo.id,
            fileinfo.page,
            context_list,
            fileinfo.file_path,
            e))
Ejemplo n.º 8
0
def add_page_fileinfo(page, template_mapping, file_path,
        url, sitewide_file_path, mapping_sort=None):
    '''
    Add a given page (could also be an index) to the fileinfo index.
    If the page already exists, then the existing fileinfo
    is updated with the new information.

    Called by the page builder routines.

    :param page:
        The page object to add to the fileinfo index.
    :param template_mapping:
        The template mapping to use for creating the page's fileinfo(s).
    :param file_path:
        The file path to use for the fileinfo.
    :param url:
        The URL to associate with the fileinfo.
    :param sitewide_file_path:
        The sitewide file path to use for the fileinfo.
    :param mapping_sort:
        Sort order for the mapping, if used.
    '''
    try:
        existing_fileinfo = FileInfo.get(
            FileInfo.sitewide_file_path == sitewide_file_path,
            FileInfo.template_mapping == template_mapping
            )

    except FileInfo.DoesNotExist:

        try:

            new_fileinfo = FileInfo.create(page=page,
                template_mapping=template_mapping,
                file_path=file_path,
                sitewide_file_path=sitewide_file_path,
                url=url,
                mapping_sort=mapping_sort)

            fileinfo = new_fileinfo

        except IntegrityError:

            from core.error import FileInfoCollision
            collision = FileInfo.get(
                FileInfo.sitewide_file_path == sitewide_file_path)
            raise FileInfoCollision('''
Template mapping #{}, {}, for template #{},
yields a path that already exists in the system: {}
This appears to be a collision with mapping {} in template {}'''.format(
                template_mapping.id,
                template_mapping.path_string,
                template_mapping.template.id,
                sitewide_file_path,
                collision.template_mapping.path_string,
                collision.template_mapping.template.for_log))

    else:

        existing_fileinfo.file_path = file_path
        existing_fileinfo.sitewide_file_path = sitewide_file_path
        existing_fileinfo.url = url
        existing_fileinfo.modified_date = datetime.datetime.utcnow()
        existing_fileinfo.mapping_sort = mapping_sort
        existing_fileinfo.save()

        fileinfo = existing_fileinfo

    return fileinfo
Ejemplo n.º 9
0
def preview(path):
    from core.ui import page
    preview_page = FileInfo.get(
        FileInfo.url == path)
    return page.page_preview(preview_page.page.id)
Ejemplo n.º 10
0
def preview(path):
    from core.ui import page
    preview_page = FileInfo.get(FileInfo.url == path)
    return page.page_preview(preview_page.page.id)