Conflict Handler

The conflict handler is used to solve conflicts occuring during the import of csv files.

Interface

class pysk.db.ConflictHandler(db=None, mode=1, verbose=1, logFunctor=<built-in method write of file object>)

Checks for conflicts in database and tries to resolve them

__call__(rec)

Invoke conflict handler

Checks if the record is valid and if conflicts exist. Depending on the mode settings conflicts are resolved.

Parameters:rec – Rec to investigate
abort()

Raise runtime error

addWarning(warning)

Set warning flag

Sets the respective warning flag in self._flags

Parameters:warning – Flag to set
disableWarning(warning)

Disable a given warning

Parameters:warning – Warning to disable
enableWarning(warning)

Enable a given warning

Parameters:warning – Warning
handleConflicts(flight)

Identify potential conflicts for a given flight

Parameters:flight – Flight to search conflicts for
hasWarnings()

Check if current instance has enabled warnings

Returns:True if and only if this instance has at least one enabled warning flag
static isDuplicate(flight, other)

Check if a flight is an exact duplicate of another flight

Parameters:
  • flight – first flight
  • other – second flight
Returns:

True if and only if first flight is an exact duplicate of other

isValid(flight)

Check flight for consistency

Verifies that all requirements of a flight are met.

Parameters:Flight to check (flight) –
iterConflicts()

Iterate conflicts as strings

Yields:String representation of each conflict
keepAll()

Ignore conflicts and import/keep the candidate

log(message)

Log function. Forwards messages to the callback log function.

Parameters:message – Message to print to stream
replaceConflicts()

Replace all conflicting records by candidate

skipCandidate()

Skip or remove the candidate

warnings()

Get iterable over all warnings

Yields:String for each active warning

Constants

Warning Flags

pysk.db.conflict_handler.NONE = 0

No warnings

pysk.db.conflict_handler.ALL = 65535

All warnings are set

pysk.db.conflict_handler.MISSING_DEPARTURE_TIME = 1

Record is lacking departure time

pysk.db.conflict_handler.MISSING_LANDING_TIME = 2

Record is lacking landing time

pysk.db.conflict_handler.MISSING_DEPARTURE_LOCATION = 4

Record is lacking departure location

pysk.db.conflict_handler.MISSING_LANDING_LOCATION = 8

Record is lacking landing location

pysk.db.conflict_handler.MISSING_LAUNCH_METHOD = 16

Record is lacking launch method information

pysk.db.conflict_handler.MISSING_PILOT = 32

Record is lacking pilot information

pysk.db.conflict_handler.MISSING_PLANE = 64

Record is missing airplane information

Warning Messages

pysk.db.conflict_handler.WARNINGS = {32: 'missing pilot', 1: 'missing departure time', 2: 'missing landing time', 4: 'missing departure location', 8: 'missing landing location', 64: 'missing plane', 16: 'missing launch method'}

Dictionary containing a warning string message for each warning flag

Possible Modes

pysk.db.conflict_handler.INTERACTIVE = 1

Prompts user on conflict for manual resolution

pysk.db.conflict_handler.IGNORE_ALL_CONFLICTS = 2

Import all records regardless of eventual conflicts

pysk.db.conflict_handler.REJECT_ON_CONFLICT = 3

Do not import records with conflicts