[csw-devel] [PATCH] checkpkg: allow collection of obsoletion info

Maciej Bliziński maciej at opencsw.org
Sun Mar 27 10:18:42 CEST 2011


> +  def GetObsoletedBy(self):

Add a docstring here.

    """Collects obsoleteness information.

    Documentation:
    http://...

    Returns:
      a tuple (bool, list) of (syntax_ok, obsoleted_by)

    If the package has not been obsoleted, or the package predates the
    implementation of this mechanism, the list is empty.
    """

> +    obsoleted_by = []
> +    obsoleted_by_path = os.path.join(self.directory, "install", "obsoleted")
> +    if no os.path.exists(obsoleted_by_path):
> +      return obsoleted_by
> +    fd = open(obsoleted_by_path, "r")

I've recently learned a Python idiom for opening files:

with open(obsoleted_by_path, "r") as fd:
  indented block
  using fd

fd is unavailable outside that block

> +    for line in fd:
> +      fields = re.split(c.WS_RE, line)

I expect that some packages might contain a file with bad syntax, e.g.
3 fields or 1 field.

> +      pkgname = fields[0]
> +      catalogname = fields[1]

This line would throw an exception (i.e. checkpkg process would abort)
if there was only one field.  To make it more resilient:

obsoleted_by = []
obsoleted_syntax_ok = True

  fields = re.split(c.WS_RE, line.strip())
  if 2 != len(fields):
    obsoleted_syntax_ok = False
    continue
  pkgname, catalogname = fields

return obsoleted_syntax_ok, obsoleted_by

Or even better:
return {
  "syntax": obsoleted_syntax_ok,
  "by": obsoleted_by,
}

> +      obsoleted_by.append((pkgname, catalogname))
> +    fd.close()

If you have the 'with' block of code, fd is closed automatically when
you leave the 'with' block.

> +    return obsoleted_by

Next steps should be:

- add a dict item around lib/python/package_stats.py line 500 (you
could add a tuple, or transform it into a dictionary, or use whatever
form that you think will be convenient to use later on;  I like
dictionaries because they tend to be self-descriptive)
- since you're changing the data format, increment
PACKAGE_STATS_VERSION in package_stats.py (line 25)
- use the new data structure in a check

Maciej


More information about the devel mailing list