def get_current_db_version(self): """Return the current version of the database""" db_version = self._sql_execute("SELECT db_version FROM core_system_info").fetchone()[0] if db_version is None or db_version == '': # Should only happen for the first upgrade using this script return NormalizedVersion('0.1.0') else: return NormalizedVersion(self._suggest_normalized_version(db_version))
def mkversion(version_obj): try: if hasattr(version_obj, 'slug'): ver = NormalizedVersion(suggest_normalized_version(version_obj.slug)) else: ver = NormalizedVersion(suggest_normalized_version(version_obj['slug'])) return ver except TypeError: return None
def make_version(version): ver = mkversion(version) if not ver: if version.slug == LATEST: return NormalizedVersion('99999.0', error_on_huge_major_num=False) elif version.slug == STABLE: return NormalizedVersion('9999.0', error_on_huge_major_num=False) else: return NormalizedVersion('999.0', error_on_huge_major_num=False) return ver
def make_version(version): ver = mkversion(version) if not ver: if version.slug == 'latest': return NormalizedVersion('99999.0', error_on_huge_major_num=False) elif version.slug == 'stable': return NormalizedVersion('9999.0', error_on_huge_major_num=False) else: return NormalizedVersion('999.0', error_on_huge_major_num=False) return ver
def get_current_app_version(self): """Return the current version of the application""" try: app_version = self._sql_execute("SELECT app_version FROM core_system_info").fetchone()[0] # Should only happen if the 'app_version' column doesn't exist (first application upgrade using this script) if app_version is None or app_version == '': app_version = NormalizedVersion('0.1.0') return NormalizedVersion(self._suggest_normalized_version(app_version)) except Exception: return NormalizedVersion('0.1.0')
def app_upgrade(upgrade_instance): """Eventually upgrade the application (depending on the current version number) @param upgrade_instance : instance of the Upgrade object @return true if an upgrade was done """ old_app_version = upgrade_instance.get_current_app_version() new_app_version = upgrade_instance.get_new_app_version() if new_app_version == NormalizedVersion('0.2.0'): if old_app_version == NormalizedVersion('0.1.0'): _upgrade_app_from_0_1_0_to_0_2_0(upgrade_instance) return True return False
def test_from_parts(self): for v, s in self.versions: parts = v.parts v2 = V.from_parts(*v.parts) self.assertEquals(v, v2) self.assertEquals(str(v), str(v2))
def sort_version_aware(versions): """ Takes a list of versions objects and sort them caring about version schemes """ from distutils2.version import NormalizedVersion from projects.utils import mkversion fallback = NormalizedVersion('99999999.0', error_on_huge_major_num=False) return sorted(versions, key=lambda v:(mkversion(v) or fallback), reverse=True)
def set_version(self, version): try: self._version = NormalizedVersion(version) except IrrationalVersionError: suggestion = suggest_normalized_version(version) if suggestion: self.version = suggestion else: raise IrrationalVersionError(version)
def test_from_parts(self): for v, s in self.versions: v2 = V.from_parts(*v.parts) self.assertEqual(v, v2) self.assertEqual(str(v), str(v2))
def mkversion(version_obj): try: ver = NormalizedVersion(suggest_normalized_version(version_obj.slug)) return ver except TypeError: return None
def _create_package_for_external(self, id, output_dir, force): """ Create package for a external 1. read json file to get informations and list of files 2. generate package @param id : name of external @param output_dir : target directory for package @param force : False : ask for confirmation """ self.log("Hardware id : %s" % id) if PACKAGE_MODE == True: msg = "Domogik in 'production' mode (packages management activated) : creating a package is not possible" self.log(msg) return try: pkg_obj = PackageJson(id, pkg_type="external") pkg_json = pkg_obj.json except: self.log(str(traceback.format_exc())) return # check version format try: NormalizedVersion(pkg_json["identity"]["version"]) except: self.log("Plugin version '%s' is not valid. Exiting." % pkg_json["identity"]["version"]) return try: NormalizedVersion(pkg_json["identity"]["domogik_min_version"]) except: self.log("Domogik min version '%s' is not valid. Exiting." % pkg_json["identity"]["domogik_min_version"]) return self.log("Json file OK") if pkg_json["identity"]["type"] != "external": self.log("Error : this package is not an external member") return # display external informations pkg_obj.display() # check file existence if pkg_json["files"] == []: self.log("There is no file defined : the package won't be created") return # check doc files exist doc_path = DOC_PATH + "/external/%s/" % id doc_fullpath = SRC_PATH + doc_path if not os.path.isdir(doc_fullpath): self.log( "There is no documentation files in '%s' : the package won't be created" % doc_fullpath) return if force == False: self.log("\nAre these informations OK ?") resp = raw_input("[o/N]") if resp.lower() != "o": self.log("Exiting...") return # Copy Json file in a temporary location in order to complete it json_tmp_file = "%s/external-%s-%s.json" % (tempfile.gettempdir( ), pkg_json["identity"]["id"], pkg_json["identity"]["version"]) shutil.copyfile(pkg_json["identity"]["info_file"], json_tmp_file) # Update info.json with generation date pkg_obj.set_generated(json_tmp_file) # Create .tgz self._create_tar_gz( "external-%s-%s" % (pkg_json["identity"]["id"], pkg_json["identity"]["version"]), output_dir, pkg_json["all_files"], json_tmp_file, pkg_json["identity"]["icon_file"], doc_fullpath)
def is_stage_or_prod(tag): try: NormalizedVersion(version) return True except IrrationalVersionError: return False
def is_prod(tag): try: return NormalizedVersion(version).is_final except IrrationalVersionError: return False
def get_new_app_version(self): """Return the version of the application we should upgrade to (normalized version)""" return NormalizedVersion(self._suggest_normalized_version(__version__))
def get_new_db_version(self): """Return the version of the database we should upgrade to (normalized version)""" return NormalizedVersion(self._suggest_normalized_version(DB_VERSION))