server/migractions.py
changeset 7398 26695dd703d8
parent 7342 d1c8b5b3531c
child 7412 9179ae452159
equal deleted inserted replaced
7397:6a9e66d788b3 7398:26695dd703d8
   199                 format_file.write('%s\n' % format)
   199                 format_file.write('%s\n' % format)
   200             with open(osp.join(tmpdir, 'versions.txt'), 'w') as version_file:
   200             with open(osp.join(tmpdir, 'versions.txt'), 'w') as version_file:
   201                 versions = repo.get_versions()
   201                 versions = repo.get_versions()
   202                 for cube, version in versions.iteritems():
   202                 for cube, version in versions.iteritems():
   203                     version_file.write('%s %s\n' % (cube, version))
   203                     version_file.write('%s %s\n' % (cube, version))
   204                     
       
   205             if not failed:
   204             if not failed:
   206                 bkup = tarfile.open(backupfile, 'w|gz')
   205                 bkup = tarfile.open(backupfile, 'w|gz')
   207                 for filename in os.listdir(tmpdir):
   206                 for filename in os.listdir(tmpdir):
   208                     bkup.add(osp.join(tmpdir, filename), filename)
   207                     bkup.add(osp.join(tmpdir, filename), filename)
   209                 bkup.close()
   208                 bkup.close()
   240         if osp.isfile(osp.join(tmpdir, 'format.txt')):
   239         if osp.isfile(osp.join(tmpdir, 'format.txt')):
   241             with open(osp.join(tmpdir, 'format.txt')) as format_file:
   240             with open(osp.join(tmpdir, 'format.txt')) as format_file:
   242                 written_format = format_file.readline().strip()
   241                 written_format = format_file.readline().strip()
   243                 if written_format in ('portable', 'native'):
   242                 if written_format in ('portable', 'native'):
   244                     format = written_format
   243                     format = written_format
   245         self.config.open_connections_pools = False
   244         self.config.init_cnxset_pool = False
   246         repo = self.repo_connect()
   245         repo = self.repo_connect()
   247         for source in repo.sources:
   246         for source in repo.sources:
   248             if systemonly and source.uri != 'system':
   247             if systemonly and source.uri != 'system':
   249                 continue
   248                 continue
   250             try:
   249             try:
   253                 print '-> error trying to restore %s [%s]' % (source.uri, exc)
   252                 print '-> error trying to restore %s [%s]' % (source.uri, exc)
   254                 if not self.confirm('Continue anyway?', default='n'):
   253                 if not self.confirm('Continue anyway?', default='n'):
   255                     raise SystemExit(1)
   254                     raise SystemExit(1)
   256         shutil.rmtree(tmpdir)
   255         shutil.rmtree(tmpdir)
   257         # call hooks
   256         # call hooks
   258         repo.open_connections_pools()
   257         repo.init_cnxset_pool()
   259         repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile)
   258         repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile)
   260         print '-> database restored.'
   259         print '-> database restored.'
   261 
   260 
   262     @property
   261     @property
   263     def cnx(self):
   262     def cnx(self):
   286                 try:
   285                 try:
   287                     login, pwd = manager_userpasswd()
   286                     login, pwd = manager_userpasswd()
   288                 except (KeyboardInterrupt, EOFError):
   287                 except (KeyboardInterrupt, EOFError):
   289                     print 'aborting...'
   288                     print 'aborting...'
   290                     sys.exit(0)
   289                     sys.exit(0)
   291             self.session.keep_pool_mode('transaction')
   290             self.session.keep_cnxset_mode('transaction')
   292             self.session.data['rebuild-infered'] = False
   291             self.session.data['rebuild-infered'] = False
   293             return self._cnx
   292             return self._cnx
   294 
   293 
   295     @property
   294     @property
   296     def session(self):
   295     def session(self):
   297         if self.config is not None:
   296         if self.config is not None:
   298             session = self.repo._get_session(self.cnx.sessionid)
   297             session = self.repo._get_session(self.cnx.sessionid)
   299             if session.pool is None:
   298             if session.cnxset is None:
   300                 session.set_read_security(False)
   299                 session.set_read_security(False)
   301                 session.set_write_security(False)
   300                 session.set_write_security(False)
   302             session.set_pool()
   301             session.set_cnxset()
   303             return session
   302             return session
   304         # no access to session on remote instance
   303         # no access to session on remote instance
   305         return None
   304         return None
   306 
   305 
   307     def commit(self):
   306     def commit(self):
   308         if hasattr(self, '_cnx'):
   307         if hasattr(self, '_cnx'):
   309             self._cnx.commit()
   308             self._cnx.commit()
   310         if self.session:
   309         if self.session:
   311             self.session.set_pool()
   310             self.session.set_cnxset()
   312 
   311 
   313     def rollback(self):
   312     def rollback(self):
   314         if hasattr(self, '_cnx'):
   313         if hasattr(self, '_cnx'):
   315             self._cnx.rollback()
   314             self._cnx.rollback()
   316         if self.session:
   315         if self.session:
   317             self.session.set_pool()
   316             self.session.set_cnxset()
   318 
   317 
   319     def rqlexecall(self, rqliter, ask_confirm=False):
   318     def rqlexecall(self, rqliter, ask_confirm=False):
   320         for rql, kwargs in rqliter:
   319         for rql, kwargs in rqliter:
   321             self.rqlexec(rql, kwargs, ask_confirm=ask_confirm)
   320             self.rqlexec(rql, kwargs, ask_confirm=ask_confirm)
   322 
   321 
  1358 
  1357 
  1359     @property
  1358     @property
  1360     def _cw(self):
  1359     def _cw(self):
  1361         session = self.session
  1360         session = self.session
  1362         if session is not None:
  1361         if session is not None:
  1363             session.set_pool()
  1362             session.set_cnxset()
  1364             return session
  1363             return session
  1365         return self.cnx.request()
  1364         return self.cnx.request()
  1366 
  1365 
  1367     def cmd_storage_changed(self, etype, attribute):
  1366     def cmd_storage_changed(self, etype, attribute):
  1368         """migrate entities to a custom storage. The new storage is expected to
  1367         """migrate entities to a custom storage. The new storage is expected to