Projects

The Project object is used to represent a project.xml file. Example usage:

>>> from bkgen.project import Project
>>> fn = '/path/to/Project-Folder/project.xml'
>>> project = Project(fn=fn)

Now all of the methods of the project can be called.

class bkgen.project.Project(**args)[source]

Bases: bxml.xml.XML, bkgen.source.Source

Every project has a project.xml file that holds information about the project. The root element is pub:project, where pub: is the Publishing XML namespace (see publishingxml.org).

OUTPUT_KINDS = {‘EPUB’: ‘.epub’, ‘Kindle’: ‘.mobi’}

The kinds of outputs that are currently supported.

ROOT_TAG = ‘{http://publishingxml.org/ns}project’

The tag for the root element of a project.

add_resource(href, resource_class, kind=None)[source]

add the given resource to the project file, if it isn’t already present

build_archive()[source]

create a zip archive of the project folder itself

build_epub(clean=True, show_nav=False, zip=True, check=True, cleanup=False, before_compile=None, **image_args)[source]
build_mobi(clean=True, cleanup=False, before_compile=None, **image_args)[source]
build_outputs(kind=None, cleanup=True, before_compile=None)[source]

build the project outputs kind=None: which kind of output to build; if None, build all

content_path
cover_path
classmethod create(parent_path, title, name=None, **project_params)[source]
create a new project.
parent_path = the filesystem path to the parent folder that this project is in title = the title for the project name = the name of the project, which becomes its folder name and URL slug project_params = parameters passed to the Project.__init__()

Returns the Project XML object.

documents()[source]

all of pub:document files in the content subfolder.

get_cover_href(kind=’digital’)[source]
image_path
images()[source]

all of the image files in the content subfolder.

import_documents(documents)[source]

import the given document collection. This includes (1) storing the document in the project.content_folder (2) adding sections of the document to the spine, if not present

import_image(fn, **params)[source]

import the image from a local file. Process through GraphicsMagick to ensure clean.

import_images(images)[source]
import_metadata(metadata)[source]

import the metadata found in the Metadata XML object

import_source(source, documents=True, images=True, stylesheet=True, metadata=False, **params)[source]

import a source into the project. source = a Source object that contains the content source documents = whether to import documents from the source images = whether to import images from the source stylesheet = whether to import a stylesheet from the source metadata = whether to import metadata from the source **params = passed to the Source.documents(**params) method

import_source_file(fn, **args)[source]

import the source fn. fn = the filesystem path to the file (such as a temporary file location) args = arguments that will be passed to Project.import_source()

interior_path
metadata()[source]

metadata is kept in the project.xml opf:metadata block.

name
output_image(fn, output_path=None, outfn=None, format=’jpeg’, ext=’.jpg’, res=300, quality=80, maxwh=2048, maxpixels=4000000.0)[source]
output_kinds
output_path
output_resources(output_path=None, **image_args)[source]
output_spineitems(output_path=None, ext=’.xhtml’, resources=None, http_equiv_content_type=False, canonicalized=False, **image_args)[source]
output_stylesheet(fn, output_path=None)[source]
path
resources()[source]
stylesheet()[source]

the master .css for this project is the resource class=”stylesheet”.

bkgen.project.build_project(project_path, format=None)[source]
bkgen.project.cleanup_project(project_path)[source]
bkgen.project.import_all(project_path)[source]

import sources, cover, and metadata into project

bkgen.project.remove_project(project_path)[source]
bkgen.project.zip_project(project_path)[source]