# Copyright John N. Laliberte # LICENSE - GPL2 # vim: set sts=4 sw=4 et tw=0 : # gnome module import urllib2, package_module, simple_cache_module import clioptions_module # import ftp_module DEBUG = False class GNOME: def _isgnome3(self, gnome_release_list): if int(gnome_release_list[0]) == 2 and int(gnome_release_list[1]) > 90: return True return False def __init__(self, nextrev=False): options = clioptions_module.Options() args = options.get_arguments() self.nextrev = nextrev; self.major_release = ".".join( args.release_number.split(".")[:2] ) self.full_release = args.release_number # gnome_release is the major release number the development is leading up to or is part of. E.g, 2.21.5 will turn to 2.22 and 2.22.2 becomes 2.22 # This is used in latest versions list fetching URL construction gnome_release_list = args.release_number.split(".") if self._isgnome3(gnome_release_list): gnome_release_list = ['3', '0'] elif int(gnome_release_list[1]) % 2 != 0: gnome_release_list[1] = str(int(gnome_release_list[1]) + 1) self.gnome_release = ".".join(gnome_release_list[:2]) self.ftpserver = "ftp.gnome.org" self.release_directories = ["pub/GNOME/admin/" + self.major_release + "/" + self.full_release + "/", "pub/GNOME/platform/" + self.major_release + "/" + self.full_release + "/", "pub/GNOME/desktop/" + self.major_release + "/" + self.full_release + "/", "pub/GNOME/bindings/" + self.major_release + "/" + self.full_release + "/"] self.latest_versions_file_path = 'http://www.gnome.org/~vuntz/tmp/versions/' self.latest_versions_url = self.latest_versions_file_path + 'versions-' + self.gnome_release self.release_versions_file_path = 'http://ftp.gnome.org/pub/GNOME/teams/releng/' def generate_data_from_versions_markup(self, url): try: f = urllib2.urlopen(url) except: raise ValueError("Couldn't open %s" % url) ret = [] for line in f.readlines(): components = str.strip(line).split(':') # Skip invalid lines if len(components) != 4 or len(components[2]) == 0: continue # Skip mobile stuff, because we don't care. And they are mostly dupes anyway if components[0] == 'mobile': continue pkg = package_module.Package(components[1] + "-" + components[2]) if (pkg.name and pkg.version): ret.append(pkg) else: print "Warning: Ignoring package %s because parsing of its name or version string '%s' failed" % (components[1], components[2]) f.close() return ret def generate_data_individual(self): return self.generate_data_from_versions_markup(self.latest_versions_url) def generate_data_release(self): return self.generate_data_from_versions_markup(self.release_versions_file_path + self.full_release + '/versions') """ We might want to modify this later to an extra fallback and/or for non-official modules whose tarballs are hosted on GNOME or compatible FTP def generate_data_ftp(self): # Deprecated: connect to ftp and get the list of all the packages in the release directories walker = ftp_module.FTPWalker(self.ftpserver,"anonymous","test@test.com") files = [] for directory in self.release_directories: f_files = ftp_module.find_files(walker, directory,"","") files.extend(f_files) # filter out bad files files = self.filter_files(files) # create package objects for the files release_packages = [] # the packages that are required for a release for package_name in files: release_package = package_module.Package(package_name) release_packages.append(release_package) # while connected, find out the latest version of the packages that we found in the # release directories latest_packages = [] # the latest versions of packages on the gnome ftp. for package in release_packages: file_list = ftp_module.find_files(walker, "pub/GNOME/sources" + "/" + package.raw_name + "/" + package.major_minor,"","") # if maintainers release tarballs late, they will not get picked up # therefore, if the tarball is 1 less than the y of the x.y you # specify, lets also check to see if there are any files for # the actual release number. major = package.major_minor.split(".")[0] minor = package.major_minor.split(".")[1] options = clioptions_module.Options() args = options.get_arguments() release_minor = args.release_number.split(".")[1] if int(minor) == (int(release_minor) -1): file_list_future = ftp_module.find_files(walker, "pub/GNOME/sources" + "/" + package.raw_name + "/" + major + "." + str(int(minor)+1),"","") # if there are results, replace the old list. if len(file_list_future) > 0: file_list = file_list_future elif self.nextrev == True: # Try to find minor+1 file_list_future = ftp_module.find_files(walker, "pub/GNOME/sources" + "/" + package.raw_name + "/" + major + "." + str(int(minor)+1),"","") # if there are results, replace the old list. if len(file_list_future) > 0: file_list = file_list_future # make sure we don't try to do this on directories with no files, # or on directories that don't exist # create package objects for the files if len(file_list) > 0: latest = self.filter_latest_only(file_list) latest_package = package_module.Package(package.name + "-" + latest) latest_packages.append(latest_package) # disconnect from the ftp # cache the results cache = simple_cache_module.SimpleCache() for release_package in release_packages: latest_package = portage_module.findpackage(release_package.name, latest_packages) if latest_package != None: cache.write_to_queue(release_package.name_plus_version_plus_revision, latest_package.name_plus_version_plus_revision) else: print "No matching latest package!" + str(release_package.name) cache.flush_queue() return (release_packages, latest_packages) """ def filter_files(self, files): # we want to filter out all the bad files. newfiles = [] for file in files: # only keep files with .tar.bz2 ending. if 0 < file.find(".tar.") and 0 < file.find(".bz2"): file = file.replace(".tar.bz2", "") newfiles.append(file) return newfiles # this needs to be fixed so that if a directory doesn't have LATEST-IS-, it returns an error def filter_latest_only(self, lines): latest_string = "LATEST-IS-" latest = "" for item in lines: if 0 <= item.string.rfind(latest_string): latest = item try: return_latest = latest[10:] except: return_latest = "" return return_latest import portage_module def compare_packages(release_packages, latest_packages, packages_in_portage): # we care about 5 cases # 1. portage version is less than the release version. (RED) # 2. portage version is equal to the release version, but less than the latest version. (LIGHT GREEN) # 3. portage version is equal to the release version and the latest version. (GREEN) # 4. portage version is greater than the release version (GREEN) # 5. package does not exist in portage (GREY) # again, we choose release_packages as the enumerator for the package names # since it will have ALL packages ( for example, if we used portage_packages, we # might miss the packages that do not exist in portage ) status_packages = [] for package in release_packages: color = None release_package = package latest_package = portage_module.findpackage(package.name, latest_packages) if latest_package == None: print "Warning: latest packages set does not have an entry for %s, using release set version %s." % (package.name, package.version) latest_package = package portage_package = portage_module.findpackage(package.name, packages_in_portage) if portage_package == None: status = package_module.Status.NotFound # we need to create a phony package since findpackage # returns None portage_package = package_module.Package(package.name) elif portage_module.best_version_test(portage_package.name_plus_version, \ release_package.name_plus_version) == 2: status = package_module.Status.NeedUpdate elif portage_module.best_version_test(portage_package.name_plus_version, \ latest_package.name_plus_version) == 2: status = package_module.Status.NewerVersion else: status = package_module.Status.Compliant #if portage_package != None: # FIXME: Reports release version as latest version to not have to deal with this right now if latest_package == None: print "No latest version known for %s, FIXME!" % release_package.name latest_package = release_package if DEBUG: print "package: " + str(release_package.name) + \ " | pp: " + str(portage_package.version) + \ " | rp: " + str(release_package.version) + \ " | lp: " + str(latest_package.version) + \ " | status: " + str(status) status_packages.append(package_module.PackageStatus(release_package.name, str(portage_package.version), str(release_package.version), str(latest_package.version), status)) return status_packages