server/sources/extlite.py
changeset 2493 9806571ea790
parent 2306 95da5d9f0870
child 2611 0557f25682da
equal deleted inserted replaced
2492:c51be1cf8317 2493:9806571ea790
     9 
     9 
    10 
    10 
    11 from os.path import join, exists
    11 from os.path import join, exists
    12 
    12 
    13 from cubicweb import server
    13 from cubicweb import server
    14 from cubicweb.server.sqlutils import SQL_PREFIX, sqlexec, SQLAdapterMixIn
    14 from cubicweb.server.sqlutils import (SQL_PREFIX, SQLAdapterMixIn, sqlexec,
       
    15                                       sql_source_backup, sql_source_restore)
    15 from cubicweb.server.sources import AbstractSource, native
    16 from cubicweb.server.sources import AbstractSource, native
    16 from cubicweb.server.sources.rql2sql import SQLGenerator
    17 from cubicweb.server.sources.rql2sql import SQLGenerator
    17 
    18 
    18 class ConnectionWrapper(object):
    19 class ConnectionWrapper(object):
    19     def __init__(self, source=None):
    20     def __init__(self, source=None):
    82         # which will call set_schema
    83         # which will call set_schema
    83         self._need_sql_create = not exists(dbpath)
    84         self._need_sql_create = not exists(dbpath)
    84         self._need_full_import = self._need_sql_create
    85         self._need_full_import = self._need_sql_create
    85         AbstractSource.__init__(self, repo, appschema, source_config,
    86         AbstractSource.__init__(self, repo, appschema, source_config,
    86                                 *args, **kwargs)
    87                                 *args, **kwargs)
       
    88 
       
    89     def backup(self, confirm, backupfile=None, timestamp=None, askconfirm=False):
       
    90         """method called to create a backup of source's data"""
       
    91         backupfile = self.backup_file(backupfile, timestamp)
       
    92         sql_source_backup(self, self.sqladapter, confirm, backupfile,
       
    93                           askconfirm)
       
    94 
       
    95     def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
       
    96                askconfirm=False):
       
    97         """method called to restore a backup of source's data"""
       
    98         backupfile = self.backup_file(backupfile, timestamp)
       
    99         sql_source_restore(self, self.sqladapter, confirm, backupfile, drop,
       
   100                            askconfirm)
    87 
   101 
    88     @property
   102     @property
    89     def _sqlcnx(self):
   103     def _sqlcnx(self):
    90         # XXX: sqlite connections can only be used in the same thread, so
   104         # XXX: sqlite connections can only be used in the same thread, so
    91         #      create a new one each time necessary. If it appears to be time
   105         #      create a new one each time necessary. If it appears to be time