Python module debian.blends

A module to handle Debian Pure Blends tasks, modelled after apt.package.

The examples use the following sample tasks file:

>>> sample_task = """Format: https://blends.debian.org/blends/1.1
... Task: Education
... Install: true
... Description: Educational astronomy applications
...  Various applications that can be used to teach astronomy.
...  .
...  This is however incomplete.
...
... Recommends: celestia-gnome | celestia-glut, kstars
...
... Recommends: gravit
... WNPP: 743379
... Homepage: http://gravit.slowchop.com/
... Pkg-Description: Visually stunning gravity simulator
...  Gravit is a free, visually stunning gravity simulator.
...  .
...  You can spend endless time experimenting with various
...  configurations of simulated universes.
... Why: Useful package
... Remark: Entered Debian in 2014
...
... Suggests: sunclock, xtide
... """
>>> with open('education', 'w') as fp:
...     nbytes = fp.write(sample_task)
class blends.Blend(basedir='.')

Representation of a Debian Pure Blend.

name

Full (package) name of the blend (debian-astro)

short_name

Short name of the blend (astro)

title

Blends title (Debian Astro)

prefix

Prefix for tasks (astro)

tasks

Task list

update(cache)

Update from cache

Parameters:

cacheapt.Cache like object

This adds the available versions to all dependencies. It updates descriptions, summaries etc. available to all BaseDependencies in all tasks.

Instead of using update(), also the += operator can be used.

property all

All Base Dependencies of this task

fix_dependencies()

Fix the dependencies according to available packages

This lowers all unavailable recommended dependencies to suggested.

gen_control()

Return the task as list of Deb822 objects suitable for debian/control

gen_task_desc(udeb=False)

Return the task as list of Deb822 objects suitable for blends-task.desc

class blends.Task(blend, name, sequence, base_deps=None)

Representation of a Blends task. Modelled after apt.package.Version.

The Version class contains all information related to a specific package version of a blends task.

Parameters:
  • blendBlend object, or Blend name

  • name – Name of the task

  • sequencestr or file containing the Deb822 description of the task

  • base_deps – List of dependencies to add to the task (str)

When the header does not contain a line

Format: https://blends.debian.org/blends/1.1

then the Depends priorities will be lowered to Recommends when read.

Example:

>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> print(task.name)
education
>>> print(task.package_name)
astro-education
>>> print(task.description)
Various applications that can be used to teach astronomy.

This is however incomplete.
>>> print(task.summary)
Educational astronomy applications
>>> print(task.section)
metapackages
>>> print(task.architecture)
all
>>> for p in task.all:
...     print(p.name)
celestia-gnome
celestia-glut
kstars
gravit
sunclock
xtide
blend

Blend name

prefix

Metapackage prefix

name

Task name

header

Deb822 header

base_deps

Base dependencies

content

Deb822List content of the task

format_upgraded

True if the format was upgraded from an older version

property install

True if the task is installed as a default package

property index

True if the task shall appear in the tasks index in the web senitel

property is_metapackage

True if the tasks has a Debian metapackage

property description

Return the formatted long description.

property summary

Return the short description (one line summary).

property section

Return the section of the package.

property architecture

Return the architecture of the package version.

property tests

Return all tests for this task when included in tasksel

property all

All Base Dependencies of this task

gen_control()

Return the task as Deb822 object suitable for debian/control

>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> print(task.gen_control().dump())
Package: astro-education
Section: metapackages
Architecture: all
Recommends: celestia-gnome | celestia-glut,
            gravit,
            kstars
Suggests: sunclock,
          xtide
Description: Educational astronomy applications
 Various applications that can be used to teach astronomy.
 .
 This is however incomplete.
gen_task_desc(udeb=False)

Return the task as Deb822 object suitable for blends-task.desc.

Parameters:

