mirror of
				https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
				synced 2025-10-31 08:34:04 +00:00 
			
		
		
		
	Add Suites to keep track of all suites
At the moment, it is just a glorified dict. However, we will eventually use it to get rid of the hardcoded references to "testing" etc. all over the code. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
		
							parent
							
								
									37f02d611c
								
							
						
					
					
						commit
						e63aa05708
					
				
							
								
								
									
										14
									
								
								britney.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								britney.py
									
									
									
									
									
								
							| @ -192,7 +192,7 @@ from urllib.parse import quote | |||||||
| import apt_pkg | import apt_pkg | ||||||
| 
 | 
 | ||||||
| # Check the "check_field_name" reflection before removing an import here. | # Check the "check_field_name" reflection before removing an import here. | ||||||
| from britney2 import SuiteInfo, SourcePackage, BinaryPackageId, BinaryPackage | from britney2 import Suites, SuiteInfo, SourcePackage, BinaryPackageId, BinaryPackage | ||||||
| from britney2.consts import (SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS, PROVIDES, MULTIARCH) | from britney2.consts import (SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS, PROVIDES, MULTIARCH) | ||||||
| from britney2.excuse import Excuse | from britney2.excuse import Excuse | ||||||
| from britney2.hints import HintParser | from britney2.hints import HintParser | ||||||
| @ -292,7 +292,7 @@ class Britney(object): | |||||||
|         # parse the command line arguments |         # parse the command line arguments | ||||||
|         self.policies = [] |         self.policies = [] | ||||||
|         self._hint_parser = HintParser() |         self._hint_parser = HintParser() | ||||||
|         self.suite_info = {} |         self.suite_info = None  # Initialized during __parse_arguments | ||||||
|         self.__parse_arguments() |         self.__parse_arguments() | ||||||
|         MigrationItem.set_architectures(self.options.architectures) |         MigrationItem.set_architectures(self.options.architectures) | ||||||
| 
 | 
 | ||||||
| @ -501,19 +501,22 @@ class Britney(object): | |||||||
|                          not getattr(self.options, k.lower()): |                          not getattr(self.options, k.lower()): | ||||||
|                         setattr(self.options, k.lower(), v) |                         setattr(self.options, k.lower(), v) | ||||||
| 
 | 
 | ||||||
|  |         suites = [] | ||||||
|         for suite in ('testing', 'unstable', 'pu', 'tpu'): |         for suite in ('testing', 'unstable', 'pu', 'tpu'): | ||||||
|             suffix = suite if suite in {'pu', 'tpu'} else '' |             suffix = suite if suite in {'pu', 'tpu'} else '' | ||||||
|             if hasattr(self.options, suite): |             if hasattr(self.options, suite): | ||||||
|                 suite_path = getattr(self.options, suite) |                 suite_path = getattr(self.options, suite) | ||||||
|                 self.suite_info[suite] = SuiteInfo(name=suite, path=suite_path, excuses_suffix=suffix) |                 suites.append(SuiteInfo(name=suite, path=suite_path, excuses_suffix=suffix)) | ||||||
|             else: |             else: | ||||||
|                 if suite in {'testing', 'unstable'}:  # pragma: no cover |                 if suite in {'testing', 'unstable'}:  # pragma: no cover | ||||||
|                     self.logger.error("Mandatory configuration %s is not set in the config", suite.upper()) |                     self.logger.error("Mandatory configuration %s is not set in the config", suite.upper()) | ||||||
|                     sys.exit(1) |                     sys.exit(1) | ||||||
|                 self.logger.info("Optional suite %s is not defined (config option: %s) ", suite, suite.upper()) |                 self.logger.info("Optional suite %s is not defined (config option: %s) ", suite, suite.upper()) | ||||||
| 
 | 
 | ||||||
|  |         self.suite_info = Suites(suites[0], suites[1:]) | ||||||
|  | 
 | ||||||
|         try: |         try: | ||||||
|             release_file = read_release_file(self.suite_info['testing'].path) |             release_file = read_release_file(self.suite_info.target_suite.path) | ||||||
|             self.logger.info("Found a Release file in testing - using that for defaults") |             self.logger.info("Found a Release file in testing - using that for defaults") | ||||||
|         except FileNotFoundError: |         except FileNotFoundError: | ||||||
|             self.logger.info("Testing does not have a Release file.") |             self.logger.info("Testing does not have a Release file.") | ||||||
| @ -547,7 +550,8 @@ class Britney(object): | |||||||
|         else: |         else: | ||||||
|             if not release_file:  # pragma: no cover |             if not release_file:  # pragma: no cover | ||||||
|                 self.logger.error("No configured architectures and there is no release file for testing") |                 self.logger.error("No configured architectures and there is no release file for testing") | ||||||
|                 self.logger.error("Please check if there is a \"Release\" file in %s", self.suite_info['testing'].path) |                 self.logger.error("Please check if there is a \"Release\" file in %s", | ||||||
|  |                                   self.suite_info.target_suite.path) | ||||||
|                 self.logger.error("or if the config file contains a non-empty \"ARCHITECTURES\" field") |                 self.logger.error("or if the config file contains a non-empty \"ARCHITECTURES\" field") | ||||||
|                 sys.exit(1) |                 sys.exit(1) | ||||||
|             allarches = sorted(release_file['Architectures'].split()) |             allarches = sorted(release_file['Architectures'].split()) | ||||||
|  | |||||||
| @ -7,6 +7,41 @@ SuiteInfo = namedtuple('SuiteInfo', [ | |||||||
| ]) | ]) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class Suites(object): | ||||||
|  | 
 | ||||||
