zensols.zotsite package

Submodules

zensols.zotsite.app module

This project exports your local Zotero library to a usable HTML website.

class zensols.zotsite.app.CiteApplication(resource)[source]

Bases: _Application

Map Zotero keys to BetterBibtex citekeys.

__init__(resource)
citekey(format=None, key=None)[source]

Look up a citation key and print out BetterBibtex field(s) with default {itemKey}={citationKey} for format.

Parameters:
  • key (str) – key in format <library ID>_<item key>, standard input if not given, or all for every entry

  • format (str) – the format of the output or json for all fields

class zensols.zotsite.app.ExportApplication(resource, prune_pattern=None)[source]

Bases: _Application

This project exports your local Zotero library to a usable HTML website.

__init__(resource, prune_pattern=None)
export(output_dir=None)[source]

Generate and export the Zotero website.

Parameters:

output_dir (Path) – the directory to dump the site; default to configuration file

print_structure()[source]

Print (sub)collections and papers in those collections as a tree.

prune_pattern: str = None

A regular expression used to filter Collection nodes.

property site_creator: SiteCreator
class zensols.zotsite.app.PrototypeApplication(config_factory)[source]

Bases: object

CLI_META = {'is_usage_visible': False}
__init__(config_factory)
config_factory: ConfigFactory
proto()[source]
class zensols.zotsite.app.QueryApplication(resource)[source]

Bases: _Application

Query the Zotero database.

__init__(resource)
find_path(format=None, key=None)[source]

Output paths with default {itemKey}={path} for format.

Parameters:
  • format (str) – the format of the output or json for all fields

  • key (str) – key in format <library ID>_<item key>, standard input if not given, or all for every entry

class zensols.zotsite.app.Resource(zotero_db, cite_db, site_creator)[source]

Bases: object

Zotsite first class objects.

__init__(zotero_db, cite_db, site_creator)
cite_db: CiteDatabase

Maps Zotero keys to BetterBibtex citekeys.

site_creator: SiteCreator

Creates the Zotero content web site.

zotero_db: ZoteroDatabase

The database access object.

zensols.zotsite.betterbib module

A class that replaces item IDs with BetterBibtex IDs

class zensols.zotsite.betterbib.BetterBibtexMapper(lib)[source]

Bases: object

Read the BetterBibtex database and create a mapping from item DB ids to citation keys.

__init__(lib)[source]
property mapping: Dict[str, Any]
class zensols.zotsite.betterbib.BetterBibtexVisitor(lib)[source]

Bases: Visitor

Use the BetterBibtexMapper to change the keys in mapped items to the respective citation keys.

__init__(lib)[source]
enter_parent(parent)[source]

Template method for traversing down/into a node.

leave_parent(parent)[source]

Template method for traversing up/out of a node.

visit_child(child)[source]

Template method for visiting a node.

zensols.zotsite.cite module

Query Zotero collections metadata.

class zensols.zotsite.cite.CiteDatabase(_persister, _sql)[source]

Bases: object

Map Zotero keys to BetterBibtex citekeys.

__init__(_persister, _sql)
property entries: Dict[str, Dict[str, Any]]

Get all entries from the BetterBibtex database with <libraryID>_<itemKey> as keys and the dict entry as values.

zensols.zotsite.cli module

Command line entry point to the application.

class zensols.zotsite.cli.ApplicationFactory(*args, **kwargs)[source]

Bases: ApplicationFactory

__init__(*args, **kwargs)[source]
classmethod get_resource()[source]

Contains programatic resources (citation) queries and the website creation.

Return type:

Resource

zensols.zotsite.cli.main(args=['/Users/landes/opt/lib/python/bin/sphinx-build', '-M', 'html', '/Users/landes/view/util/zotsite/target/doc/src', '/Users/landes/view/util/zotsite/target/doc/build'], **kwargs)[source]
Return type:

ActionResult

zensols.zotsite.db module

Data access objects to the Zotero SQLite database.

class zensols.zotsite.db.ZoteroDatabase(_persister, _data_dir, _collection_like, _library_id)[source]

Bases: object

Provides access to data from the Zotero database.

__init__(_persister, _data_dir, _collection_like, _library_id)
get_library(**kwargs) Library

Get an object graph representing the data in the Zotero database.

Return type:

Library

property item_paths: Dict[str, Path]

Get paths only for this library.

See:

paths

property library_id: int

zensols.zotsite.domain module

Contains domain and visitor (GoF pattern) classes.

class zensols.zotsite.domain.Collection(sel, items, collections)[source]

Bases: Container

Represents a (sub)collection, which is a container for other collections and items.

__init__(sel, items, collections)[source]
get_id()[source]
property name
class zensols.zotsite.domain.CollectionVisitor(predicate)[source]

