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:
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
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
def __init__(self, archive):
self.distro_launchpad = UbuntuDistroLaunchpad()
# set archive_name to main for now
self.archive = DistroArchive(archive_name='main')
self.source_package_name = source_package_name
self.archive = archive
self.current_archive = self.set_archive()
# self.ubuntu isnt getting set properly so the setting archive methods
# arent working
self.ubuntu = self.distro_launchpad.ubuntu
def set_main_archive(self):
"""
@ -78,34 +67,74 @@ class UbuntuPackageArchive
Can we make a function that uses the launchpadlib to set the archive to
main, multiverse, restricted, universe
"""
print('Setting archive to main archive')
print('Setting package archive to 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):
"""
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')
print('Please instantiate a source_package_name 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()
#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)
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()
results = []
for source in sources:
name = source.source_package_name
version = source.source_package_version
results.append((name, version))
source_package_name = source.source_package_name
source_package_version = source.source_package_version
results.append((source_package_name, source_package_version))
d = defaultdict(list)
for k, v in results:
d[k].append(v)
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())