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 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 _sort_version(version1, version2): nv1 = suggest_normalized_version(version1) nv2 = suggest_normalized_version(version2) if nv1 is not None and nv2 is not None: # we can use d2 to sort if nv1 < nv2: return -1 elif nv1 > nv2: return 1 return 0 else: # we fallback to setuptools sorting return cmp(parse_version(version1), parse_version(version2))
def split_archive_name(archive_name, probable_name=None): """Split an archive name into two parts: name and version. Return the tuple (name, version) """ # Try to determine wich part is the name and wich is the version using the # "-" separator. Take the larger part to be the version number then reduce # if this not works. def eager_split(str, maxsplit=2): # split using the "-" separator splits = str.rsplit("-", maxsplit) name = splits[0] version = "-".join(splits[1:]) if version.startswith("-"): version = version[1:] if suggest_normalized_version(version) is None and maxsplit >= 0: # we dont get a good version number: recurse ! return eager_split(str, maxsplit - 1) else: return name, version if probable_name is not None: probable_name = probable_name.lower() name = None if probable_name is not None and probable_name in archive_name: # we get the name from probable_name, if given. name = probable_name version = archive_name.lstrip(name) else: name, version = eager_split(archive_name) version = suggest_normalized_version(version) if version is not None and name != "": return name.lower(), version else: raise CantParseArchiveName(archive_name)
def distinfo_dirname(name, version): """ The *name* and *version* parameters are converted into their filename-escaped form, i.e. any ``'-'`` characters are replaced with ``'_'`` other than the one in ``'dist-info'`` and the one separating the name from the version number. :parameter name: is converted to a standard distribution name by replacing any runs of non- alphanumeric characters with a single ``'-'``. :type name: string :parameter version: is converted to a standard version string. Spaces become dots, and all other non-alphanumeric characters (except dots) become dashes, with runs of multiple dashes condensed to a single dash. :type version: string :returns: directory name :rtype: string""" file_extension = '.dist-info' name = name.replace('-', '_') normalized_version = suggest_normalized_version(version) # Because this is a lookup procedure, something will be returned even if # it is a version that cannot be normalized if normalized_version is None: # Unable to achieve normality? normalized_version = version return '-'.join([name, normalized_version]) + file_extension
def distinfo_dirname(name, version): """ The *name* and *version* parameters are converted into their filename-escaped form, i.e. any ``'-'`` characters are replaced with ``'_'`` other than the one in ``'dist-info'`` and the one separating the name from the version number. :parameter name: is converted to a standard distribution name by replacing any runs of non- alphanumeric characters with a single ``'-'``. :type name: string :parameter version: is converted to a standard version string. Spaces become dots, and all other non-alphanumeric characters (except dots) become dashes, with runs of multiple dashes condensed to a single dash. :type version: string :returns: directory name :rtype: string""" file_extension = '.dist-info' name = _normalize_dist_name(name) normalized_version = suggest_normalized_version(version) # Because this is a lookup procedure, something will be returned even if # it is a version that cannot be normalized if normalized_version is None: # Unable to achieve normality? normalized_version = version return '-'.join([name, normalized_version]) + file_extension
def _suggest_normalized_version(self, version): n_version = suggest_normalized_version(version) if n_version is None: print("Error : invalid version number : %s" % version) print("See : http://wiki.domogik.org/Release_numbering") self._abort_install_process() else: return n_version
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 eager_split(str, maxsplit=2): # split using the "-" separator splits = str.rsplit("-", maxsplit) name = splits[0] version = "-".join(splits[1:]) if version.startswith("-"): version = version[1:] if suggest_normalized_version(version) is None and maxsplit >= 0: # we dont get a good version number: recurse ! return eager_split(str, maxsplit - 1) else: return name, version
def mkversion(version_obj): try: ver = NormalizedVersion(suggest_normalized_version(version_obj.slug)) return ver except TypeError: return None
def __init__(self, version_str): sugg_ver = suggest_normalized_version(version_str) super(MongoNormalizedVersion, self).__init__(sugg_ver) self.version_str = version_str
def test_pypi(): # FIXME need a better way to do that # To re-run from scratch, just delete these two .pkl files INDEX_PICKLE_FILE = 'pypi-index.pkl' VERSION_PICKLE_FILE = 'pypi-version.pkl' package_info = version_info = [] # if there's a saved version of the package list # restore it # else: # pull the list down from pypi # save a pickled version of it if os.path.exists(INDEX_PICKLE_FILE): print "Loading saved pypi data..." f = open(INDEX_PICKLE_FILE, 'rb') try: package_info = pickle.load(f) finally: f.close() else: print "Retrieving pypi packages..." server = xmlrpclib.Server('http://pypi.python.org/pypi') package_info = server.search({'name': ''}) print "Saving package info..." f = open(INDEX_PICKLE_FILE, 'wb') try: pickle.dump(package_info, f) finally: f.close() # If there's a saved list of the versions from the packages # restore it # else # extract versions from the package list # save a pickled version of it versions = [] if os.path.exists(VERSION_PICKLE_FILE): print "Loading saved version info..." f = open(VERSION_PICKLE_FILE, 'rb') try: versions = pickle.load(f) finally: f.close() else: print "Extracting and saving version info..." versions = [p['version'] for p in package_info] o = open(VERSION_PICKLE_FILE, 'wb') try: pickle.dump(versions, o) finally: o.close() total_versions = len(versions) matches = 0.00 no_sugg = 0.00 have_sugg = 0.00 suggs = [] no_suggs = [] for ver in versions: sugg = suggest_normalized_version(ver) if sugg == ver: matches += 1 elif sugg == None: no_sugg += 1 no_suggs.append(ver) else: have_sugg += 1 suggs.append((ver, sugg)) pct = "(%2.2f%%)" print "Results:" print "--------" print "" print "Suggestions" print "-----------" print "" for ver, sugg in suggs: print "%s -> %s" % (ver, sugg) print "" print "No suggestions" print "--------------" for ver in no_suggs: print ver print "" print "Summary:" print "--------" print "Total Packages : ", total_versions print "Already Match : ", matches, pct % (matches/total_versions*100,) print "Have Suggestion : ", have_sugg, pct % (have_sugg/total_versions*100,) print "No Suggestion : ", no_sugg, pct % (no_sugg/total_versions*100,)
def is_valid_version(version_number): return suggest_normalized_version(version_number) is not None
def __init__(self, version_number, edition=None): sugg_ver = suggest_normalized_version(version_number) super(MongoDBVersionInfo,self).__init__(sugg_ver) self.version_number = version_number self.edition = edition or MongoDBEdition.COMMUNITY
def __init__(self, version_str): sugg_ver = suggest_normalized_version(version_str) super(MongoNormalizedVersion,self).__init__(sugg_ver) self.version_str = version_str