publi module

A program to build, update, export publications

class publi.PublicationDatabase(database_file=None, pdf_dir=None, prefix=None)[source]

Bases: object

Class to hold information about publication lists

add_bibdata(entries)[source]

Add several entries to the database.

Parameters:entries (str or pybtex.database.BibliographyData. If a string is passed it will be treated as the name of a BibTeX file.) – Entries to add
add_entry(key, entry)[source]

Add an entry to the database.

Parameters:
  • key (str) – Key of the new entry. Will be disambiguated before insertion
  • entry (pybtex.database.Entry) – Entry to add
classmethod default_comparator(item1, item2)[source]

Default comparator for bibliograpyh items.This function will first compare the keys and then check whether both entries have a title field and if so, check whether their values are similar according to a ratio computed with difflib.SequenceMatcher. Equality is assumed if r>=0.8

Parameters:
  • cls (class) – Class object
  • item1 (tuple) – First bibliography item
  • item2 (tuple) – Second bibliography item
Returns:

Whether the two are duplicates or not

Return type:

bool

delete(key)[source]
Parameters:key (str) – Bibliography key to delete
find_duplicates(comparator=None)[source]

Find suspected duplicates.

Parameters:comparator (function (see default_comparator())) – binary function to determine whether two bib items (of type (str, pybtex.database.Entry)) are identical
iter_entries(predicate=None)[source]

Create and iterator for filtering entries.

Parameters:
  • predicate – Filter function to use. If None, all entries will be included.
  • predicate – function
load()[source]

Deserialize self from pickled file named db.pckl.

populate(database_file, pdf_dir)[source]

Collect all bibdata from all files into one big-ass database (self), rekeying the entries. This method will also set publipy_biburl, publipy_abstracturl, and publipy_pdfurl attributes on the entries. Pdf files are copied to pdf_dir/pdf.

Parameters:
  • database_file (str) – File containing all bibliography data
  • pdf_dir (str) – Directory filled with pdfs named by their bibliography keys
publications_for_member(member)[source]

Get all publications the given person is involved in. Currently not implemented

Parameters:member (str or pybtex.database.Person) – Relevant person
Returns:Iterator
publications_for_type(type)[source]

Get all publications of the given kind (book, article, inproceedings..).

Parameters:type (str) – Desired type
Returns:Iterator
publications_for_year(min_year, max_year)[source]

Get all publications between two years (inclusive)

Parameters:
  • min_year (str or int) – Minimum allowed year
  • max_year (str or int) – Maximum allowed year
Returns:

Iterator

Raises:

ValueError if min_year >= max_year

save()[source]

Serialize self to pickled file named db.pckl for caching and update the PublicationDatabase.database_file with all entries. Also, directories abstract, pdf and bib are created under PublicationDatabase.prefix which are filled with one file per key each – one for a BibTeX file with the single entry, one text file for the abstract (if present in the entry) and one pdf file (if a pdf named like the entry’s key was found in the pdf_dir parameter passed to PublicationDatabase.populate())

publi.add(args)[source]

Add item(s) to the database. Uses the entries field from the arguments.

Parameters:args (argparse.Namespace) – Command line arguments obtained via argparse.ArgumentParser’s argparse.ArgumentParser.parse_args() method.
publi.build(args)[source]

Build and save a PublicationDatabase from the arguments passed.

Parameters:args (argparse.Namespace) – argparse.Namespace object obtained via argparse.ArgumentParser’s argparse.ArgumentParser.parse_args() method.
publi.check_validity(entry)[source]

Currently unimplemented.

publi.disambiguate(key, keyset)[source]

Disambiguate key over set of keys by successively appending more alphanumeric numbers.

See generate_suffix()

publi.filtered_entries(database, args)[source]

Get a PublicationDatabase containing only selected entries. Will read out the person, expr, and mytype filters from the arguments. Only entries meeting all criteria are selected.

Parameters:
publi.generate_key_bibtool(entry)[source]

Generate a key like bibtool would create with the following options

  • key.base=lower
  • key.format=short
Parameters:entry (pybtex.database.Entry) – Entry to key
Returns:The new key
Return type:str
publi.generate_key_swe(entry)[source]

Create a new bibtex key for the given entry in the format desired by the group leader. The format is <first author>:<first title word>:yy. Stop words (non-significant ones such as articles) are ignored. Missing fields are empty.

Parameters:entry (pybtex.database.Entry) – Bibliography item to key
Returns:The new key
Return type:str
publi.generate_suffix(key, keyset, current_suffix='')[source]

Generate a key suffix for disambiguation. The resulting key will be unique with respect to keyset. Works by appending successively more alphanumeric characters (key -> key.a -> key.b -> ... -> key.ab)

Parameters:
  • key (str) – Original key
  • keyset (set) – Set of keys over which to disambiguate
  • current_suffix (str) – Accumulator argument for recursion
Returns:

The new key

Return type:

str

publi.group_entries_by_key(entries, sorter, group_name_dict=None)[source]

Sort set of entries into groups depending on the value of sorter. Returns dict where keys are the different values of the sorter field occurring across the set of entries.

Parameters:
  • entries (list) – Iterable of pybtex.database.Entry objects
  • sorter (str) – Name of the field to sort on
  • group_name_dict (dict) – Dict to map the group names to something else
Returns:

Dictionary mapping field value to list of entries with that value

Return type:

dict

publi.list_entries(args)[source]

Render database to format and write to file. See render()

Parameters:args (argparse.Namespace) – Command line arguments
publi.main()[source]

Process user commands. The program has several subcommands. Run with –help for full details.

publi.make_plain(text)[source]

Detexify and asciify text

Parameters:text (str) – Text to make plain
Returns:Text with all LaTeX sequences rendered to text and unicode characters replaced
Return type:str
publi.print_all_authors()[source]

Print all persons found in the database. Can be authors or editors (in spite of the name)

publi.read_bibfile(filename)[source]

Parse pybtex.database.BibliographyData from BibTeX file.

Parameters:filename (str) – Name of the BibTeX file
Returns:The parsed data
Return type:pybtex.database.BibliographyData
publi.render(args)[source]

Render publication database into various formats. Supported are bib, html, tex and pdf (currently unimplemented)

Parameters:args (argparse.Namespace) – Command line arguments
Returns:Rendered database
Return type:str
Raises:ValueError if unknown format passed
publi.render_to_html(publications, args)[source]

Render publication database to html. Optionally complete or as embeddable fragment.

Parameters:
Returns:

Rendered database

publi.render_to_tex(publications, args)[source]

Render publication database to latex. Optionally complete or as embeddable fragment.

Parameters:
Returns:

Rendered database

publi.write_output(content, fname)[source]

Convenience for writing string to utf8-encoded file.

Parameters:
  • content (str) – Text to write
  • fname (str) – File to write to