Repo: Rework factory() interface
Rather than handing down a complete config, only pass what is really needed: a repository fallback path. This can already be determined by the caller. Inside Repo.factory(), we can retrieve the global context now and can stop relying on a reference stored in the config. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
		
				
					committed by
					
						
						Daniel Wagner
					
				
			
			
				
	
			
			
			
						parent
						
							0c66b24a12
						
					
				
				
					commit
					4acde53b94
				
			@@ -82,9 +82,12 @@ class Config:
 | 
			
		||||
        """
 | 
			
		||||
        repo_config_dict = self._config.get('repos', {})
 | 
			
		||||
        repo_dict = {}
 | 
			
		||||
        repo_fallback_path = os.path.dirname(self.filename)
 | 
			
		||||
        for repo in repo_config_dict:
 | 
			
		||||
            repo_config_dict[repo] = repo_config_dict[repo] or {}
 | 
			
		||||
            repo_dict[repo] = Repo.factory(repo, repo_config_dict[repo], self)
 | 
			
		||||
            repo_dict[repo] = Repo.factory(repo,
 | 
			
		||||
                                           repo_config_dict[repo],
 | 
			
		||||
                                           repo_fallback_path)
 | 
			
		||||
 | 
			
		||||
        return repo_dict
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								kas/repos.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								kas/repos.py
									
									
									
									
									
								
							@@ -27,6 +27,7 @@ import os
 | 
			
		||||
import asyncio
 | 
			
		||||
import logging
 | 
			
		||||
from urllib.parse import urlparse
 | 
			
		||||
from .context import get_context
 | 
			
		||||
from .libkas import run_cmd_async, run_cmd
 | 
			
		||||
 | 
			
		||||
__license__ = 'MIT'
 | 
			
		||||
@@ -71,11 +72,10 @@ class Repo:
 | 
			
		||||
                                self.path, self._layers)
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def factory(name, repo_config, config):
 | 
			
		||||
    def factory(name, repo_config, repo_fallback_path):
 | 
			
		||||
        """
 | 
			
		||||
            Return an instance Repo depending on params.
 | 
			
		||||
        """
 | 
			
		||||
        ctx = config.context
 | 
			
		||||
        layers_dict = repo_config.get('layers', {})
 | 
			
		||||
        layers = list(filter(lambda x, laydict=layers_dict:
 | 
			
		||||
                             str(laydict[x]).lower() not in
 | 
			
		||||
@@ -100,7 +100,7 @@ class Repo:
 | 
			
		||||
        if url is None:
 | 
			
		||||
            # No version control operation on repository
 | 
			
		||||
            if path is None:
 | 
			
		||||
                path = Repo.get_root_path(os.path.dirname(config.filename))
 | 
			
		||||
                path = Repo.get_root_path(repo_fallback_path)
 | 
			
		||||
                logging.info('Using %s as root for repository %s', path,
 | 
			
		||||
                             name)
 | 
			
		||||
 | 
			
		||||
@@ -108,11 +108,11 @@ class Repo:
 | 
			
		||||
            disable_operations = True
 | 
			
		||||
        else:
 | 
			
		||||
            if path is None:
 | 
			
		||||
                path = os.path.join(ctx.kas_work_dir, name)
 | 
			
		||||
                path = os.path.join(get_context().kas_work_dir, name)
 | 
			
		||||
            else:
 | 
			
		||||
                if not os.path.isabs(path):
 | 
			
		||||
                    # Relative pathes are assumed to start from work_dir
 | 
			
		||||
                    path = os.path.join(ctx.kas_work_dir, path)
 | 
			
		||||
                    path = os.path.join(get_context().kas_work_dir, path)
 | 
			
		||||
 | 
			
		||||
        if typ == 'git':
 | 
			
		||||
            return GitRepo(url, path, refspec, layers, patches,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user