SlackLog formatters

SlackLog formatter takes an in-memory representation of a Slackware ChangeLog.txt and produces a different representation of it.

The in-memory representation is an instance of SlackLog.

Currently, the following formatters are provided:

class slacklog.formatters.SlackLogFormatter[source]

Bases: object

Base class for SlackLog formatters.

This class is meant for subclassing.

max_entries = None

If not None, must be an int representing how many entries are formatted from the beginning of the log. Rest of the entries are ignored.

max_pkgs = None

If not None, must be an int representing how many packages are formatted from the beginning of each entry. Rest of the packages are ignored.

format(log)[source]

Return unicode representation of the in-memory representation of the log.

Default implementation calls format_log_preamble(), followed by a call to format_entry() for each log entry, and finally calls format_log_postamble().

The return value is the concatenation of the return values of the mentioned functions.

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of the log.
format_log_preamble(log)[source]

Return unicode representation of the log preamble, the part before entries.

Default implementation returns empty string.

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log preamble.
format_log_postamble(log)[source]

Return unicode representation of the log postamble, the part after all entries.

Default implementation returns empty string.

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log postamble.
format_entry(entry, is_first, is_last)[source]

Return unicode representation of a single log entry.

Default implementation calls format_entry_separator() with arguments is_first and is_last, followed by a call to format_entry_preamble(), followed by a call to format_pkg() for each package in this log entry, finally followed by a call to format_entry_postamble().

The return value is the concatenation of the return values of the mentioned functions.

Parameters:
  • entrySlackLogEntry – in-memory representation of the log entry.
  • is_firstboolTrue if this is first entry, False otherwise.
  • is_lastboolTrue if this is last entry, False otherwise.
Returns:

unicode – Unicode representation of log entry.

format_entry_separator(is_first, is_last)[source]

Return unicode representation of the log entry separator.

Default implementation returns an empty string.

Parameters:
  • is_firstboolTrue if this is first entry, False otherwise.
  • is_lastboolTrue if this is last entry, False otherwise.
Returns:

unicode – Unicode representation of log entry separator.

format_entry_preamble(entry)[source]

Return unicode representation of the log entry preamble, the part before packages.

Default implementation returns an empty string.

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry preamble.
format_entry_postamble(entry)[source]

Return unicode representation of the log entry postamble, the part after packages.

Default implementation returns an empty string.

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry postamble.
format_pkg(pkg, is_first, is_last)[source]

Return unicode representation of a single log entry package.

Default implementation calls format_pkg_separator(), followed by a call to format_pkg_preamble(), and finally calls format_pkg_postamble().

The return value is the concatenation of the return values of the mentioned functions.

Parameters:
  • pkgSlackLogPkg – in-memory representation of the log entry package
  • is_firstboolTrue if this is first package, False otherwise.
  • is_lastboolTrue if this is last package, False otherwise.
Returns:

unicode – Unicode representation of log entry package.

format_pkg_separator(is_first, is_last)[source]

Return unicode representation of the log entry package separator.

Default implementation returns an empty string.

Parameters:
  • is_firstboolTrue if this is first package, False otherwise.
  • is_lastboolTrue if this is last package, False otherwise.
Returns:

unicode – Unicode representation of log entry package separator.

format_pkg_preamble(pkg)[source]

Return unicode representation of the log entry package preamble.

Default implementation returns an empty string.

Parameters:pkgSlackLogPkg – in-memory representation of the log entry package
Returns:unicode – Unicode representation of log entry package preamble.
format_pkg_postamble(pkg)[source]

Return unicode representation of the log entry package postamble.

Default implementation returns an empty string.

Parameters:pkgSlackLogPkg – in-memory representation of the log entry package
Returns:unicode – Unicode representation of log entry package postamble.
format_list(list_of_items, item_formatter, max_items=None)[source]

Return unicode representation of a list of objects.

This method is not meant for subclassing.

Parameters:
  • list_of_items (list) – List of items to format.
  • item_formatter – Function that formats one item. A callable that takes one item as the first positional argument, two booleans is_first and is_last as second and third positional arguments, and returns a unicode string.
  • max_itemsint or falsy – Maximum number of items to format. If falsy, all items are formatted.
Returns:

unicode – Formatted data.

class slacklog.formatters.SlackLogTxtFormatter[source]

Bases: slacklog.formatters.SlackLogFormatter

Concrete SlackLog formatter that tries to regenerate the original ChangeLog.txt.

format_log_preamble(log)[source]

Overrides SlackLogFormatter.format_entry_separator().

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log preamble.
format_log_postamble(log)[source]

Overrides SlackLogFormatter.format_entry_separator().

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log postamble.
format_entry_separator(is_first, is_last)[source]

Overrides SlackLogFormatter.format_entry_separator().

Parameters:
  • is_firstboolTrue if this is first entry, False otherwise.
  • is_lastboolTrue if this is last entry, False otherwise.
Returns:

unicode – Unicode representation of log entry separator.

format_entry_preamble(entry)[source]

Overrides SlackLogFormatter.format_entry_preamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry preamble.
format_pkg_preamble(pkg)[source]

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkgSlackLogPkg – in-memory representation of the log entry package
Returns:unicode – Unicode representation of log entry package preamble.
class slacklog.formatters.SlackLogRssFormatter[source]

Bases: slacklog.formatters.SlackLogFormatter

Concrete SlackLog formatter that generates an RSS feed.

slackware = None

unicode description of the distro version. E.g. ‘Slackware 13.37’ or ‘Slackware64 current’.

