~raoul-snyman/openlp/pyro-impress

« back to all changes in this revision

Viewing changes to openlp/core/lib/db.py

  • Committer: Raoul Snyman
  • Date: 2019-06-05 04:53:18 UTC
  • mfrom: (2700.2.174 openlp)
  • Revision ID: raoul@snyman.info-20190605045318-bd2hsvmgrf7f5qew
HEAD

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
from openlp.core.common import delete_file
41
41
from openlp.core.common.applocation import AppLocation
42
42
from openlp.core.common.i18n import translate
43
 
from openlp.core.common.json import OpenLPJsonDecoder, OpenLPJsonEncoder
 
43
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder
44
44
from openlp.core.common.settings import Settings
45
45
from openlp.core.lib.ui import critical_error_message_box
46
46
 
132
132
    Create a path to a database from the plugin name and database name
133
133
 
134
134
    :param plugin_name: Name of plugin
135
 
    :param openlp.core.common.path.Path | str | None db_file_name: File name of database
 
135
    :param pathlib.Path | str | None db_file_name: File name of database
136
136
    :return: The path to the database
137
137
    :rtype: str
138
138
    """
150
150
    Log and report to the user that a database cannot be loaded
151
151
 
152
152
    :param plugin_name: Name of plugin
153
 
    :param openlp.core.common.path.Path db_file_path: File name of database
 
153
    :param pathlib.Path db_file_path: File name of database
154
154
    :return: None
155
155
    """
156
156
    db_path = get_db_path(plugin_name, db_file_path)
165
165
    Construct the connection string for a database.
166
166
 
167
167
    :param plugin_name: The name of the plugin for the database creation.
168
 
    :param openlp.core.common.path.Path | str | None db_file_name: The database file name. Defaults to None resulting
169
 
                                                                   in the plugin_name being used.
 
168
    :param pathlib.Path | str | None db_file_name: The database file name. Defaults to None resulting in the plugin_name
 
169
                                                   being used.
170
170
    :return: The database URL
171
171
    :rtype: str
172
172
    """
215
215
    Create a PathType for storing Path objects with SQLAlchemy. Behind the scenes we convert the Path object to a JSON
216
216
    representation and store it as a Unicode type
217
217
    """
218
 
    impl = types.UnicodeText
 
218
    impl = types.Unicode
219
219
 
220
220
    def coerce_compared_value(self, op, value):
221
221
        """
224
224
 
225
225
        :param op: The operation being carried out. Not used, as we only care about the type that is being used with the
226
226
            operation.
227
 
        :param openlp.core.common.path.Path | str value: The value being used for the comparison. Most likely a Path
228
 
            Object or str.
229
 
        :return: The coerced value stored in the db
230
 
        :rtype: PathType or UnicodeText
 
227
        :param pathlib.Path | str value: The value being used for the comparison. Most likely a Path Object or str.
 
228
        :return PathType | UnicodeText: The coerced value stored in the db
231
229
        """
232
230
        if isinstance(value, str):
233
231
            return UnicodeText()
238
236
        """
239
237
        Convert the Path object to a JSON representation
240
238
 
241
 
        :param openlp.core.common.path.Path value: The value to convert
 
239
        :param pathlib.Path value: The value to convert
242
240
        :param dialect: Not used
243
 
        :return: The Path object as a JSON string
244
 
        :rtype: str
 
241
        :return str: The Path object as a JSON string
245
242
        """
246
243
        data_path = AppLocation.get_data_path()
247
 
        return json.dumps(value, cls=OpenLPJsonEncoder, base_path=data_path)
 
244
        return json.dumps(value, cls=OpenLPJSONEncoder, base_path=data_path)
248
245
 
249
246
    def process_result_value(self, value, dialect):
250
247
        """
253
250
        :param types.UnicodeText value: The value to convert
254
251
        :param dialect: Not used
255
252
        :return: The JSON object converted Python object (in this case it should be a Path object)
256
 
        :rtype: openlp.core.common.path.Path
 
253
        :rtype: pathlib.Path
257
254
        """
258
255
        data_path = AppLocation.get_data_path()
259
 
        return json.loads(value, cls=OpenLPJsonDecoder, base_path=data_path)
 
256
        return json.loads(value, cls=OpenLPJSONDecoder, base_path=data_path)
260
257
 
261
258
 
262
259
def upgrade_db(url, upgrade):
351
348
 
352
349
        :param plugin_name: The name to setup paths and settings section names
353
350
        :param init_schema: The init_schema function for this database
354
 
        :param openlp.core.common.path.Path db_file_path: The file name to use for this database. Defaults to None
355
 
            resulting in the plugin_name being used.
 
351
        :param pathlib.Path | None db_file_path: The file name to use for this database. Defaults to None resulting in
 
352
            the plugin_name being used.
356
353
        :param upgrade_mod: The upgrade_schema function for this database
357
354
        """
358
355
        super().__init__()