]> Frank Brehm's Git Trees - pixelpark/puppet-tools.git/commitdiff
Adding property 'ref_type' to class PuppetfileModuleInfo.
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 13 Feb 2023 14:35:07 +0000 (15:35 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 13 Feb 2023 14:35:07 +0000 (15:35 +0100)
lib/dpx_puppettools/pfile_moduleinfo.py

index f7f5352b114ec07501022cda6e12e5ecec3618e4..fb5cd931646e4fe269fdcd5a0d1eb5f491c74f60 100644 (file)
@@ -25,8 +25,7 @@ from .xlate import XLATOR
 from .errors import BaseModuleInfoError
 from .base_moduleinfo import BaseModuleInfo
 
-
-__version__ = '0.3.0'
+__version__ = '0.3.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -52,6 +51,7 @@ class PuppetfileModuleInfo(BaseModuleInfo):
 
     default_repo_type = 'forge'
     valid_repo_types = ('forge', 'git', 'svn', 'tarball', 'local')
+    valid_ref_types = ('ref', 'head', 'tag', 'branch', 'commit-id')
 
     re_empty_mod_pf_line = re.compile(r'\s*mod\s+\'([^\']+)\'\s*$', re.IGNORECASE)
     re_mod_pf_line = re.compile(r'\s*mod\s+\'([^\']+)\'\s*,\s*(\S+.*)\s*$', re.IGNORECASE)
@@ -72,11 +72,12 @@ class PuppetfileModuleInfo(BaseModuleInfo):
             initialized=None, name=None, vendor=None, full_name=None,
             repo_type=None, repo=None, ref=None, use_control_branch=False,
             forge_version=None, default_branch=None, exclude_spec=False,
-            install_path=None):
+            ref_type=None, install_path=None):
 
         self._repo_type = self.default_repo_type
         self._repo = None
         self._ref = None
+        self._ref_type = None
         self._use_control_branch = False
         self._forge_version = None
         self._default_branch = None
@@ -92,6 +93,7 @@ class PuppetfileModuleInfo(BaseModuleInfo):
             self.repo_type = repo_type
         self.repo = repo
         self.ref = ref
+        self.ref_type = ref_type
         self.use_control_branch = use_control_branch
         self.forge_version = forge_version
         self.default_branch = default_branch
@@ -144,6 +146,23 @@ class PuppetfileModuleInfo(BaseModuleInfo):
             return
         self._ref = to_str(value).strip()
 
+    # -------------------------------------------------------------------------
+    @property
+    def ref_type(self):
+        """The type of the Git reference."""
+        return self._ref_type
+
+    @ref_type.setter
+    def ref_type(self, value):
+        if value is None:
+            self._ref_type = None
+            return
+        v = to_str(value).strip().lower()
+        if v not in self.valid_ref_types:
+            msg = _("Invalid Git reference type {!r}.").format(value)
+            raise ModuleInfoTypeError(msg)
+        self._ref_type = v
+
     # -------------------------------------------------------------------------
     @property
     def forge_version(self):
@@ -224,6 +243,7 @@ class PuppetfileModuleInfo(BaseModuleInfo):
         res['forge_version'] = self.forge_version
         res['install_path'] = self.install_path
         res['ref'] = self.ref
+        res['ref_type'] = self.ref_type
         res['repo'] = self.repo
         res['repo_type'] = self.repo_type
         res['use_control_branch'] = self.use_control_branch
@@ -241,6 +261,7 @@ class PuppetfileModuleInfo(BaseModuleInfo):
         res['forge_version'] = self.forge_version
         res['install_path'] = self.install_path
         res['ref'] = self.ref
+        res['ref_type'] = self.ref_type
         res['repo'] = self.repo
         res['repo_type'] = self.repo_type
         res['use_control_branch'] = self.use_control_branch
@@ -268,6 +289,8 @@ class PuppetfileModuleInfo(BaseModuleInfo):
             fields.append("repo={!r}".format(self.repo))
         if self.ref:
             fields.append("ref={!r}".format(self.ref))
+        if self.ref_type:
+            fields.append("ref_type={!r}".format(self.ref_type))
         if self.use_control_branch:
             fields.append("use_control_branch={!r}".format(True))
         if self.forge_version:
@@ -298,6 +321,8 @@ class PuppetfileModuleInfo(BaseModuleInfo):
             module_info.repo = self.repo
         if self.ref:
             module_info.ref = self.ref
+        if self.ref_type:
+            module_info.ref_type = self.ref_type
         if self.use_control_branch:
             module_info.use_control_branch = True
         if self.forge_version:
@@ -344,6 +369,9 @@ class PuppetfileModuleInfo(BaseModuleInfo):
         if 'ref' in data:
             module_info.ref = data['ref']
 
+        if 'ref_type' in data:
+            module_info.ref_type = data['ref_type']
+
         if 'use_control_branch' in data:
             module_info.use_control_branch = data['use_control_branch']
 
@@ -509,9 +537,11 @@ class PuppetfileModuleInfo(BaseModuleInfo):
 
             if 'tag' in definitions:
                 module_info.ref = definitions['tag']
+                module_info.ref_type = 'tag'
 
             if 'ref' in definitions:
                 module_info.ref = definitions['ref']
+                module_info.ref_type = 'ref'
 
             if 'branch' in definitions:
                 branch = definitions['branch']
@@ -519,9 +549,11 @@ class PuppetfileModuleInfo(BaseModuleInfo):
                     module_info.use_control_branch = True
                 else:
                     module_info.ref = branch
+                module_info.ref_type = 'branch'
 
             if 'commit' in definitions:
                 module_info.ref = definitions['commit']
+                module_info.ref_type = 'commit-id'
 
             if 'latest' in definitions:
                 module_info.forge_version = 'latest'