unicode. Full URL of the RSS feed.

unicode. Full URL of the WWW version of the feed.

description = None

unicode description of the feed.

language = None

unicode language identifier. E.g. ‘en’.

managingEditor = None

unicode. Email, and possibly name, of the feed manager. E.g. ‘jane@doe.net (Jane Doe)’.

webMaster = None

unicode. Email, and possibly name, of the webmaster. E.g. ‘john@doe.net (John Doe)’.

lastBuildDate = None

datetime.datetime. Timestamp when this feed was last generated. UTC assumed.

format_log_preamble(log)[source]

Overrides SlackLogFormatter.format_log_preamble().

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log preamble.
format_log_postamble(log)[source]

Overrides SlackLogFormatter.format_log_postamble().

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log postamble.
format_entry_preamble(entry)[source]

Overrides SlackLogFormatter.format_entry_preamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry preamble.
format_entry_postamble(entry)[source]

Overrides SlackLogFormatter.format_entry_postamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry postamble.
format_pkg_preamble(pkg)[source]

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkgSlackLogPkg – in-memory representation of the log entry package
Returns:unicode – Unicode representation of log entry package preamble.
class slacklog.formatters.SlackLogAtomFormatter[source]

Bases: slacklog.formatters.SlackLogFormatter

Concrete SlackLog formatter that generates an Atom feed.

slackware = None

unicode description of the distro version. E.g. ‘Slackware 13.37’ or ‘Slackware64 current’.

unicode. Full URL of the Atom feed.

unicode. Full URL of the HTML version.

name = None

unicode. Name of the feed author.

email = None

unicode. Email of the feed author.

updated = None

datetime.datetime. Timestamp when this feed was last generated. UTC assumed.

format_log_preamble(log)[source]

Overrides SlackLogFormatter.format_log_preamble().

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log preamble.
format_log_postamble(log)[source]

Overrides SlackLogFormatter.format_log_postamble().

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of log postamble.
format_entry_preamble(entry)[source]

Overrides SlackLogFormatter.format_entry_preamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry preamble.
format_entry_postamble(entry)[source]

Overrides SlackLogFormatter.format_entry_postamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry postamble.
format_pkg_preamble(pkg)[source]

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkgSlackLogPkg – in-memory representation of the log entry package
Returns:unicode – Unicode representation of log entry package preamble.
class slacklog.formatters.SlackLogPyblosxomFormatter[source]

Bases: slacklog.formatters.SlackLogFormatter

Concrete SlackLog formatter that generates Pyblosxom blog entries.

quiet = None

If True,

slackware = None

unicode description of the distro version. E.g. ‘Slackware 13.37’ or ‘Slackware64 current’.

datadir = None

Blog entry directory.

extension = None

Blog entry filename extension.

encoding = None

Blog entry file encoding.

tags_separator = None

Separator for tags.

pkg_separator = None

Separator for packages.

pyfilemtime = None

If True, a pyfilemtime compatible filenames are generated.

overwrite = None

If True, already existing blog entries are overwritten.

backup = None

If True, already existing blog entries are copied to backups before overwriting.

entry_preamble = None

unicode. HTML to insert before the entry.

entry_postamble = None

unicode. HTML to insert after the entry.

entry_desc_preamble = None

unicode. HTML to insert before the entry description.

entry_desc_postamble = None

unicode. HTML to insert after the entry description.

entry_pkgs_preamble = None

unicode. HTML to insert before the list of packages.

entry_pkgs_postamble = None

unicode. HTML to insert after the list of packages.

pkg_preamble = None

unicode. HTML to insert before a package.

pkg_postamble = None

unicode. HTML to insert after a package.

pkg_name_preamble = None

unicode. HTML to insert before package name.

pkg_name_postamble = None

unicode. HTML to insert after package name.

pkg_desc_preamble = None

unicode. HTML to insert before package description.

pkg_desc_postamble = None

unicode. HTML to insert after package description.

format_entry(entry, is_first, is_last)[source]

Overrides SlackLogFormatter.format_entry().

Parameters:
  • entrySlackLogEntry – in-memory representation of the log entry.
  • is_firstboolTrue if this is first entry, False otherwise.
  • is_lastboolTrue if this is last entry, False otherwise.
Returns:

unicode – Unicode representation of log entry.

format_entry_preamble(entry)[source]

Overrides SlackLogFormatter.format_entry_preamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry preamble.
format_entry_postamble(entry)[source]

Overrides SlackLogFormatter.format_entry_postamble().

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry postamble.
format_pkg_preamble(pkg)[source]

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkgSlackLogPkg – in-memory representation of the log entry package
Returns:unicode – Unicode representation of log entry package preamble.
format_entry_basename(entry)[source]

Return basename for the log entry.

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry name
format_entry_title(entry)[source]

Return log entry title.

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry title
format_entry_tags(entry)[source]

Return log entry tags.

Parameters:entrySlackLogEntry – in-memory representation of the log entry.
Returns:unicode – Unicode representation of log entry tags
class slacklog.formatters.SlackLogJsonFormatter[source]

Bases: slacklog.formatters.SlackLogFormatter

Concrete SlackLog formatter that generates JSON dump.

indent = None

If not None, must be an int representing how many spaces to indent the array elements and object keys.

format(log)[source]

Return unicode representation of the in-memory representation of the log.

Parameters:logSlackLog – in-memory representation of the log.
Returns:unicode – Unicode representation of the log.