From d2a52e47c867f8f5864781f200bed4d0adf373b3 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 23 Jan 2015 17:44:20 +0100 Subject: Plugins/Packages: all attributes should be defined in __init__ --- src/lib/Bcfg2/Server/Plugins/Packages/Source.py | 117 ++++++++++++++---------- src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 17 +++- 2 files changed, 81 insertions(+), 53 deletions(-) (limited to 'src/lib/Bcfg2') diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py index c09a9988b..cf26c982f 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py @@ -143,6 +143,75 @@ class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902 #: source self.essentialpkgs = set() + #: A list of the text of all 'Component' attributes of this + #: source from XML + self.components = [] + + #: A list of the arches supported by this source + self.arches = [] + + #: A list of the the names of packages that are blacklisted + #: from this source + self.blacklist = [] + + #: A list of the the names of packages that are whitelisted in + #: this source + self.whitelist = [] + + #: Whether or not to include deb-src lines in the generated APT + #: configuration + self.debsrc = False + + #: A dict of repository options that will be included in the + #: configuration generated on the server side (if such is + #: applicable; most backends do not generate any sort of + #: repository configuration on the Bcfg2 server) + self.server_options = dict() + + #: A dict of repository options that will be included in the + #: configuration generated for the client (if that is + #: supported by the backend) + self.client_options = dict() + + #: A list of URLs to GPG keys that apply to this source + self.gpgkeys = [] + + #: Whether or not to include essential packages from this source + self.essential = True + + #: Whether or not to include recommended packages from this source + self.recommended = False + + #: The "rawurl" attribute from :attr:`xsource`, if applicable. + #: A trailing slash is automatically appended to this if there + #: wasn't one already present. + self.rawurl = None + + #: The "url" attribute from :attr:`xsource`, if applicable. A + #: trailing slash is automatically appended to this if there + #: wasn't one already present. + self.url = None + + #: The "version" attribute from :attr:`xsource` + self.version = None + + #: The "name" attribute from :attr:`xsource` + self.name = None + + #: A list of predicates that are used to determine if this + #: source applies to a given + #: :class:`Bcfg2.Server.Plugins.Metadata.ClientMetadata` + #: object. + self.conditions = [] + + #: Formerly, :ref:`server-plugins-generators-packages` only + #: supported applying package sources to groups; that is, they + #: could not be assigned by more complicated logic like + #: per-client repositories and group or client negation. This + #: attribute attempts to provide for some limited backwards + #: compat with older code that relies on this. + self.groups = [] + self._init_attributes(basepath, xsource, setup) #: A set of all package names in this source. This will not @@ -220,35 +289,12 @@ class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902 :type setup: dict """ - #: A list of the text of all 'Component' attributes of this - #: source from XML self.components = [item.text for item in xsource.findall('Component')] - - #: A list of the arches supported by this source self.arches = [item.text for item in xsource.findall('Arch')] - - #: A list of the the names of packages that are blacklisted - #: from this source self.blacklist = [item.text for item in xsource.findall('Blacklist')] - - #: A list of the the names of packages that are whitelisted in - #: this source self.whitelist = [item.text for item in xsource.findall('Whitelist')] - - #: Whether or not to include deb-src lines in the generated APT - #: configuration self.debsrc = xsource.get('debsrc', 'false') == 'true' - #: A dict of repository options that will be included in the - #: configuration generated on the server side (if such is - #: applicable; most backends do not generate any sort of - #: repository configuration on the Bcfg2 server) - self.server_options = dict() - - #: A dict of repository options that will be included in the - #: configuration generated for the client (if that is - #: supported by the backend) - self.client_options = dict() opts = xsource.findall("Options") for el in opts: repoopts = dict([(k, v) @@ -259,48 +305,23 @@ class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902 if el.get("serveronly", "false").lower() == "false": self.client_options.update(repoopts) - #: A list of URLs to GPG keys that apply to this source self.gpgkeys = [el.text for el in xsource.findall("GPGKey")] - #: Whether or not to include essential packages from this source self.essential = xsource.get('essential', 'true').lower() == 'true' - - #: Whether or not to include recommended packages from this source self.recommended = xsource.get('recommended', 'false').lower() == 'true' - #: The "rawurl" attribute from :attr:`xsource`, if applicable. - #: A trailing slash is automatically appended to this if there - #: wasn't one already present. self.rawurl = xsource.get('rawurl', '') if self.rawurl and not self.rawurl.endswith("/"): self.rawurl += "/" - #: The "url" attribute from :attr:`xsource`, if applicable. A - #: trailing slash is automatically appended to this if there - #: wasn't one already present. self.url = xsource.get('url', '') if self.url and not self.url.endswith("/"): self.url += "/" - #: The "version" attribute from :attr:`xsource` self.version = xsource.get('version', '') - - #: The "name" attribute from :attr:`xsource` self.name = xsource.get('name', None) - #: A list of predicates that are used to determine if this - #: source applies to a given - #: :class:`Bcfg2.Server.Plugins.Metadata.ClientMetadata` - #: object. - self.conditions = [] - #: Formerly, :ref:`server-plugins-generators-packages` only - #: supported applying package sources to groups; that is, they - #: could not be assigned by more complicated logic like - #: per-client repositories and group or client negation. This - #: attribute attempts to provide for some limited backwards - #: compat with older code that relies on this. - self.groups = [] for el in xsource.iterancestors(): if el.tag == "Group": if el.get("negate", "false").lower() == "true": diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index ae8ac5d6f..6669d3066 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -1028,10 +1028,21 @@ class YumSource(Source): #: YumSource sets the ``type`` on Package entries to "yum" ptype = 'yum' + def __init__(self, basepath, xsource, setup): + self.filemap = dict() + self.file_to_arch = dict() + self.needed_paths = set() + self.packages = dict() + self.yumgroups = dict() + self.pulp_id = None + self.repo = None + + Source.__init__(self, basepath, xsource, setup) + __init__.__doc__ = Source.__init__.__doc__ + def _init_attributes(self, basepath, xsource, setup): Source._init_attributes(self, basepath, xsource, setup) - self.pulp_id = None if HAS_PULP and xsource.get("pulp_id"): self.pulp_id = xsource.get("pulp_id") @@ -1064,14 +1075,10 @@ class YumSource(Source): self.repo['relative_path']) self.arches = [self.repo['arch']] - self.packages = dict() self.deps = dict([('global', dict())]) self.provides = dict([('global', dict())]) self.filemap = dict([(x, dict()) for x in ['global'] + self.arches]) - self.needed_paths = set() - self.file_to_arch = dict() - self.yumgroups = dict() _init_attributes.__doc__ = Source._init_attributes.__doc__ @property -- cgit v1.2.3-1-g7c22