SlackLog parsers

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

The in-memory representation is an instance of SlackLog.

class slacklog.parsers.SlackLogParser[source]

Bases: object

Parser for Slackware ChangeLog.txt files. This implementation works for 12.x and newer Slackware versions.

quiet = None

If True, warnings about date parsing are not printed.

min_date = None

If set to a datetime.datetime object, older log entries are ignored (not parsed).

ENTRY = None

Counter of entries (for debugging).

PKG = None

Counter of packages (for debugging).

parse(data)[source]

Return the in-memory representation of the data.

Parameters:dataunicode – the ChangeLog.txt content.
Returns:SlackLog – in-memory representation of data
split_log_to_entries(data)[source]

Split the ChangeLog.txt into a list of unparsed entries.

Parameters:dataunicode –the ChangeLog.txt content.
Returns:[unicode] – list of unparsed entries, separators removed.
parse_entry(data, log)[source]

Parse a single ChangeLog entry.

Parameters:
  • dataunicode – ChangeLog entry content.
  • logSlackLog – in-memory representation that is being parsed.
Returns:

SlackLogEntry – in-memory representation of the ChangeLog entry.

gen_entry_checksum(data)[source]

Generate ChangeLog entry checksum from data.

Parameters:dataunicode – ChangeLog entry content.
Returns:unicode – Entry checksum.
gen_entry_identifier(data, checksum, parent)[source]

Generate ChangeLog entry identifier from data, checksum, and/or parent identifier.

Parameters:
  • dataunicode – ChangeLog entry content.
  • checksumunicode – ChangeLog entry checksum.
  • parentunicode – Parent entry identifier or None
Returns:

unicode – Entry identifier.

parse_entry_timestamp(data)[source]

Parse ChangeLog entry timestamp from data.

Parameters:dataunicode – ChangeLog entry content.
Returns:[datetime.datetime, tzinfo, bool, unicode] – a four element list: timestamp in UTC, original timezone, True if the timestamp had a 12-hour clock, and the rest of the entry.
parse_entry_description(data)[source]

Parse ChangeLog entry description from data.

Parameters:dataunicode – ChangeLog entry content (without timestamp).
Returns:[unicode, unicode] – a two element list: description and the rest of the entry.
split_entry_to_pkgs(data)[source]

Split ChangeLog entry content into a list of unparsed packages.

Parameters:dataunicode – ChangeLog entry content (without timestamp or description).
Returns:[unicode] – a list of unparsed packages.
parse_pkg(data, entry)[source]

Parse a single package.

Parameters:
  • dataunicode – Package name and description of the update.
  • entrySlackLogEntry – in-memory representation of the ChangeLog entry being parsed.
Returns:

SlackLogPkg – in-memory representation of the package.

parse_pkg_name(data)[source]

Parse package name from a package.

Parameters:dataunicode – Package name and description.
Returns:[unicode, unicode] – a two element list: package name and package description.
parse_pkg_description(data)[source]

Parse package description from a package.

Parameters:dataunicode – Package description.
Returns:unicode – Package description.
get_line(data)[source]

Consume one line from data.

Parameters:dataunicode – Data.
Returns:[unicode, unicode] – a two element list: first line, rest of the data.
parse_date(data)[source]

Parse a time string into a timestamp.

Parameters:dataunicode – Time string.
Returns:datetime.datetime – Timestamp in UTC timezone.
parse_date_with_timezone(data)[source]

Parse a time string into a timestamp.

Parameters:dataunicode – Time string.
Returns:[datetime.datetime, tzinfo] – a two element list: Timestamp in UTC timezone, and the original timezone.