univention.ucslint package


univention.ucslint.base module

class univention.ucslint.base.UPCMessage(id_, msg=None, filename=None, line=None, pos=None)[source]

Bases: object

Univention Policy Check message.

  • id – Message identifier.
  • msg – Message test.
  • filename – Associated file name.
  • line – Associated line number.
  • pos – Associated column number.

Return unique message identifier.

class univention.ucslint.base.UniventionPackageCheckBase[source]

Bases: object

Abstract base class for checks.

addmsg(msgid, msg=None, filename=None, line=None, pos=None)[source]

Add UPCMessage message.

  • msgid – Message identifier.
  • msg – Message text.
  • filename – Associated file name.
  • line – Associated line number.
  • pos – Associated column number.

Return mapping from message-identifiert to 2-tuple (severity, message-text).


Set debug level.

Parameters:level – Debug level.

Print debug message.

Parameters:msg – Text string.

Checks to be run before real check or to create precalculated data for several runs. Only called once!

Parameters:path – Directory or file to check.

The real check.

Parameters:path – Directory or file to check.

Return result as list of messages.

Returns:List of UPCMessage
class univention.ucslint.base.UniventionPackageCheckDebian[source]

Bases: univention.ucslint.base.UniventionPackageCheckBase

Check for debian/ directory.


the real check.

exception univention.ucslint.base.UCSLintException[source]

Bases: exceptions.Exception

Top level exception.

exception univention.ucslint.base.DebianControlNotEnoughSections[source]

Bases: univention.ucslint.base.UCSLintException

Content exception.

exception univention.ucslint.base.DebianControlParsingError[source]

Bases: univention.ucslint.base.UCSLintException

Parsing exception.

exception univention.ucslint.base.FailedToReadFile(fn)[source]

Bases: univention.ucslint.base.UCSLintException

File reading exception.

class univention.ucslint.base.DebianControlEntry(content)[source]

Bases: dict

Handle paragraph in Deb822 control file.

Parameters:content – String content of paragraph.
class univention.ucslint.base.ParserDebianControl(filename)[source]

Bases: object

Parse debian/control file.

Parameters:filename – Full path.
class univention.ucslint.base.RegExTest(regex, msgid, msg, cntmin=None, cntmax=None)[source]

Bases: object

Regular expression test.

  • regex – Compiled regular expression
  • msgid – Message identifier.
  • msg – Message text.
  • cntmin – Required minimum number of matches.
  • cntmax – Required maximum number of matches.
class univention.ucslint.base.UPCFileTester(maxsize=102400)[source]

Bases: object

Univention Package Check - File Tester simple class to test if a certain text exists/does not exist in a textfile

By default only the first 100k of the file will be read.

>>>     import re
>>>     x = UPCFileTester()
>>>     x.open('/etc/fstab')
>>>     x.addTest( re.compile('ext[234]'), '5432-1', 'Habe ein extfs in Zeile %(startline)s und Position %(startpos)s in Datei %(basename)s gefunden.', cntmax=0)
>>>     x.addTest( re.compile('squashfs'), '1234-5', 'Habe kein squashfs in Datei %(basename)s gefunden.', cntmin=1)
>>>     msglist = x.runTests()
>>>     for msg in msglist:
>>>             print('%s ==> %s ==> %s' % (msg.id, msg.filename, msg.msg))
5432-1: /etc/fstab:4:29: Habe ein extfs in Zeile 4 und Position 29 in Datei fstab gefunden.
5432-1: /etc/fstab:7:19: Habe ein extfs in Zeile 7 und Position 19 in Datei fstab gefunden.
1234-5: /etc/fstab: Habe kein squashfs in Datei fstab gefunden.

creates a new UPCFileTester object

Parameters:maxsize – maximum number of bytes read from specified file

Opens the specified file and reads up to maxsize bytes into memory.

Parameters:filename – File to process.
_getpos(linenumber, pos_in_line)[source]

Converts ‘unwrapped’ position values (line and position in line) into position values corresponding to the raw file. Counting of lines and position starts at 1, so first byte is at line 1 pos 1!

  • linenumber – Line number starting at 1.
  • pos_in_line – Column number startin at 1.

2-tuple (line-number, column-number).

addTest(regex, msgid, msg, cntmin=None, cntmax=None)[source]

add a new test

  • regex – regular expression.
  • msgid – msgid for UPCMessage
  • msg – message for UPCMessage if msg contains one or more of the keywords ‘%(startline)s’, ‘%(startpos)s’, ‘%(endline)s’, ‘%(endpos)s’ or ‘%(basename)s’ they will get replaced by their corresponding value.
  • cntmin – ‘regex’ has to match at least ‘cntmin’ times otherwise a UPCMessage will be added
  • cntmax – ‘regex’ has to match at most ‘cntmax’ times otherwise a UPCMessage will be added

ValueError – if neither cntmin nor cntmax has been set


Runs all given tests on loaded file.

Returns:a list of UPCMessage objects
class univention.ucslint.base.FilteredDirWalkGenerator(path, ignore_dirs=None, prefixes=None, suffixes=None, ignore_suffixes=None, ignore_files=None, ignore_debian_subdirs=True, reHashBang=None, readSize=2048, dangling_symlinks=False)[source]

Bases: object

FilteredDirWalkGenerator is a generator that walks down all directories and returns all matching filenames.

There are several posibilities to limit returned results:

  • ignore_dirs – a list of additional directory names that will be excluded when traversing subdirectories (e.g. [‘.git’, ‘.svn’])
  • prefixes – a list of prefixes files have to start with (e.g. [‘univention-‘, ‘preinst’])
  • suffixes – a list of suffixes files have to end with (e.g. [‘.py’, ‘.sh’, ‘.patch’])
  • ignore_suffixes – a list of additional files, that end with one of defined suffixes, will be ignored (e.g. [‘~’, ‘.bak’])
  • ignore_files – list of additional files that will be ignored (e.g. [‘.gitignore’, ‘config.sub’]).
  • ignore_debian_subdirs – boolean that defines if .../debian/* directories are ignored or not.
  • reHashBang – if defined, only files are returned whose first bytes match specified regular expression.
  • readSize – number of bytes that will be read for e.g. reHashBang

example: >>> for fn in FilteredDirWalkGenerator(path, suffixes=[‘.py’]): >>> print(fn)

IGNORE_DIRS = set(['.pybuild', '.git', '.svn', 'CVS'])
IGNORE_SUFFIXES = set(['.swp', '.pyc', '.bak', '.pyo', '~'])
IGNORE_FILES = set(['config.status', 'configure', 'missing', 'config.guess', 'config.sub', 'libtool', 'depcomp', 'install-sh'])

Run simple test.