Bases: Visitor

A visitor that prints items for debugging.

__init__(predicate)[source]
enter_parent(parent)[source]

Template method for traversing down/into a node.

leave_parent(parent)[source]

Template method for traversing up/out of a node.

visit_child(child)[source]

Template method for visiting a node.

class zensols.zotsite.domain.Container(items, collections)[source]

Bases: ZoteroObject

Container class holds items and sub-collections.

__init__(items, collections)[source]
property children
class zensols.zotsite.domain.Item(sel, children)[source]

Bases: ZoteroObject

Represents an attachement object, like PDFs, site links etc.

__init__(sel, children)[source]
property creators: (<class 'list'>, <class 'zensols.zotsite.domain.Name'>)
get_db_id()[source]
get_id()[source]
property metadata
property name
property path
set_id(id)[source]
class zensols.zotsite.domain.Library(data_dir, library_id, collections)[source]

Bases: Container

Represents the top level object that contains the root level collections.

__init__(data_dir, library_id, collections)[source]
attachment_resource(item)[source]
get_id()[source]
get_storage_path(fname=None)[source]
property name
property title
class zensols.zotsite.domain.Name(first, last)[source]

Bases: object

__init__(first, last)[source]
class zensols.zotsite.domain.Note(sel)[source]

Bases: ZoteroObject

Represents a note Zotero data object.

__init__(sel)[source]
get_id()[source]
property name
property title
class zensols.zotsite.domain.PrintVisitor(writer)[source]

Bases: Visitor

A visitor that prints items for debugging.

__init__(writer)[source]
enter_parent(parent)[source]

Template method for traversing down/into a node.

leave_parent(parent)[source]

Template method for traversing up/out of a node.

visit_child(child)[source]

Template method for visiting a node.

class zensols.zotsite.domain.SortedWalker(key_fn=None, reverse=False)[source]

Bases: Walker

Iterates through the Zotero visiting children in sorted order.

__init__(key_fn=None, reverse=False)[source]

Initialize.

Parameters:
  • key_fn (Callable) – a function/callable used to sort the data that takes a single argument to access compared data, which defaults to :function:`str`

  • reverse (bool) – whether or not to reverse the visited results

walk(parent, visitor)[source]

Recursively traverse the object graph.

class zensols.zotsite.domain.UnsortedWalker[source]

Bases: Walker

Iterates through the Zotero visiting children in whatever order is provided by the database.

walk(parent, visitor)[source]

Recursively traverse the object graph.

class zensols.zotsite.domain.Visitor[source]

Bases: ABC

The visitor in the GoF visitor pattern.

abstract enter_parent(parent)[source]

Template method for traversing down/into a node.

abstract leave_parent(parent)[source]

Template method for traversing up/out of a node.

abstract visit_child(child)[source]

Template method for visiting a node.

class zensols.zotsite.domain.Walker[source]

Bases: ABC

Iterates the Zotero data and calls the visitor for each node.

abstract walk(parent, visitor)[source]

Recursively traverse the object graph.

exception zensols.zotsite.domain.ZoteroApplicationError[source]

Bases: ApplicationError

Thrown for application errors meant to be reported by the command line.

__module__ = 'zensols.zotsite.domain'
class zensols.zotsite.domain.ZoteroObject(children)[source]

Bases: ABC

Represents any collection, item etc. Zotero data object.

__init__(children)[source]
property children
abstract get_id()[source]
property id
property note
short_title(str_len)[source]

Return the short name of this object.

property title
property type

Return the type this item is.

zensols.zotsite.fscpvisitor module

Contains a class to copy files from the package resource location to the target website path.

class zensols.zotsite.fscpvisitor.FileSystemCopyVisitor(lib, out_dir, robust, itemmapper)[source]

Bases: Visitor

This class copies all Item objects to their destination.

__init__(lib, out_dir, robust, itemmapper)[source]

Initialize the visitor object.

Parameters:
  • lib (Library) – the object graph returned from ZoteroDatabase.get_library()

  • out_dir (Path) – the target directory to copy data

  • robust (bool) – whether to raise an exception on file system errors

  • itemmapper (ItemMapper) – used for file name substitution so the widget uses the correct names (i.e. underscore substitution)

enter_parent(parent)[source]

Template method for traversing down/into a node.

leave_parent(parent)[source]

Template method for traversing up/out of a node.

visit_child(child)[source]

Template method for visiting a node.

zensols.zotsite.itemmap module

Contains classes that map Item unique identifiers.

class zensols.zotsite.itemmap.IdItemMapper(lib, fmatch_re=None, repl_re=None)[source]

Bases: ItemMapper

Map by using item IDs.

