core Package

core Package

backup Module

class camelot.core.backup.BackupMechanism(filename, storage=None)[source]

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.

backup()[source]

Generator function that yields tuples : (numer_of_steps_completed, total_number_of_steps, description_of_current_step) while performing a backup.

backup_table_filter(from_table)[source]

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
copy_table_data(from_table, to_table)[source]
delete_table_data(to_table)[source]

This method might be subclassed to turn off/on foreign key checks

classmethod get_default_storage()[source]
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

classmethod get_filename_prefix()[source]
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.

prepare_schema_for_restore(from_engine, to_engine)[source]

This method will be called before the actual restore starts. It allows bringing the schema at the same revision as the backed up data.

restore()[source]

Generator function that yields tuples : (numer_of_steps_completed, total_number_of_steps, description_of_current_step) while performing a restore.

restore_table_filter(from_table)[source]

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
update_schema_after_restore(from_engine, to_engine)[source]

This method will be called after the restore has been done. It allows bringing the schema at the revision the application expects.

conf Module

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.

class camelot.core.conf.LazyProxy[source]

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.

append_settings_module()[source]

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(name, default)

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.

class camelot.core.conf.SimpleSettings(author, name)[source]

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') )
CAMELOT_MEDIA_ROOT()[source]
ENGINE()[source]

constants Module

Created on Jul 19, 2009

@author: tw55413

dbprofiles Module

class camelot.core.dbprofiles.EmptyProxy[source]
classmethod hostName()[source]
classmethod password()[source]
classmethod port()[source]
classmethod user()[source]
camelot.core.dbprofiles.engine_from_profile()[source]
camelot.core.dbprofiles.fetch_profiles(from_file=None)[source]
camelot.core.dbprofiles.get_cipher()[source]
camelot.core.dbprofiles.get_countrycode(profile=None)[source]
Returns:two-letter ISO 3166 country code
camelot.core.dbprofiles.get_languagecode(profile=None)[source]
Returns:two-letter ISO 639 language code
camelot.core.dbprofiles.get_network_proxy()[source]
camelot.core.dbprofiles.last_used_profile()[source]
camelot.core.dbprofiles.media_root_from_profile()[source]
camelot.core.dbprofiles.selected_profile_info()[source]
Returns:a dict with the info of the selected profile
camelot.core.dbprofiles.store_profiles(profiles, to_file=None)[source]
camelot.core.dbprofiles.stylesheet_from_profile()[source]
camelot.core.dbprofiles.use_chosen_profile(profilename)[source]

exception Module

Camelot specific subclasses of Exception

exception camelot.core.exception.CancelRequest[source]

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

exception camelot.core.exception.GuiException[source]

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.

exception camelot.core.exception.UserException(text, title=_('Could not proceed'), icon=None, resolution=None, detail=None)[source]

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 :

../_images/user_exception.png

license Module

orm Module

Helper functions related to the connection between the SQLAlchemy ORM and the Camelot Views.

camelot.core.orm.refresh_session(session)[source]

Session refresh expires all objects in the current session and sends a local entity update signal via the remote_signals mechanism

this method ought to be called in the model thread.

resources Module

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.

camelot.core.resources.resource_filename(module_name, filename)[source]

Return the absolute path to a file in a directory using pkg_resources

camelot.core.resources.resource_string(module_name, filename)[source]

load a file as a string using pkg_resources

schema_display Module

sql Module

camelot.core.sql.like_op(column, string)[source]
camelot.core.sql.transaction(original_function)[source]

Decorator for methods on an entity, to make them transactional

camelot.core.sql.update_database_from_model()[source]

Introspection the model and add missing columns in the database

this function can be ran in setup_model after setup_all(create_tables=True)

threaded_logging Module

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.

class camelot.core.threaded_logging.CloudLaunchHandler(cloud_record, connection_kwargs={})[source]

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.

class camelot.core.threaded_logging.ThreadedAwsHandler(access_key, secret_access_key, queue_name, revision=0, connection_kwargs={})[source]

Bases: logging.Handler

A logging handler that sends the logs to an AWS queue through the SQS, this handler requires the boto library

emit(record)[source]
timeout()[source]
class camelot.core.threaded_logging.ThreadedHttpHandler(host, url, method='GET')[source]

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

emit(record)[source]
timeout()[source]
class camelot.core.threaded_logging.ThreadedTimer(interval, handler)[source]

Bases: PyQt4.QtCore.QThread

Thread that checks every interval milli seconds if there are logs to be sent to the server

run()[source]

threading Module

Some helper functions and classes related to threading issues

camelot.core.threading.synchronized(original_function)[source]

Decorator for synchronized access to an object, the object should have an attribute _mutex which is of type QMutex

utils Module

Utility functions

class camelot.core.utils.CollectionGetterFromObjectGetter(object_getter)[source]

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.

camelot.core.utils.create_constant_function(constant)[source]
camelot.core.utils.dgettext(domain, message)[source]

Like ugettext but look the message up in the specified domain. This uses the Translation table.

camelot.core.utils.format_float(value, precision=3)[source]
camelot.core.utils.is_deleted(qobj)
Parameters:qobj – a QtCore.QObject
Returns:True if the qobj was deleted, False otherwise
camelot.core.utils.is_deleted_pyqt(qobj)[source]
Parameters:qobj – a QtCore.QObject
Returns:True if the qobj was deleted, False otherwise
camelot.core.utils.is_deleted_pyside(qobj)[source]
Parameters:qobj – a QtCore.QObject
Returns:True if the qobj was deleted, False otherwise
camelot.core.utils.load_translations()[source]

Fill the global dictionary of translations with all data from the database, to be able to do fast gui thread lookups of translations

camelot.core.utils.set_translation(source, value)[source]

Store a tranlation in the global translation dictionary

camelot.core.utils.ugettext(string_to_translate)[source]

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)

class camelot.core.utils.ugettext_lazy(string_to_translate)[source]

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.

camelot.core.utils.variant_to_pyobject(qvariant=None)[source]

Try to convert a QVariant to a python object as good as possible

camelot.core.utils.xls2list(xf)[source]

Comments
blog comments powered by Disqus