diff --git a/tools/ubuntu_package_puller/ubuntu_launchpad_distro_archive_lookup.py b/tools/ubuntu_package_puller/ubuntu_launchpad_distro_archive_lookup.py new file mode 100644 index 0000000..4a90d9b --- /dev/null +++ b/tools/ubuntu_package_puller/ubuntu_launchpad_distro_archive_lookup.py @@ -0,0 +1,111 @@ +from launchpadlib.launchpad import Launchpad +from collections import defaultdict +import httplib2 + +class UbuntuDistroLaunchpad: + """ + Use launchpadlib api to query for the package history tree + of a target source_package_name + distro_series + """ + def __init__(self, source_package_name=None, distro_series=None, + version=None, debug=False): + + self.source_package_name = source_package_name + self.distro_series = distro_series + self.version = version + self.debug = debug + + self.launchpad = self.login() + self.ubuntu = self.set_ubuntu() + self.distro = self.set_distro() + + self.set_debug() + + def login(self): + return Launchpad.login_anonymously('package_version_history_lookup', 'production') + + def set_debug(self): + if self.debug is False: + httplib2.debuglevel = 0 + else: + if self.debug is True: + print('HTTP Debugging Enabled') + httplib.debuglevel = 1 + + def set_ubuntu(self): + return self.launchpad.distributions['ubuntu'] + + def set_distro_series(self): + return self.ubuntu.getSeries(name_or_version=self.distro_series) + + def set_version(self): + return self.ubuntu.getSeries(name_or_version=self.version) + + def set_distro(self): + if self.distro_series and self.version is None: + return self.set_distro_series() + elif self.version and self.distro_series is None: + return self.set_version() + +class DistroArchive + """ + TODO: + Make this on handle setting the archive + """ + + def __init__(self, archive_name='main'): + self.archive_name = archive_name + + +class UbuntuPackageArchive + """ + NOTE: Separating the package archive and lookup process from setting the distro + i think is better for organization + """ + + + def __init__(self, ): + # test if this works or not + self.distro_launchpad = UbuntuDistroLaunchpad() + # set archive_name to main for now + self.archive = DistroArchive(archive_name='main') + self.source_package_name = source_package_name + + + def set_main_archive(self): + """ + TODO: + Can we make a function that uses the launchpadlib to set the archive to + main, multiverse, restricted, universe + """ + print('Setting archive to main archive') + return self.ubuntu.main_archive + + def get_published_sources(self): + """ + this function needs self.source_package_name to be set + TODO: investigate to see if this api call works with a version or if there is a version instead of distro_series param with getPublishedSources so we can use the self.distro instead of what we are setting for series = now + """ + if self.source_package_name is None: + print('Please instantiate a source_package_name with the UbuntuDistroLaunchpad() class if you wish to use this method') + else: + # this code here can/should be archive aware so we can get from the + # others. see the comment in the set_main_archive() function. + archive = self.set_main_archive() + #series = self.set_distro_series() + series = self.distro + return archive.getPublishedSources(source_name=self.source_package_name, distro_series=series) + + def package_name_and_version_history(self): + sources = self.get_published_sources() + results = [] + for source in sources: + name = source.source_package_name + version = source.source_package_version + results.append((name, version)) + + d = defaultdict(list) + for k, v in results: + d[k].append(v) + + return sorted(d.items())