fixing the classes

This commit is contained in:
Brendan McDevitt 2022-08-20 01:51:50 -05:00
parent 678b3032e1
commit e358eef7ca

View file

@ -47,30 +47,19 @@ class UbuntuDistroLaunchpad:
elif self.version and self.distro_series is None: elif self.version and self.distro_series is None:
return self.set_version() return self.set_version()
class DistroArchive class UbuntuPackageArchive:
"""
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 NOTE: Separating the package archive and lookup process from setting the distro
i think is better for organization i think is better for organization
""" """
def __init__(self, archive):
def __init__(self, ):
# test if this works or not
self.distro_launchpad = UbuntuDistroLaunchpad() self.distro_launchpad = UbuntuDistroLaunchpad()
# set archive_name to main for now self.archive = archive
self.archive = DistroArchive(archive_name='main') self.current_archive = self.set_archive()
self.source_package_name = source_package_name # self.ubuntu isnt getting set properly so the setting archive methods
# arent working
self.ubuntu = self.distro_launchpad.ubuntu
def set_main_archive(self): def set_main_archive(self):
""" """
@ -78,8 +67,41 @@ class UbuntuPackageArchive
Can we make a function that uses the launchpadlib to set the archive to Can we make a function that uses the launchpadlib to set the archive to
main, multiverse, restricted, universe main, multiverse, restricted, universe
""" """
print('Setting archive to main archive') print('Setting package archive to main archive')
return self.ubuntu.main_archive return self.ubuntu.main_archive
def set_multiverse_archive(self):
print('Setting package archive to multiverse archive')
return self.ubuntu.multiverse_archive
def set_restricted_archive(self):
print('Setting package archive to restricted archive')
return self.ubuntu.restricted_archive
def set_universe_archive(self):
print('Setting package archive to universe archive')
return self.ubuntu.universe_archive
def set_archive(self):
if self.archive == 'main':
return self.set_main_archive()
elif self.archive == 'multiverse':
return self.set_multiverse_archive()
elif self.archive == 'restricted':
return self.set_restricted_archive()
elif self.archive == 'universe':
return self.set_universe_archive()
class UbuntuPackageHistory:
def __init__(self, archive=None, source_package_name=None,
distro_version=None, distro_series=None):
self.archive = archive
self.current_archive = UbuntuPackageArchive(archive)
self.source_package_name = source_package_name
self.distro_version = distro_version
self.distro_series = distro_series
self.distro = UbuntuDistroLaunchpad(distro_series=distro_series).distro
def get_published_sources(self): def get_published_sources(self):
""" """
@ -87,25 +109,32 @@ class UbuntuPackageArchive
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 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: 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') print('Please instantiate a source_package_name if you wish to use this method')
else: else:
# this code here can/should be archive aware so we can get from the # this code here can/should be archive aware so we can get from the
# others. see the comment in the set_main_archive() function. # others. see the comment in the set_main_archive() function.
archive = self.set_main_archive() #archive = self.set_main_archive()
#series = self.set_distro_series() #series = self.set_distro_series()
series = self.distro series = self.distro
return archive.getPublishedSources(source_name=self.source_package_name, distro_series=series) return self.archive.getPublishedSources(source_name=self.source_package_name, distro_series=series)
def package_name_and_version_history(self): def source_package_version_history(self):
sources = self.get_published_sources() sources = self.get_published_sources()
results = [] results = []
for source in sources: for source in sources:
name = source.source_package_name source_package_name = source.source_package_name
version = source.source_package_version source_package_version = source.source_package_version
results.append((name, version)) results.append((source_package_name, source_package_version))
d = defaultdict(list) d = defaultdict(list)
for k, v in results: for k, v in results:
d[k].append(v) d[k].append(v)
return sorted(d.items()) return sorted(d.items())
if __name__ == '__main__':
# example with python3.8, main archive, 20.04 for the distro
package_checker = UbuntuPackageHistory(archive='main',
source_package_name='python3.8', distro_series='20.04')
print(package_checker.source_package_version_history())