Infrastructure, common and multi-layer classes, helpers.



Various enhancements to Python.

class AutoArchive._infrastructure.py_additions.Enum(*names)[source]


Simple enum class.

Example Usage:

codes = Enum("FOO", "BAR", "BAZ") # codes.BAZ will be 2 and so on and str.BAZ will be "BAZ"
Parameters:names (Iterator<str>) – Iterable of Enum members.
class AutoArchive._infrastructure.py_additions.event(eventFunction)[source]

Bases: object

Decorator that declares a function as an event.

Implements a C#-like events (a call dispatchers). Decorating a function or method with this decorator declares it as an event. In order to subscribe a handler function to the event, one should use the “+=” operator and to unsubscribe the “-=” operator. Such event can be fired by a calling the decorated function. This will dispatch the event to all subscribers, i.e. subscribed handler methods are called.


Decorated function should implement only pass as its body.


Decorated function can take any number of parameters or keyword parameters. Subscriber functions has to take same parameters as the event.

Example usage:

class Button:
   # ...
   def clicked(self, some_parameter):
       "Fired when the button was clicked."
   def _fireClicked(self, some_parameter):
   # ...

class Ui:
    def __init__(self, button):
        button.clicked += self._onButtonClicked
    def _onButtonClicked(self, some_parameter):
        "Handle the button click."
        # play a sound...
Parameters:eventFunction (function) – Decorated function or method that becomes an event.
class AutoArchive._infrastructure.py_additions.classproperty[source]

Bases: property

Decorator that makes the decorated method a class property.

class AutoArchive._infrastructure.py_additions.staticproperty[source]

Bases: property

Decorator that makes the decorated method a static property.

class AutoArchive._infrastructure.py_additions.Flag[source]

Bases: object

Context management-aware boolean flag.

Example usage:

class Foo:
   def __init__(self):
       self._someFlag = Flag()

   def bar(self):
       with self._someFlag:
           # do_stuff

   def baz(self):
       if self._someFlag.isSet():
          # do_not_do_stuff

Returns True if the flag is set; False otherwise.

class AutoArchive._infrastructure.py_additions.maxRecursion(maxDepth)[source]

Bases: contextlib.ContextDecorator

Decorator that limits number of recursive calls to a function.

Parameters:maxDepth – Recursion limit.
Raises:RuntimeError – If recursion limit was exceeded.


Utils and Constants classes.

class AutoArchive._infrastructure.utils.Utils[source]

Bases: object

Various utility methods.

classmethod fatalExit(msg, appName=None)[source]

Prints msg to standard error and exits with exit code 2.

classmethod printError(msg, appName=None)[source]

Prints msg as an error to standard error.

classmethod printWarning(msg, appName=None)[source]

Prints msg as a warning to standard error.

static uniq(decorated)[source]

Decorator that filters out duplicate elements from an iterable returned by decorated function.

class AutoArchive._infrastructure.utils.Constants[source]

Bases: object

Defines various “global” constants.

DEBUG = '1'

Debugging support.


AppEnvironment class

class AutoArchive._infrastructure._app_environment.AppEnvironment(executableName, options, arguments)[source]

Bases: object

Container class for various application-related information.

  • executableName (str) – Name of the startup script.
  • options (optparse.Values) – Options passed on the command line.
  • arguments (list<str>) – Arguments passed on the command line.

Command line arguments.

Return type:list<str>

Name of the script that was used to start this application.

Return type:str

Command line options.

Return type:optparse.Values


ApplicationContext class.

class AutoArchive._infrastructure._application_context.ApplicationContext(appEnvironment, configuration, storage)[source]

Bases: object

Provides access to a various program-related objects.

  • appEnvironment (object) – Object that will be made available via appEnvironment property.
  • configuration (IConfiguration) – Application configuration.
  • storage (FileStorage) – Application storage.

Gets the application environment object.

Return type:object

Gets access to application configuration.

Return type:ConfigurationBase


Can be None


Gets access to application persistent storage.

Return type:FileStorage


Can be None