SlackLog formatters

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

slacklog.formatters.readable(d)[source]
slacklog.formatters.anchor(d)[source]
class slacklog.formatters.SlackLogFormatter[source]

Bases: object

Base class for SlackLog formatters.

This class is ment 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:log – in-memory representation of the log.
Type:slacklog.models.SlackLog
Returns:Unicode representation of the log.
Type:unicode
format_log_preamble(log)[source]

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

Default implementation returns empty string.

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

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

Default implementation returns empty string.

Parameters:log – in-memory representation of the log.
Type:slacklog.models.SlackLog
Returns:Unicode representation of log postamble.
Type:unicode
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:
  • entry – in-memory representation of the log entry.
  • is_first (bool) – True if this is first entry, False otherwise.
  • is_last (bool) – True if this is last entry, False otherwise.
Type:

slacklog.models.SlackLogEntry

Returns:

Unicode representation of log entry.

Type:

unicode

format_entry_separator(is_first, is_last)[source]

Return unicode representation of the log entry separator.

Default implementation returns an empty string.

Parameters:
  • is_first (bool) – True if this is first entry, False otherwise.
  • is_last (bool) – True if this is last entry, False otherwise.
Returns:

Unicode representation of log entry separator.

Type:

unicode

format_entry_preamble(entry)[source]

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

Default implementation returns an empty string.

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

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

Default implementation returns an empty string.

Parameters:entry – in-memory representation of the log entry.
Type:slacklog.models.SlackLogEntry
Returns:Unicode representation of log entry postamble.
Type:unicode
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:
  • pkg – in-memory representation of the log entry package
  • is_first (bool) – True if this is first package, False otherwise.
  • is_last (bool) – True if this is last package, False otherwise.
Type:

slacklog.models.SlackLogPkg

Returns:

Unicode representation of log entry package.

Type:

unicode

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_first (bool) – True if this is first package, False otherwise.
  • is_last (bool) – True if this is last package, False otherwise.
Returns:

Unicode representation of log entry package separator.

Type:

unicode

format_pkg_preamble(pkg)[source]

Return unicode representation of the log entry package preamble.

Default implementation returns an empty string.

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

Return unicode representation of the log entry package postamble.

Default implementation returns an empty string.

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

Return unicode representation of a list of objects.

This method is not ment for subclassing.

Parameters:
  • list_of_items – List of items to format.
  • item_formatter – Function that formats one item.
  • max_items – Maximum number of items to format. If falsy, all items are formatted.
Type:

list

Type:

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.

Type:

int or falsy.

Returns:

Formatted data.

Return type:

unicode

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:log – in-memory representation of the log.
Type:slacklog.models.SlackLog
Returns:Unicode representation of log preamble.
Type:unicode
format_log_postamble(log)[source]

Overrides SlackLogFormatter.format_entry_separator().

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

Overrides SlackLogFormatter.format_entry_separator().

Parameters:
  • is_first (bool) – True if this is first entry, False otherwise.
  • is_last (bool) – True if this is last entry, False otherwise.
Returns:

Unicode representation of log entry separator.

Type:

unicode

format_entry_preamble(entry)[source]

Overrides SlackLogFormatter.format_entry_preamble().

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

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkg – in-memory representation of the log entry package
Type:slacklog.models.SlackLogPkg
Returns:Unicode representation of log entry package preamble.
Type:unicode
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:log – in-memory representation of the log.
Type:slacklog.models.SlackLog
Returns:Unicode representation of log preamble.
Type:unicode
format_log_postamble(log)[source]

Overrides SlackLogFormatter.format_log_postamble().

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

Overrides SlackLogFormatter.format_entry_preamble().

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

Overrides SlackLogFormatter.format_entry_postamble().

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

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkg – in-memory representation of the log entry package
Type:slacklog.models.SlackLogPkg
Returns:Unicode representation of log entry package preamble.
Type:unicode
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:log – in-memory representation of the log.
Type:slacklog.models.SlackLog
Returns:Unicode representation of log preamble.
Type:unicode
format_log_postamble(log)[source]

Overrides SlackLogFormatter.format_log_postamble().

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

Overrides SlackLogFormatter.format_entry_preamble().

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

Overrides SlackLogFormatter.format_entry_postamble().

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

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkg – in-memory representation of the log entry package
Type:slacklog.models.SlackLogPkg
Returns:Unicode representation of log entry package preamble.
Type:unicode
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:
  • entry – in-memory representation of the log entry.
  • is_first (bool) – True if this is first entry, False otherwise.
  • is_last (bool) – True if this is last entry, False otherwise.
Type:

slacklog.models.SlackLogEntry

Returns:

Unicode representation of log entry.

Type:

unicode

format_entry_preamble(entry)[source]

Overrides SlackLogFormatter.format_entry_preamble().

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

Overrides SlackLogFormatter.format_entry_postamble().

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

Overrides SlackLogFormatter.format_pkg_preamble().

Parameters:pkg – in-memory representation of the log entry package
Type:slacklog.models.SlackLogPkg
Returns:Unicode representation of log entry package preamble.
Type:unicode
format_entry_basename(entry)[source]

Return basename for the log entry.

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

Return log entry title.

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

Return log entry tags.

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

Bases: slacklog.formatters.SlackLogFormatter

Concrete SlackLog formatter that generates JSON dump.

class SlackLogEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

Bases: json.encoder.JSONEncoder

JSON encoder that knows how to turn a SlackLog into a dict.

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
indent = None

If not None, must be an int representing how many 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:log – in-memory representation of the log.
Type:slacklog.models.SlackLog
Returns:Unicode representation of the log.
Type:unicode