def register_upgrade_hook(self, func, *args): """Register a function to upgrade from one config version to another""" to_version = Version.from_string(func.__name__) assert to_version <= PICARD_VERSION, "%r > %r !!!" % (to_version, PICARD_VERSION) self._upgrade_hooks[to_version] = { 'func': func, 'args': args, 'done': False }
def __initialize(self): """Common initializer method for :meth:`from_app` and :meth:`from_file`.""" self.setAtomicSyncRequired(False) # See comment in event() self.application = ConfigSection(self, "application") self.profiles = ConfigSection(self, "profiles") self.setting = SettingConfigSection(self, "setting") self.persist = ConfigSection(self, "persist") TextOption("application", "version", '0.0.0dev0') self._version = Version.from_string(self.application["version"]) self._upgrade_hooks = dict()
def __initialize(self): """Common initializer method for :meth:`from_app` and :meth:`from_file`.""" self.application = ConfigSection(self, "application") self.setting = ConfigSection(self, "setting") self.persist = ConfigSection(self, "persist") self.profile = ConfigSection(self, "profile/default") self.current_preset = "default" TextOption("application", "version", '0.0.0dev0') self._version = Version.from_string(self.application["version"]) self._upgrade_hooks = dict()
def test_version_conversion_short(self): versions = ( (Version(1, 1, 0, 'final', 0), '1.1'), (Version(1, 1, 1, 'final', 0), '1.1.1'), (Version(0, 0, 1, 'dev', 1), '0.0.1.dev1'), (Version(1, 1, 0, 'dev', 0), '1.1.0.dev0'), (Version(1, 1, 2, 'alpha', 2), '1.1.2a2'), (Version(1, 1, 2, 'a', 2), '1.1.2a2'), (Version(1, 1, 2, 'beta', 2), '1.1.2b2'), (Version(1, 1, 2, 'b', 2), '1.1.2b2'), (Version(1, 1, 2, 'rc', 2), '1.1.2rc2'), ) for v, s in versions: self.assertEqual(version_to_string(v, short=True), s) self.assertEqual(v.to_string(short=True), s) self.assertEqual(v, Version.from_string(s)) self.assertEqual(v, version_from_string(s))
def test_version_conversion(self): versions = ( (Version(1, 1, 0, 'final', 0), '1.1.0.final0'), (Version(0, 0, 1, 'dev', 1), '0.0.1.dev1'), (Version(1, 1, 0, 'dev', 0), '1.1.0.dev0'), (Version(999, 999, 999, 'dev', 999), '999.999.999.dev999'), (Version(1, 1, 2, 'alpha', 2), '1.1.2.alpha2'), (Version(1, 1, 2, 'a', 2), '1.1.2.alpha2'), (Version(1, 1, 2, 'beta', 2), '1.1.2.beta2'), (Version(1, 1, 2, 'b', 2), '1.1.2.beta2'), (Version(1, 1, 2, 'rc', 2), '1.1.2.rc2'), ) for v, s in versions: self.assertEqual(version_to_string(v), s) self.assertEqual(str(v), s) self.assertEqual(v, Version.from_string(s)) self.assertEqual(v, version_from_string(s))
def test_compatible_api_version(self): # use first element from picard.api_versions, it should be compatible api_versions = picard.api_versions[:1] expected = set([Version.from_string(v) for v in api_versions]) result = _compatible_api_versions(api_versions) self.assertEqual(result, expected) # pretty sure 0.0 isn't compatible api_versions = ["0.0"] expected = set() result = _compatible_api_versions(api_versions) self.assertEqual(result, expected) # buggy version api_versions = ["0.a"] with self.assertRaises(VersionError): result = _compatible_api_versions(api_versions)
def __initialize(self): """Common initializer method for :meth:`from_app` and :meth:`from_file`.""" self.application = ConfigSection(self, "application") self.setting = ConfigSection(self, "setting") self.persist = ConfigSection(self, "persist") self.profile = ConfigSection(self, "profile/default") self.current_preset = "default" TextOption("application", "version", '0.0.0dev0') self._version = Version.from_string(self.application["version"]) self._upgrade_hooks = dict() # Save known config names for faster access and to prevent # strange cases of Qt locking up when accessing QSettings.allKeys() # or QSettings.contains() shortly after having written settings # inside threads. # See https://tickets.metabrainz.org/browse/PICARD-1590 self.__known_keys = set(self.allKeys())
def version_from_string(version_str): """Deprecated: Use picard.version.Version.from_string instead""" return Version.from_string(version_str)
__version__ = PICARD_VERSION_STR_SHORT PICARD_FANCY_VERSION_STR = PICARD_VERSION_STR_SHORT # Keep those ordered api_versions = [ "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", ] api_versions_tuple = [Version.from_string(v) for v in api_versions] def crash_handler(): """Implements minimal handling of an exception crashing the application. This function tries to log the exception to a log file and display a minimal crash dialog to the user. This function is supposed to be called from inside an except blog. """ import sys # Allow disabling the graphical crash handler for debugging and CI purposes. if set(sys.argv) & { '--no-crash-dialog', '-v', '--version', '-V', '--long-version', '-h', '--help' }:
def version(self): try: return Version.from_string(self.__dict__['version']) except (KeyError, VersionError): return Version(0, 0, 0)
def version(self): try: return Version.from_string(self.data['PLUGIN_VERSION']) except (KeyError, VersionError): return Version(0, 0, 0)
def _compatible_api_versions(api_versions): versions = [Version.from_string(v) for v in list(api_versions)] return set(versions) & set(picard.api_versions_tuple)