def test_minor(self): v1 = Version("v22.0.0") v2 = Version("v22.1.0") v3 = Version("v22.0.9") assert v2 > v1 assert v2 > v3
def test_different_formats_should_be_equal(self): v1 = Version(2) v2 = Version("2") v3 = Version(2.000000) v4 = Version("v0002.0.000000") assert v1 == v2 == v3 == v4
def test_patch(self): v1 = Version("v11.11.19") v2 = Version("v11.11.2") v3 = Version("v11.11.09") assert v1 > v2 assert v1 > v3
def test_major(self): v1 = Version("11.0.0") v2 = Version("12.0.0") v3 = Version("v11.99.99rc99") assert v2 > v1 assert v2 > v3
def get_valid_version(version_str: str, build_dir: str) -> str: build_version = get_build_version(build_dir) str_version = re.search(r'^([0-9\.]+)', version_str).group(1) if Version(build_version, ignore_trailing_zero=True) != Version( str_version, ignore_trailing_zero=True): return build_version else: return version_str
def test_comparing_against_non_version(): with raises(TypeError) as exception: Version('1.0.0') > None assert 'cannot compare' in repr(exception.value) with raises(TypeError) as exception: Version('1.0.0') == object() assert 'cannot compare' in repr(exception.value)
def __init__(self, versionRanges): # For soup/direct maven index: self.versions = [] if not isinstance(versionRanges, basestring): for vr in versionRanges: self.versions.append(Version(vr)) else: self.versions.append(Version(versionRanges)) self.versionRanges = versionRanges
def get_latest_version(site): data = urllib.request.urlopen(site) p = LinkParser() p.feed(data.read().decode('utf-8')) latest = Version('0.0') for link in p.links: ver = Version(link) if latest < ver: latest = ver return latest
def pkg(message): """Outputs a message with a package icon.""" import platform from version import Version mac_ver = platform.mac_ver()[0] if mac_ver and Version(mac_ver) >= Version('10.7'): print u"\U0001F4E6" + indent, else: cwrite('@*g{[+]} ') print message
def test_merge_with_self_and_self_produces_self(self): version_1_copy_string_1 = self.load_xml_string_from_file( self.file_test_version_1_A) version_1_copy_1 = Version(ET.fromstring(version_1_copy_string_1)) version_1_copy_string_2 = self.load_xml_string_from_file( self.file_test_version_1_A) version_1_copy_2 = Version(ET.fromstring(version_1_copy_string_2)) version_1_copy_1.merge_with(version_1_copy_1, version_1_copy_2) self.assertTrue( self.version_1.version_semantically_equal_to(version_1_copy_1))
def isSL(self, x=None): """ if x is given: returns True if os == Scientific Linux x if x is not given: returns a Version instance with the SL version otherwise returns False """ if( self.type == "Linux" ): if( self.ver.find( "Scientific" ) != -1 or self.ver.find( "RedHat" ) != -1): if x != None: return Version( self.ver )[0] == x else: return Version( self.ver ) return False
def test_section_3(): """Section 3. When a major version number is incremented, the minor version and patch version MUST be reset to zero. When a minor version number is incremented, the patch version MUST be reset to zero. For instance: 1.1.3 -> 2.0.0 and 2.1.7 -> 2.2.0. """ assert Version('1.1.3') < Version('2.0.0') assert Version('2.1.7') < Version('2.2.0')
def get_latest(site, directory): with ftplib.FTP() as ftp: ftp.connect(site) ftp.login() files = ftp.mlsd(directory) latest = Version(0.0) for file in files: if file[0] in ('.', '..'): continue if latest < file[0]: latest = Version(file[0]) return latest
def test_merge_with_self_and_branch_produces_branch(self): version_1_copy_string = self.load_xml_string_from_file( self.file_test_version_1_A) version_1_copy = Version(ET.fromstring(version_1_copy_string)) version_2_copy_string = self.load_xml_string_from_file( self.file_test_version_2_A) version_2_copy = Version(ET.fromstring(version_2_copy_string)) version_1_copy.merge_with(version_1_copy, version_2_copy) self.assertFalse( self.version_1.version_semantically_equal_to(version_2_copy)) self.assertTrue( version_1_copy.version_semantically_equal_to(version_2_copy))
def test_section_11(): """Section 11: Build version. A build version MAY be denoted by appending a plus sign and a series of dot separated identifiers immediately following the patch version or pre-release version. Identifiers MUST be comprised of only ASCII alphanumerics and dash [0-9A-Za-z-]. Build versions satisfy and have a higher precedence than the associated normal version. Examples: 1.0.0+build.1, 1.3.7+build.11.e0f985a. """ assert Version('1.0.0+build.1').build == ['build', 1] assert Version('1.0.0+build.11.e0f985a').build == ['build', 11, 'e0f985a']
def test_get_by_int(self): v = Version(1, 2, 3, 4, 5) self.assertEqual(v[0], v.major) self.assertEqual(v[1], v.minor) self.assertEqual(v[2], v.tiny) self.assertEqual(v[3], v.micro) self.assertEqual(v[4], v.nano)
def test_int_constructor(self): v = Version(1) self.assertEqual(v.major, 1) self.assertEqual(v.minor, 0) self.assertEqual(v.tiny, 0) self.assertEqual(v.micro, 0) self.assertEqual(v.nano, 0)
def main(): args = handle_args() content, date = load_pdf(args.input) session = prepare_db(args.dropall) # Before we go too far, we should make sure this pdf doesn't already exist date_str = time.strftime("%Y-%m-%dT%H:%M:%SZ", date) matching_versions = session.query(Version).filter( Version.date == date_str).count() if matching_versions > 0: print( "An entry already exists for this PDF. To drop all tables, run this script with --dropall" ) return else: version = Version(date_str) session.add(version) parse_content(content, version) for section in sections: session.add(section) for member in members: print(member.first_name, member.last_name + ", Member for", member.electorate) session.add(member) print("Committing to database...") session.commit() session.close() print("Done.")
def parse_version_min_os(self, lc): version = get_int(self.f) sdk = get_int(self.f) if self.macho.is_little(): version = little(version, 'I') sdk = little(sdk, 'I') version = Version(version=version) sdk = Version(version=sdk) lc.add_data('version', version.version) lc.add_data('sdk', sdk.version) self.macho.minos = version self.macho.add_lc(lc)
def test_none_constructor(self): v = Version(None) self.assertEqual(v.major, 0) self.assertEqual(v.minor, 0) self.assertEqual(v.tiny, 0) self.assertEqual(v.micro, 0) self.assertEqual(v.nano, 0)
def test_string_constructor(self): v = Version('1.2.3.4.5') self.assertEqual(v.major, 1) self.assertEqual(v.minor, 2) self.assertEqual(v.tiny, 3) self.assertEqual(v.micro, 4) self.assertEqual(v.nano, 5)
def __init__(self): Config().load() if len(sys.argv) > 1 and sys.argv[1] == "--silent": Log().silent() Log().add('info', 'gpustatd %s starting up' % (Version().get())) if self.already_running(): Log().add('fatal', 'gpustatd is already running') self.create_pid_file() self.throttled = [] self.target_temperature = Config().get('target_temperature') self.fan_speed_temperature_ratio = Config().get( 'fan_speed_temperature_ratio') os.environ["DISPLAY"] = ":%d" % (Config().get('xorg_display_no')) Log().add('info', 'scanning devices') self.devices = Nvidia().refresh(True) self.speeds = {} for device_id in self.devices.keys(): self.speeds[device_id] = self.devices[device_id]['fan'] self.self_test()
def __get_online_version_from_bitbucket(self, include_alpha_beta=False): """ Retrieves the current online version. :param bool include_alpha_beta: should we include alpha/beta releases? :return: Returns the current online version or `None` of no version was found. :rtype: None|Version """ data = self.__uriHandler.open(self.updateUrl, no_cache=True) json_data = JsonHelper(data) online_downloads = [d for d in json_data.get_value("values") if self.__is_valid_update(d)] if len(online_downloads) == 0: return None max_version = None for online_download in online_downloads: online_parts = online_download['name'].rsplit(".", 1)[0].split("-") if len(online_parts) < 2: continue # fix the problem that a ~ is preventing downloads on BitBucket online_version_data = online_parts[1].replace("alpha", "~alpha").replace("beta", "~beta") online_version = Version(online_version_data) if not include_alpha_beta and online_version.buildType is not None: self.__logger.trace("Ignoring %s", online_version) continue self.__logger.trace("Found possible version: %s", online_version) if online_version > max_version: max_version = online_version return max_version
def test_get_by_string(self): v = Version(1, 2, 3, 4, 5) self.assertEqual(v['major'], v.major) self.assertEqual(v['minor'], v.minor) self.assertEqual(v['tiny'], v.tiny) self.assertEqual(v['micro'], v.micro) self.assertEqual(v['nano'], v.nano)
def test_list_constructor(self): v = Version([1, 2, 3, 4, 5]) self.assertEqual(v.major, 1) self.assertEqual(v.minor, 2) self.assertEqual(v.tiny, 3) self.assertEqual(v.micro, 4) self.assertEqual(v.nano, 5)
def test_get_by_int(self): v = Version('1.2.3.4.5') self.assertEqual(v[0], v.major) self.assertEqual(v[1], v.minor) self.assertEqual(v[2], v.tiny) self.assertEqual(v[3], v.micro) self.assertEqual(v[4], v.nano)
def __init__(self, name, cls, location=None, fileFormat="ascii", defaultValues=None, values=None): """Init foam file.""" self.__dict__['is{}'.format(self.__class__.__name__)] = True self.__version = str(Version().OFVer) self.format = str(fileFormat) # ascii / binary self.cls = str(cls) # dictionary or field self.name = str(name) self.location = location # location is optional if self.location: if self.location.replace('"', '') in self.__locations: self.location = '"' + self.location.replace('"', '') + '"' else: raise ValueError( '{} is not a valid OpenFOAM location: {}'.format( self.location, self.__locations ) ) # Initiate values if not values: values = {} if not defaultValues: defaultValues = {} self.__values = deepcopy(defaultValues) self.updateValues(values, mute=True)
def __get_online_version_from_github(self, include_alpha_beta=False): """ Retrieves the current online version. :param bool include_alpha_beta: should we include alpha/beta releases? :return: Returns the current online version or `None` of no version was found. :rtype: None|Version """ data = self.__uriHandler.open(self.updateUrl, no_cache=True) json_data = JsonHelper(data) version_tag = "tag_name" online_versions = [ r[version_tag].lstrip("v").replace("-", "~") for r in json_data.get_value() if bool(r[version_tag]) and ( not r["prerelease"] or include_alpha_beta) ] if not bool(online_versions): return None max_version = None for online_version_data in online_versions: online_version = Version(online_version_data) if not include_alpha_beta and online_version.buildType is not None: self.__logger.trace("Ignoring %s", online_version) continue self.__logger.trace("Found possible version: %s", online_version) if online_version > max_version: max_version = online_version return max_version
def __is_index_consistent(self, index): """ A quick check if a given Channel Index is correct. :param dict index: A index with Channel information. :return: An indication (True/False) if the index is consistent. :rtype: bool """ if self.__CHANNEL_INDEX_CHANNEL_KEY not in index: Logger.warning("Channel Index Inconsistent: missing '%s' key.", self.__CHANNEL_INDEX_CHANNEL_INFO_KEY) return False if self.__CHANNEL_INDEX_ADD_ONS_KEY not in index: Logger.warning("Channel Index Inconsistent: missing '%s' key.", self.__CHANNEL_INDEX_ADD_ONS_KEY) return False # verify if the channels add-ons match, otherwise it is invalid anyways indexed_channel_add_ons = index[self.__CHANNEL_INDEX_ADD_ONS_KEY] channel_pack_paths = self.__get_channel_pack_folders()[1] # see if the numbers match if len(indexed_channel_add_ons) != len(channel_pack_paths): Logger.warning( "Channel Index Inconsistent: add-on count is not up to date (index=%s vs actual=%s).", len(indexed_channel_add_ons), len(channel_pack_paths)) return False # cross reference by putting them on a big pile and then get the distinct values (set) and # compare the length of the distinct values. if len(set(indexed_channel_add_ons + channel_pack_paths)) != len(channel_pack_paths): Logger.warning( "Channel Index Inconsistent: add-on content is not up to date." ) return False # Validate the version of the add-on and the channel-sets channels = index[self.__CHANNEL_INDEX_CHANNEL_KEY] first_version = channels[list( channels.keys())[0]][self.__CHANNEL_INDEX_CHANNEL_VERSION_KEY] first_version = Version(first_version) if not Config.version.are_compatible(first_version): Logger.warning("Inconsisten version 'index' vs 'add-on': %s vs %s", first_version, Config.version) return False first_path = channels[list( channels.keys())[0]][self.__CHANNEL_INDEX_CHANNEL_INFO_KEY] if not first_path.startswith(Config.rootDir.rstrip(os.sep)): Logger.warning( "Inconsisten path for ChannelSet and main add-on:\n" "Channel: '%s'\n" "Add-on: '%s'", first_path, Config.rootDir) return False return True
def __init__(self, versions): self.versions = [] for version in versions: try: self.versions.append(Version(self.normalized(version))) except: # Unfortunately we must ignore this version. :( pass