def upgrade_instance(self, appid): print('\n' + underline_title('Upgrading the instance %s' % appid)) from logilab.common.changelog import Version config = cwcfg.config_for(appid) config.repairing = True # notice we're not starting the server config.verbosity = self.config.verbosity set_sources_mode = getattr(config, 'set_sources_mode', None) if set_sources_mode is not None: set_sources_mode(self.config.ext_sources or ('migration', )) # get instance and installed versions for the server and the componants mih = config.migration_handler() repo = mih.repo vcconf = repo.get_versions() helper = self.config_helper(config, required=False) if self.config.force_cube_version: for cube, version in self.config.force_cube_version.items(): vcconf[cube] = Version(version) toupgrade = [] for cube in config.cubes(): installedversion = config.cube_version(cube) try: applversion = vcconf[cube] except KeyError: config.error('no version information for %s' % cube) continue if installedversion > applversion: toupgrade.append((cube, applversion, installedversion)) cubicwebversion = config.cubicweb_version() if self.config.force_cubicweb_version: applcubicwebversion = Version(self.config.force_cubicweb_version) vcconf['cubicweb'] = applcubicwebversion else: applcubicwebversion = vcconf.get('cubicweb') if cubicwebversion > applcubicwebversion: toupgrade.append( ('cubicweb', applcubicwebversion, cubicwebversion)) # run cubicweb/componants migration scripts if self.config.fs_only or toupgrade: for cube, fromversion, toversion in toupgrade: print('-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)) with mih.cnx: with mih.cnx.security_enabled(False, False): mih.migrate(vcconf, reversed(toupgrade), self.config) clear_cache(config, 'instance_md5_version') else: print('-> no data migration needed for instance %s.' % appid) # rewrite main configuration file if not self.config.no_config_update: mih.rewrite_configuration() mih.shutdown() # handle i18n upgrade if not self.i18nupgrade(config): return print() if helper: helper.postupgrade(repo) print('-> instance migrated.') print()
def version_strictly_lower(a, b): if a is None: return True if b is None: return False if a: a = Version(a) if b: b = Version(b) return a < b
def cube_version(cls, cube): """return the version of the cube located in the given directory """ from logilab.common.changelog import Version version = cls.cube_pkginfo(cube).numversion assert len(version) == 3, version return Version(version)
def cubicweb_version(): """return installed cubicweb version""" from logilab.common.changelog import Version str_base_version = pkg_resources.get_distribution('cubicweb').parsed_version.base_version version = tuple([int(x) for x in str_base_version.split('.')]) assert len(version) == 3, version return Version(version)
def cubicweb_version(): """return installed cubicweb version""" from logilab.common.changelog import Version from cubicweb import __pkginfo__ version = __pkginfo__.numversion assert len(version) == 3, version return Version(version)
def get_versions(self, checkversions=False): """Return the a dictionary containing cubes used by this instance as key with their version as value, including cubicweb version. This is a public method, not requiring a session id. """ from logilab.common.changelog import Version vcconf = {} with self.internal_cnx() as cnx: for pk, version in cnx.execute( 'Any K,V WHERE P is CWProperty, P value V, P pkey K, ' 'P pkey ~="system.version.%"', build_descr=False): cube = pk.split('.')[-1] # XXX cubicweb migration if cube in CW_MIGRATION_MAP: cube = CW_MIGRATION_MAP[cube] version = Version(version) vcconf[cube] = version if checkversions: if cube != 'cubicweb': fsversion = self.config.cube_version(cube) else: fsversion = self.config.cubicweb_version() if version < fsversion: msg = ('instance has %s version %s but %s ' 'is installed. Run "cubicweb-ctl upgrade %s".') raise ExecutionError( msg % (cube, version, fsversion, self.config.appid)) return vcconf
def warn(self, version=None, reason="", stacklevel=2): """Display a deprecation message only if the version is older than the compatible version. """ if (self.compatible_version is None or version is None or Version(version) < self.compatible_version): if self.module_name and version: reason = '[%s %s] %s' % (self.module_name, version, reason) elif self.module_name: reason = '[%s] %s' % (self.module_name, reason) elif version: reason = '[%s] %s' % (version, reason) warn(reason, DeprecationWarning, stacklevel=stacklevel)
def filter_scripts(config, directory, fromversion, toversion, quiet=True): """return a list of paths of migration files to consider to upgrade from a version to a greater one """ from logilab.common.changelog import Version # doesn't work with appengine assert fromversion assert toversion assert isinstance(fromversion, tuple), fromversion.__class__ assert isinstance(toversion, tuple), toversion.__class__ assert fromversion <= toversion, (fromversion, toversion) if not exists(directory): if not quiet: print(directory, "doesn't exists, no migration path") return [] if fromversion == toversion: return [] result = [] for fname in os.listdir(directory): if fname.endswith(IGNORED_EXTENSIONS): continue fpath = join(directory, fname) try: tver, mode = fname.split('_', 1) except ValueError: continue mode = mode.split('.', 1)[0] if not config.accept_mode(mode): continue try: tver = Version(tver) except ValueError: continue if tver <= fromversion: continue if tver > toversion: continue result.append((tver, fpath)) # be sure scripts are executed in order return sorted(result)
def max_version(a, b): return str(max(Version(a), Version(b)))
def compatibility(self, compatible_version): """Set the compatible version. """ self.compatible_version = Version(compatible_version)