cwctl.py
changeset 2512 106b2a05dc88
parent 2489 37a747ad6fd4
child 2532 f7ca29d75183
equal deleted inserted replaced
2511:a4b50efb97f6 2512:106b2a05dc88
   612     def ordered_instances(self):
   612     def ordered_instances(self):
   613         # need this since mro return StopInstanceCommand implementation
   613         # need this since mro return StopInstanceCommand implementation
   614         return InstanceCommand.ordered_instances(self)
   614         return InstanceCommand.ordered_instances(self)
   615 
   615 
   616     def upgrade_instance(self, appid):
   616     def upgrade_instance(self, appid):
       
   617         print '\n' + underline_title('Upgrading the instance %s' % appid)
   617         from logilab.common.changelog import Version
   618         from logilab.common.changelog import Version
   618         config = cwcfg.config_for(appid)
   619         config = cwcfg.config_for(appid)
   619         config.repairing = True # notice we're not starting the server
   620         config.repairing = True # notice we're not starting the server
   620         config.verbosity = self.config.verbosity
   621         config.verbosity = self.config.verbosity
   621         try:
   622         try:
   622             config.set_sources_mode(self.config.ext_sources or ('migration',))
   623             config.set_sources_mode(self.config.ext_sources or ('migration',))
   623         except AttributeError:
   624         except AttributeError:
   624             # not a server config
   625             # not a server config
   625             pass
   626             pass
   626         # get instance and installed versions for the server and the componants
   627         # get instance and installed versions for the server and the componants
   627         print 'getting versions configuration from the repository...'
       
   628         mih = config.migration_handler()
   628         mih = config.migration_handler()
   629         repo = mih.repo_connect()
   629         repo = mih.repo_connect()
   630         vcconf = repo.get_versions()
   630         vcconf = repo.get_versions()
   631         print 'done'
       
   632         if self.config.force_componant_version:
   631         if self.config.force_componant_version:
   633             packversions = {}
   632             packversions = {}
   634             for vdef in self.config.force_componant_version:
   633             for vdef in self.config.force_componant_version:
   635                 componant, version = vdef.split('=')
   634                 componant, version = vdef.split('=')
   636                 packversions[componant] = Version(version)
   635                 packversions[componant] = Version(version)
   652         else:
   651         else:
   653             applcubicwebversion = vcconf.get('cubicweb')
   652             applcubicwebversion = vcconf.get('cubicweb')
   654         if cubicwebversion > applcubicwebversion:
   653         if cubicwebversion > applcubicwebversion:
   655             toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
   654             toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
   656         if not self.config.fs_only and not toupgrade:
   655         if not self.config.fs_only and not toupgrade:
   657             print 'no software migration needed for instance %s' % appid
   656             print '-> no software migration needed for instance %s.' % appid
   658             return
   657             return
   659         for cube, fromversion, toversion in toupgrade:
   658         for cube, fromversion, toversion in toupgrade:
   660             print '**** %s migration %s -> %s' % (cube, fromversion, toversion)
   659             print '\n' + underline_title('%s migration %s -> %s' %
       
   660                                          (cube, fromversion, toversion))
   661         # only stop once we're sure we have something to do
   661         # only stop once we're sure we have something to do
   662         if not (cwcfg.mode == 'dev' or self.config.nostartstop):
   662         if not (cwcfg.mode == 'dev' or self.config.nostartstop):
   663             self.stop_instance(appid)
   663             self.stop_instance(appid)
   664         # run cubicweb/componants migration scripts
   664         # run cubicweb/componants migration scripts
   665         mih.migrate(vcconf, reversed(toupgrade), self.config)
   665         mih.migrate(vcconf, reversed(toupgrade), self.config)
   673         templdir = cwcfg.cube_dir(config.cubes()[0])
   673         templdir = cwcfg.cube_dir(config.cubes()[0])
   674         langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))]
   674         langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))]
   675         errors = config.i18ncompile(langs)
   675         errors = config.i18ncompile(langs)
   676         if errors:
   676         if errors:
   677             print '\n'.join(errors)
   677             print '\n'.join(errors)
   678             if not confirm('error while compiling message catalogs, '
   678             if not confirm('Error while compiling message catalogs, '
   679                            'continue anyway ?'):
   679                            'continue anyway ?'):
   680                 print 'migration not completed'
   680                 print '-> migration not completed.'
   681                 return
   681                 return
   682         mih.shutdown()
   682         mih.shutdown()
   683         print
   683         print
   684         print 'instance migrated'
   684         print '-> instance migrated.'
   685         if not (cwcfg.mode == 'dev' or self.config.nostartstop):
   685         if not (cwcfg.mode == 'dev' or self.config.nostartstop):
   686             self.start_instance(appid)
   686             self.start_instance(appid)
   687         print
   687         print
   688 
   688 
   689 
   689