|  |     def __init__(self, target_suite, source_suites): | ||||||
|  |         self._suites = {} | ||||||
|  |         self._by_name_or_alias = {} | ||||||
|  |         self.target_suite = target_suite | ||||||
|  |         self.source_suites = source_suites | ||||||
|  |         self._suites[target_suite.name] = target_suite | ||||||
|  |         self._by_name_or_alias[target_suite.name] = target_suite | ||||||
|  |         if target_suite.excuses_suffix: | ||||||
|  |             self._by_name_or_alias[target_suite.excuses_suffix] = target_suite | ||||||
|  |         for suite in source_suites: | ||||||
|  |             self._suites[suite.name] = suite | ||||||
|  |             self._by_name_or_alias[suite.name] = suite | ||||||
|  |             if suite.excuses_suffix: | ||||||
|  |                 self._by_name_or_alias[suite.excuses_suffix] = suite | ||||||
|  | 
 | ||||||
|  |     @property | ||||||
|  |     def primary_source_suite(self): | ||||||
|  |         return self.source_suites[0] | ||||||
|  | 
 | ||||||
|  |     @property | ||||||
|  |     def by_name_or_alias(self): | ||||||
|  |         return self._by_name_or_alias | ||||||
|  | 
 | ||||||
|  |     def __getitem__(self, item): | ||||||
|  |         return self._suites[item] | ||||||
|  | 
 | ||||||
|  |     def __len__(self): | ||||||
|  |         return len(self.source_suites) + 1 | ||||||
|  | 
 | ||||||
|  |     def __iter__(self): | ||||||
|  |         yield from self._suites | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class SourcePackage(object): | class SourcePackage(object): | ||||||
| 
 | 
 | ||||||
|     __slots__ = ['version', 'section', 'binaries', 'maintainer', 'is_fakesrc', 'build_deps_arch', 'testsuite', 'testsuite_triggers'] |     __slots__ = ['version', 'section', 'binaries', 'maintainer', 'is_fakesrc', 'build_deps_arch', 'testsuite', 'testsuite_triggers'] | ||||||
| @ -24,6 +59,7 @@ class SourcePackage(object): | |||||||
|     def __getitem__(self, item): |     def __getitem__(self, item): | ||||||
|         return getattr(self, self.__slots__[item]) |         return getattr(self, self.__slots__[item]) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| BinaryPackageId = namedtuple('BinaryPackageId', [ | BinaryPackageId = namedtuple('BinaryPackageId', [ | ||||||
|     'package_name', |     'package_name', | ||||||
|     'version', |     'version', | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| import unittest | import unittest | ||||||
| import os | import os | ||||||
| 
 | 
 | ||||||
| from britney2 import SuiteInfo, SourcePackage | from britney2 import Suites, SuiteInfo, SourcePackage | ||||||
| from britney2.excuse import Excuse | from britney2.excuse import Excuse | ||||||
| from britney2.hints import HintParser | from britney2.hints import HintParser | ||||||
| from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict | from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict | ||||||
| @ -18,10 +18,10 @@ def initialize_policy(test_name, policy_class, *args, **kwargs): | |||||||
|         hints = kwargs['hints'] |         hints = kwargs['hints'] | ||||||
|         del kwargs['hints'] |         del kwargs['hints'] | ||||||
|     options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs) |     options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs) | ||||||
|     suite_info = { |     suite_info = Suites( | ||||||
|         'testing': SuiteInfo('testing', os.path.join(test_dir, 'testing'), ''), |         SuiteInfo('testing', os.path.join(test_dir, 'testing'), ''), | ||||||
|         'unstable': SuiteInfo('unstable', os.path.join(test_dir, 'unstable'), ''), |         [SuiteInfo('unstable', os.path.join(test_dir, 'unstable'), '')], | ||||||
|     } |     ) | ||||||
|     policy = policy_class(options, suite_info, *args) |     policy = policy_class(options, suite_info, *args) | ||||||
|     fake_britney = MockObject(log=lambda x, y='I': None) |     fake_britney = MockObject(log=lambda x, y='I': None) | ||||||
|     hint_parser = HintParser() |     hint_parser = HintParser() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user