cwctl.py
brancholdstable
changeset 7676 cc3987eb793c
parent 7593 0c1024b3e7fc
child 7595 83872394b5d9
equal deleted inserted replaced
7388:dc319ece0bd6 7676:cc3987eb793c
   150         for appid in args:
   150         for appid in args:
   151             if askconfirm:
   151             if askconfirm:
   152                 print '*'*72
   152                 print '*'*72
   153                 if not ASK.confirm('%s instance %r ?' % (self.name, appid)):
   153                 if not ASK.confirm('%s instance %r ?' % (self.name, appid)):
   154                     continue
   154                     continue
   155             status = max(status, self.run_arg(appid))
   155             try:
       
   156                 status = max(status, self.run_arg(appid))
       
   157             except (KeyboardInterrupt, SystemExit):
       
   158                 print >> sys.stderr, '%s aborted' % self.name
       
   159                 return 2 # specific error code
   156         sys.exit(status)
   160         sys.exit(status)
   157 
   161 
   158     def run_arg(self, appid):
   162     def run_arg(self, appid):
   159         cmdmeth = getattr(self, '%s_instance' % self.name)
   163         cmdmeth = getattr(self, '%s_instance' % self.name)
   160         try:
   164         try:
   161             status = cmdmeth(appid)
   165             status = cmdmeth(appid)
   162         except (KeyboardInterrupt, SystemExit):
       
   163             print >> sys.stderr, '%s aborted' % self.name
       
   164             return 2 # specific error code
       
   165         except (ExecutionError, ConfigurationError), ex:
   166         except (ExecutionError, ConfigurationError), ex:
   166             print >> sys.stderr, 'instance %s not %s: %s' % (
   167             print >> sys.stderr, 'instance %s not %s: %s' % (
   167                 appid, self.actionverb, ex)
   168                 appid, self.actionverb, ex)
   168             status = 4
   169             status = 4
   169         except Exception, ex:
   170         except Exception, ex:
   755             vcconf['cubicweb'] = applcubicwebversion
   756             vcconf['cubicweb'] = applcubicwebversion
   756         else:
   757         else:
   757             applcubicwebversion = vcconf.get('cubicweb')
   758             applcubicwebversion = vcconf.get('cubicweb')
   758         if cubicwebversion > applcubicwebversion:
   759         if cubicwebversion > applcubicwebversion:
   759             toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
   760             toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
   760         if not self.config.fs_only and not toupgrade:
       
   761             print '-> no data migration needed for instance %s.' % appid
       
   762             self.i18nupgrade(config)
       
   763             mih.shutdown()
       
   764             return
       
   765         for cube, fromversion, toversion in toupgrade:
       
   766             print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)
       
   767         # only stop once we're sure we have something to do
   761         # only stop once we're sure we have something to do
   768         if not (CWDEV or self.config.nostartstop):
   762         if not (CWDEV or self.config.nostartstop):
   769             StopInstanceCommand(self.logger).stop_instance(appid)
   763             StopInstanceCommand(self.logger).stop_instance(appid)
   770         # run cubicweb/componants migration scripts
   764         # run cubicweb/componants migration scripts
   771         mih.migrate(vcconf, reversed(toupgrade), self.config)
   765         if self.config.fs_only or toupgrade:
       
   766             for cube, fromversion, toversion in toupgrade:
       
   767                 print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)
       
   768             mih.migrate(vcconf, reversed(toupgrade), self.config)
       
   769         else:
       
   770             print '-> no data migration needed for instance %s.' % appid
   772         # rewrite main configuration file
   771         # rewrite main configuration file
   773         mih.rewrite_configuration()
   772         mih.rewrite_configuration()
   774         mih.shutdown()
   773         mih.shutdown()
   775         # handle i18n upgrade
   774         # handle i18n upgrade
   776         if not self.i18nupgrade(config):
   775         if not self.i18nupgrade(config):
   903                 # use cmdline parser to access left/right attributes only
   902                 # use cmdline parser to access left/right attributes only
   904                 # remember that usage requires instance appid as first argument
   903                 # remember that usage requires instance appid as first argument
   905                 scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs
   904                 scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs
   906                 for script in scripts:
   905                 for script in scripts:
   907                     mih.cmd_process_script(script, scriptargs=args)
   906                     mih.cmd_process_script(script, scriptargs=args)
       
   907                     mih.commit()
   908             else:
   908             else:
   909                 mih.interactive_shell()
   909                 mih.interactive_shell()
   910         finally:
   910         finally:
   911             if not self.config.pyro:
   911             if not self.config.pyro:
   912                 mih.shutdown()
   912                 mih.shutdown()