__init__(lib, fmatch_re=None, repl_re=None)[source]
get_file_name(item)[source]

Return a file path used on the browser side for item.

Return type:

str

get_resource_name(item)[source]

Return a resource used on the browser side for item.

Return type:

str

class zensols.zotsite.itemmap.ItemMapper[source]

Bases: ABC

Maps Item unique identifiers.

EXT_RE = re.compile('.+\\.(.+)?$')
abstract get_file_name(item)[source]

Return a file path used on the browser side for item.

Return type:

str

abstract get_resource_name(item)[source]

Return a resource used on the browser side for item.

Return type:

str

class zensols.zotsite.itemmap.RegexItemMapper(lib, fmatch_re=None, repl_re=None)[source]

Bases: ItemMapper

Map by using regular expression replacements.

__init__(lib, fmatch_re=None, repl_re=None)[source]
get_file_name(item)[source]

Return a file path used on the browser side for item.

Return type:

str

get_resource_name(item)[source]

Return a resource used on the browser side for item.

Return type:

str

zensols.zotsite.navvisitor module

Contains the class that generates the website navigation data structure.

class zensols.zotsite.navvisitor.NavCreateVisitor(lib, item_mapper)[source]

Bases: Visitor

This class creates the data structure used by the Javascript navigation widget in the created website.

See:

Bootstrap Glyphicons

CAPS_META_KEYS = {'url'}
ITEM_ICONS = {'attachment': 'paperclip', 'blogPost': 'pencil', 'book': 'book', 'bookSection': 'book', 'computerProgram': 'floppy-disk', 'conferencePaper': 'file', 'dataset': 'oil', 'journalArticle': 'file', 'patent': 'certificate', 'preprint': 'log-in', 'report': 'font', 'thesis': 'education', 'webpage': 'bookmark'}
PDF_EXT_REGEXP = re.compile('.*\\.pdf$')
PDF_FULL_REGEXP = re.compile('^.*Full\\s*[tT]ext PDF')
UPPER = re.compile('([A-Z][a-z]+)')
__init__(lib, item_mapper)[source]

Initialize the visitor object.

Parameters:
enter_parent(parent)[source]

Template method for traversing down/into a node.

icon_name(node)[source]

Return the name of the icon name for node.

Return type:

str

leave_parent(parent)[source]

Template method for traversing up/out of a node.

property primary_roots: List[Dict[str, Any]]

The (root level) collections.

visit_child(child)[source]

Template method for visiting a node.

zensols.zotsite.prunevisitor module

A class that prunes collections based on a regular expression.

class zensols.zotsite.prunevisitor.PruneVisitor(prune_pattern=None, match_children=False)[source]

Bases: Visitor

This that filters out Collection instances based on a regular expression. Optionally, Item level nodes are included if based on match_children.

__init__(prune_pattern=None, match_children=False)
enter_parent(parent)[source]

Template method for traversing down/into a node.

leave_parent(parent)[source]

Template method for traversing up/out of a node.

match_children: bool = False

if True, then also match Item level nodes.

prune_pattern: Union[Pattern, str] = None

A regular expression used to filter Collection nodes.

property should_walk: bool
visit_child(child)[source]

Template method for visiting a node.

zensols.zotsite.screate module

Generates the the static HTML pages that make up the Zotero exported website.

class zensols.zotsite.screate.SiteCreator(config_factory, package, site_resource, db, prune_visitor, sort_walkers, sort='none', id_mapping='none', file_mapping='item', out_dir=None, robust_fs=False)[source]

Bases: object

Creates the Zotero content web site.

__init__(config_factory, package, site_resource, db, prune_visitor, sort_walkers, sort='none', id_mapping='none', file_mapping='item', out_dir=None, robust_fs=False)
config_factory: ConfigFactory

The configuration factory used to create the Walker instance.

db: ZoteroDatabase

The database access object.

export()[source]

Entry point method to export (create) the website.

file_mapping: str = 'item'

Whether to use unique item IDs for the file names or the full PDF file name; either: item or long

id_mapping: bool = 'none'

How to generate unique identifiers for URLS, either none, or betterbib`.

property item_mapper
property library: Library
out_dir: Path = None

The default output directory to store the collection.

package: Settings

Containes this Python package information used to create the site metadata.

print_structure(writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Print (sub)collections and papers in those collections as a tree.

prune_visitor: PruneVisitor

A visitor that prunes collections based on a regular expression.

robust_fs: bool = False

Whether to raise an exception on file system errors.

site_resource: Path

The (resource) path the static site files.

sort: str = 'none'

none or case (non-case might be added later).

Type:

whether or not to sort items, either

sort_walkers: Settings

A mapping of name to a Walker instance definition configuration section.

property walker: Walker

Module contents