udeb – if True, generate `blends-task.desc suitable for udebs

>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> print(task.gen_task_desc().dump())
Task: astro-education
Parent: debian-astro
Section: debian-astro
Description: Educational astronomy applications
 Various applications that can be used to teach astronomy.
 .
 This is however incomplete.
Test-new-install: mark show
Key:
 astro-education
update(cache)

Update from cache

This adds the available versions to all dependencies. It updates descriptions, summaries etc. available to all BaseDependencies.

Parameters:

cacheapt.Cache like object

Instead of using update(), also the += operator can be used:

>>> import apt
>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> dep = task.recommends[1][0]
>>> print(dep.name + ": ", dep.summary)
kstars:  None
>>> task += apt.Cache()
>>> print(dep.name + ": ", dep.summary)
kstars:  desktop planetarium, observation planning and telescope control
fix_dependencies()

Fix the dependencies according to available packages

This lowers all unavailable recommended dependencies to suggested.

>>> import apt
>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> for dep in task.recommends:
...     print(dep.rawstr)
celestia-gnome | celestia-glut
kstars
gravit
>>> for dep in task.suggests:
...     print(dep.rawstr)
sunclock
xtide
>>> task += apt.Cache()
>>> missing = task.fix_dependencies()
>>> for dep in task.recommends:
...     print(dep.rawstr)
kstars
gravit
>>> for dep in task.suggests:
...     print(dep.rawstr)
sunclock
xtide
celestia-gnome | celestia-glut
class blends.Dependency(rawtype, s=None, content=None)

Represent an Or-group of dependencies.

Example:

>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> dep = task.recommends[0]
>>> print(dep.rawstr)
celestia-gnome | celestia-glut
rawtype

The type of the dependencies in the Or-group

property rawstr

String representation of the Or-group of dependencies.

Returns the string representation of the Or-group of dependencies as it would be written in the debian/control file. The string representation does not include the type of the Or-group of dependencies.

property target_versions

A list of all Version objects which satisfy this Or-group of deps.

class blends.BaseDependency(s, content=None)

A single dependency.

Example:

>>> with open('education') as fp:
...     task = Task('debian-astro', 'education', fp)
>>> dep = task.recommends[2][0]
>>> print(dep.rawstr)
gravit
>>> print(dep.wnpp)
743379
>>> print(dep.homepage)
http://gravit.slowchop.com/
>>> print(dep.description)
Gravit is a free, visually stunning gravity simulator.

You can spend endless time experimenting with various
configurations of simulated universes.
>>> print(dep.summary)
Visually stunning gravity simulator
property rawstr

String representation of the dependency.

Returns the string representation of the dependency as it would be written in the debian/control file. The string representation does not include the type of the dependency.

property wnpp

The WNPP bug number, if available, or None

property homepage

Return the homepage for the package.

property description

Return the formatted long description.

property summary

Return the short description (one line summary).

class blends.Deb822List(paragraphs)

A list of Deb822 paragraphs

dump(fd=None, encoding=None, text_mode=False)

Dump the the contents in the original format

If fd is None, returns a str object. Otherwise, fd is assumed to be a file-like object, and this method will write the data to it instead of returning an str object.

If fd is not None and text_mode is False, the data will be encoded to a byte string before writing to the file. The encoding used is chosen via the encoding parameter; None means to use the encoding the object was initialized with (utf-8 by default). This will raise UnicodeEncodeError if the encoding can’t support all the characters in the Deb822Dict values.

blends.aptcache(release=None, srcdirs=['/etc/blends'])

Open and update a (temporary) apt cache for the specified distribution.

Parameters:
  • release – Distribution name

  • srcdirs – List of directories to search for sources.list.<<release>>

If the distribution is not given, use the system’s cache without update.

blends.uddcache(packages, release, components=['main'], **db_args)

Create a dict from UDD that is roughly modelled after apt.Cache.

The dict just resolves the version number and archs for the packages. For performance reasons, an initial package list needs to be given.

Parameters:
  • release – Distribution name

  • packages – Initial package list

  • db_args – UDD connection parameters

Provided dependencies are integrated in the returned dict.