zensols.zotsite package#

Submodules#

zensols.zotsite.app#

Inheritance diagram of zensols.zotsite.app

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

class zensols.zotsite.app.Application(site_creator, prune_pattern=None)[source]#

Bases: object

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

__init__(site_creator, prune_pattern=None)#
export(output_dir=None, show=False)[source]#

Generate and export the Zotero website.

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

  • show (bool) – whether to browse to the created site (needs pip install zensols.showfile)

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.

site_creator: SiteCreator#

Creates the Zotero content web site.

zensols.zotsite.betterbib#

Inheritance diagram of zensols.zotsite.betterbib

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.cli#

Inheritance diagram of zensols.zotsite.cli

Command line entry point to the application.

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

Bases: ApplicationFactory

__init__(*args, **kwargs)[source]#
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#

Inheritance diagram of zensols.zotsite.db

Contains access to the Zotero SQLite database.

class zensols.zotsite.db.DatabaseReader(data_dir, collection_like='%', library_id=1)[source]#

Bases: object

Database access to Zotero store.

__init__(data_dir, collection_like='%', library_id=1)#
collection_like: str = '%'#

The SQL pattern to match against subcollection names.

data_dir: Path#

Directory containing the Zotero DB files (sqlite and collections).

get_connection()[source]#

Return a database connection the SQLite database.

get_library()[source]#

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

Return type:

Library

library_id: int = 1#

The DB ide of the library to export.

zensols.zotsite.domain#

Inheritance diagram of zensols.zotsite.domain

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.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#

Inheritance diagram of zensols.zotsite.fscpvisitor

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 DatabaseReader.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#

Inheritance diagram of zensols.zotsite.itemmap

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#

Inheritance diagram of zensols.zotsite.navvisitor

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:
  • lib (Library) – the object graph returned from DatabaseReader.get_library.

  • item_mapper (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.

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#

Inheritance diagram of zensols.zotsite.prunevisitor

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#

Inheritance diagram of zensols.zotsite.screate

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: DatabaseReader#

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.

tmp()[source]#
property walker: Walker#

Module contents#