5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
|
10 from os.path import join, splitext |
10 from datetime import datetime, timedelta |
11 from datetime import datetime, timedelta |
11 from logging import getLogger |
12 from logging import getLogger |
12 |
13 |
13 from cubicweb import set_log_methods |
14 from cubicweb import set_log_methods |
14 from cubicweb.server.sqlutils import SQL_PREFIX |
15 from cubicweb.server.sqlutils import SQL_PREFIX |
|
16 |
15 |
17 |
16 |
18 |
17 class TimedCache(dict): |
19 class TimedCache(dict): |
18 def __init__(self, ttlm, ttls=0): |
20 def __init__(self, ttlm, ttls=0): |
19 # time to live in minutes |
21 # time to live in minutes |
68 pass |
70 pass |
69 |
71 |
70 def init(self): |
72 def init(self): |
71 """method called by the repository once ready to handle request""" |
73 """method called by the repository once ready to handle request""" |
72 pass |
74 pass |
|
75 |
|
76 def backup_file(self, backupfile=None, timestamp=None): |
|
77 """return a unique file name for a source's dump |
|
78 |
|
79 either backupfile or timestamp (used to generated a backup file name if |
|
80 needed) should be specified. |
|
81 """ |
|
82 if backupfile is None: |
|
83 config = self.repo.config |
|
84 return join(config.appdatahome, 'backup', |
|
85 '%s-%s-%s.dump' % (config.appid, timestamp, self.uri)) |
|
86 # backup file is the system database backup file, add uri to it if not |
|
87 # already there |
|
88 base, ext = splitext(backupfile) |
|
89 if not base.endswith('-%s' % self.uri): |
|
90 return '%s-%s%s' % (base, self.uri, ext) |
|
91 return backupfile |
|
92 |
|
93 def backup(self, confirm, backupfile=None, timestamp=None, |
|
94 askconfirm=False): |
|
95 """method called to create a backup of source's data""" |
|
96 pass |
|
97 |
|
98 def restore(self, confirm, backupfile=None, timestamp=None, drop=True, |
|
99 askconfirm=False): |
|
100 """method called to restore a backup of source's data""" |
|
101 pass |
|
102 |
|
103 def close_pool_connections(self): |
|
104 for pool in self.repo.pools: |
|
105 pool._cursors.pop(self.uri, None) |
|
106 pool.source_cnxs[self.uri][1].close() |
|
107 |
|
108 def open_pool_connections(self): |
|
109 for pool in self.repo.pools: |
|
110 pool.source_cnxs[self.uri] = (self, self.get_connection()) |
73 |
111 |
74 def reset_caches(self): |
112 def reset_caches(self): |
75 """method called during test to reset potential source caches""" |
113 """method called during test to reset potential source caches""" |
76 pass |
114 pass |
77 |
115 |