server/migractions.py
changeset 8695 358d8bed9626
parent 8694 d901c36bcfce
child 8696 0bb18407c053
equal deleted inserted replaced
8694:d901c36bcfce 8695:358d8bed9626
   153 
   153 
   154     def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs):
   154     def cmd_process_script(self, migrscript, funcname=None, *args, **kwargs):
   155         try:
   155         try:
   156             return super(ServerMigrationHelper, self).cmd_process_script(
   156             return super(ServerMigrationHelper, self).cmd_process_script(
   157                   migrscript, funcname, *args, **kwargs)
   157                   migrscript, funcname, *args, **kwargs)
   158         except ExecutionError, err:
   158         except ExecutionError as err:
   159             sys.stderr.write("-> %s\n" % err)
   159             sys.stderr.write("-> %s\n" % err)
   160         except BaseException:
   160         except BaseException:
   161             self.rollback()
   161             self.rollback()
   162             raise
   162             raise
   163 
   163 
   191         try:
   191         try:
   192             failed = False
   192             failed = False
   193             for source in repo.sources:
   193             for source in repo.sources:
   194                 try:
   194                 try:
   195                     source.backup(osp.join(tmpdir, source.uri), self.confirm, format=format)
   195                     source.backup(osp.join(tmpdir, source.uri), self.confirm, format=format)
   196                 except Exception, ex:
   196                 except Exception as ex:
   197                     print '-> error trying to backup %s [%s]' % (source.uri, ex)
   197                     print '-> error trying to backup %s [%s]' % (source.uri, ex)
   198                     if not self.confirm('Continue anyway?', default='n'):
   198                     if not self.confirm('Continue anyway?', default='n'):
   199                         raise SystemExit(1)
   199                         raise SystemExit(1)
   200                     else:
   200                     else:
   201                         failed = True
   201                         failed = True
   250         for source in repo.sources:
   250         for source in repo.sources:
   251             if systemonly and source.uri != 'system':
   251             if systemonly and source.uri != 'system':
   252                 continue
   252                 continue
   253             try:
   253             try:
   254                 source.restore(osp.join(tmpdir, source.uri), self.confirm, drop, format)
   254                 source.restore(osp.join(tmpdir, source.uri), self.confirm, drop, format)
   255             except Exception, exc:
   255             except Exception as exc:
   256                 print '-> error trying to restore %s [%s]' % (source.uri, exc)
   256                 print '-> error trying to restore %s [%s]' % (source.uri, exc)
   257                 if not self.confirm('Continue anyway?', default='n'):
   257                 if not self.confirm('Continue anyway?', default='n'):
   258                     raise SystemExit(1)
   258                     raise SystemExit(1)
   259         shutil.rmtree(tmpdir)
   259         shutil.rmtree(tmpdir)
   260         # call hooks
   260         # call hooks
   396         for fpath in sql_scripts:
   396         for fpath in sql_scripts:
   397             print '-> installing', fpath
   397             print '-> installing', fpath
   398             try:
   398             try:
   399                 sqlexec(open(fpath).read(), self.session.system_sql, False,
   399                 sqlexec(open(fpath).read(), self.session.system_sql, False,
   400                         delimiter=';;')
   400                         delimiter=';;')
   401             except Exception, exc:
   401             except Exception as exc:
   402                 print '-> ERROR:', exc, ', skipping', fpath
   402                 print '-> ERROR:', exc, ', skipping', fpath
   403 
   403 
   404     # schema synchronization internals ########################################
   404     # schema synchronization internals ########################################
   405 
   405 
   406     def _synchronize_permissions(self, erschema, teid):
   406     def _synchronize_permissions(self, erschema, teid):
  1455             else:
  1455             else:
  1456                 msg = rql
  1456                 msg = rql
  1457             if not ask_confirm or self.confirm('Execute rql: %s ?' % msg):
  1457             if not ask_confirm or self.confirm('Execute rql: %s ?' % msg):
  1458                 try:
  1458                 try:
  1459                     res = execute(rql, kwargs, build_descr=build_descr)
  1459                     res = execute(rql, kwargs, build_descr=build_descr)
  1460                 except Exception, ex:
  1460                 except Exception as ex:
  1461                     if self.confirm('Error: %s\nabort?' % ex, pdb=True):
  1461                     if self.confirm('Error: %s\nabort?' % ex, pdb=True):
  1462                         raise
  1462                         raise
  1463         return res
  1463         return res
  1464 
  1464 
  1465     def rqliter(self, rql, kwargs=None, ask_confirm=True):
  1465     def rqliter(self, rql, kwargs=None, ask_confirm=True):
  1549         if self.ask_confirm:
  1549         if self.ask_confirm:
  1550             if not self._h.confirm('Execute rql: %s ?' % msg):
  1550             if not self._h.confirm('Execute rql: %s ?' % msg):
  1551                 raise StopIteration
  1551                 raise StopIteration
  1552         try:
  1552         try:
  1553             return self._h._cw.execute(rql, kwargs)
  1553             return self._h._cw.execute(rql, kwargs)
  1554         except Exception, ex:
  1554         except Exception as ex:
  1555             if self._h.confirm('Error: %s\nabort?' % ex):
  1555             if self._h.confirm('Error: %s\nabort?' % ex):
  1556                 raise
  1556                 raise
  1557             else:
  1557             else:
  1558                 raise StopIteration
  1558                 raise StopIteration
  1559 
  1559