Bases: object
Create a backup of the current database to an sqlite database stored in a file.
The backupmechanism always considers the schema of the backed up database as the master, and never that of the backup. This means that when a backup is made, the backup file is first removed, and then filled with the tables from the the database to backup. When a restore is done, the schema of the database is not touched, but the tables are emptied and the data from the backup is copied into the existing schema.
Generator function that yields tuples : (numer_of_steps_completed, total_number_of_steps, description_of_current_step) while performing a backup.
Method used to filter which tables should be backed up, overwrite this method for taking into account specific schema issues.
From_table : | the table that is considered for backup |
---|---|
Returns: | True when the table should be backed up |
This method might be subclassed to turn off/on foreign key checks
Returns: | a camelot.core.files.storage.Storage object |
---|
Returns the storage to be used to store default backups.
By default, this will return a Storage that puts the backup files in the DataLocation as specified by the QDesktopServices
Returns: | a string with the prefix for the default name of the backup file |
---|
By default this method returns an empty string, overwrite this method to return a custom string, like the name of the company or such.
This method will be called inside the model thread.
This method will be called before the actual restore starts. It allows bringing the schema at the same revision as the backed up data.
Generator function that yields tuples : (numer_of_steps_completed, total_number_of_steps, description_of_current_step) while performing a restore.
Method used to filter which tables should be restored, overwrite this method for taking into account specific schema issues. restore_table_filter is different from backup_table_filter, since we might want to store data in the backup that should not be restored, like schema version information.
From_table : | the table that is considered for backup |
---|---|
Returns: | True when the table should be restored |
The global configuration of a Camelot application is handled through a LazyProxy object that reads settings from various targets. The default target reads the attributes from the ‘settings’ module, if this is found on the PYTHONPATH.
To access the global configuration, simply import the settings object:
from camelot.core.conf import settings
print settings.CAMELOT_MEDIA_ROOT
Developers can add targets to the settings proxy, to enable reading settings from other sources.
Bases: list
A lazy proxy of the ‘settings’ module on the PYTHONPATH, or other targets that contain global configuration. This proxy behaves as a list to which targets can be appended. The value of the first target in the list that has the requested attribute will be returned.
The Proxy is Lazy, because on each request of an attribute, the target is queried again.
Import the ‘settings’ module and append it as a target to the list of targets. This function will be called, if no other targets are specified
Get an attribute of the proxy, and when not found return default as value. This function behaves the same as the get function of a dictionary.
Bases: object
Settings that can be used for the creation of a simple Camelot application. Use these settings by appending them to the global settings at application startup:
from camelot.core.conf import settings, SimpleSettings
settings.append( SimpleSettings('myapp') )
Returns: | two-letter ISO 3166 country code |
---|
Returns: | two-letter ISO 639 language code |
---|
Camelot specific subclasses of Exception
Bases: exceptions.Exception
This exception is raised by the GUI when the user wants to cancel an action, this exception is then past to the model thread
Bases: exceptions.Exception
This exception is raised by the Action mechanism when the action requested something from the GUI but an unexpected event occured. The action can choose to ignore it or handle it.
Bases: exceptions.Exception
Raise this exception to inform the user he did something wrong, without showing a stack trace or other internals. Raising this exception won’t log stack traces either, as the occurance of this exception is considered a non-event for the developer:
from camelot.core.exception import UserException
from camelot.core.utils import ugettext
if not dvd.empty:
raise UserException( ugettext('Could not burn movie to non empty DVD'),
resolution = ugettext('Insert an empty DVD and retry') )
Will popup a gentle dialog for the user :
Helper functions related to the connection between the SQLAlchemy ORM and the Camelot Views.
wrapper around pkg_resources, with fallback to using directories specified in the settings file if pkg_resources cannot be used.
to allow fallback to the settings file, specify the settings_attribute method, this is the attribute in the settings file that contains the folder with the resources as opposed to the folder containing the module itself.
this mechanism will probably be rewritten to support the loading of resources from zip files instead of falling back to settings.
when running from a bootstrapper, we’ll try to use pgk_resources, even when runnin from within a zip file.
Logging is an important aspect of every application, as logs provide valuable feedback to developers and first line support. Camelot adds some additional functions on top of the standard Python logging library.
The added functionallity is needed for two reasons :
- Camelot applications are often installed in a distributed fashion. Thus the log files need to be collected to provide meaningfull information to the developer.
- Logging should never slow down/freeze the application. Even when logging to files this may happen, since the application never knows for sure if a file is really local, and network connections may turn slow at any time.
Both issues are resolved by using a logging handler that collects all logs, and periodically sends them to an http server in the background:
handler = ThreadedHttpHandler('www.example.com:80', '/my_logs/')
handler.setLevel(logging.INFO)
logging.root.addHandler(handler)
The logging url could include a part indentifying the user and as such assisting first line support.
Bases: camelot.core.threaded_logging.ThreadedAwsHandler
A logging handler that sends the logs to the Cloud Launch service, requires the cloudlaunch library, and only works with applications tested or deployed through cloudlaunch
The cloudlaunch record can be obtained using the get_cloud_record method of the cloudlaunch.resources module.
Bases: logging.Handler
A logging handler that sends the logs to an AWS queue through the SQS, this handler requires the boto library
Bases: logging.handlers.HTTPHandler
An Http Logging handler that does the logging itself in a different thread, to prevent slow down of the main thread
Utility functions
Bases: object
Convert an object getter to a collection getter. The resulting class is callable and will make sure object_getter is only called once, even if collection getter is called multiple times.
Like ugettext but look the message up in the specified domain. This uses the Translation table.
Parameters: | qobj – a QtCore.QObject |
---|---|
Returns: | True if the qobj was deleted, False otherwise |
Parameters: | qobj – a QtCore.QObject |
---|---|
Returns: | True if the qobj was deleted, False otherwise |
Parameters: | qobj – a QtCore.QObject |
---|---|
Returns: | True if the qobj was deleted, False otherwise |
Fill the global dictionary of translations with all data from the database, to be able to do fast gui thread lookups of translations
Store a tranlation in the global translation dictionary
Translate the string_to_translate to the language of the current locale. This is a two step process. First the function will try to get the translation out of the Translation entity, if this is not successfull, the function will ask QCoreApplication to translate string_to_translate (which tries to get the translation from the .qm files)
Bases: object
Like :function:`ugettext`, but delays the translation until the string is shown to the user. This makes it possible for the user to translate the string.