diff options
-rwxr-xr-x | morphlib/app.py | 47 | ||||
-rw-r--r-- | morphlib/util.py | 56 |
2 files changed, 60 insertions, 43 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 45db9bfa..e2460f68 100755 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -94,55 +94,16 @@ class BuildCommand(object): return morphlib.cachekeycomputer.CacheKeyComputer(build_env) def new_artifact_caches(self): - '''Create new objects for local, remote artifact caches.''' - - self.create_cachedir() - artifact_cachedir = self.create_artifact_cachedir() - - lac = morphlib.localartifactcache.LocalArtifactCache(artifact_cachedir) - - rac_url = self.app.settings['cache-server'] - if rac_url: - rac = morphlib.remoteartifactcache.RemoteArtifactCache(rac_url) - else: - rac = None - return lac, rac + return morphlib.util.new_artifact_caches(self.app.settings) def create_artifact_cachedir(self): - '''Create a new directory for the local artifact cache.''' - - artifact_cachedir = os.path.join( - self.app.settings['cachedir'], 'artifacts') - if not os.path.exists(artifact_cachedir): - os.mkdir(artifact_cachedir) - return artifact_cachedir + return morphlib.util.create_artifact_cachedir(self.app.settings) def new_repo_caches(self): - '''Create new objects for local, remote git repository caches.''' - - aliases = self.app.settings['repo-alias'] - cachedir = self.create_cachedir() - gits_dir = os.path.join(cachedir, 'gits') - bundle_base_url = self.app.settings['bundle-server'] - repo_resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases) - lrc = morphlib.localrepocache.LocalRepoCache( - self.app, gits_dir, repo_resolver, bundle_base_url=bundle_base_url) - - url = self.app.settings['cache-server'] - if url: - rrc = morphlib.remoterepocache.RemoteRepoCache(url, repo_resolver) - else: - rrc = None - - return lrc, rrc + return morphlib.util.new_repo_caches(self.app) def create_cachedir(self): - '''Create a new cache directory.''' - - cachedir = self.app.settings['cachedir'] - if not os.path.exists(cachedir): - os.mkdir(cachedir) - return cachedir + return morphlib.util.create_cachedir(self.app.settings) def compute_build_order(self, repo_name, ref, filename): '''Compute build order for a triplet.''' diff --git a/morphlib/util.py b/morphlib/util.py index e4681ec9..d1c60c36 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -13,6 +13,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import morphlib '''Utility functions for morph.''' @@ -60,3 +61,58 @@ def make_concurrency(cores=None): # gives about the optimal result for build times, since much of # builds are I/O bound, not CPU bound. return max(int(n * 1.5 + 0.5), 1) + + +def create_cachedir(settings): # pragma: no cover + '''Create a new cache directory.''' + + cachedir = settings['cachedir'] + if not os.path.exists(cachedir): + os.mkdir(cachedir) + return cachedir + + +def create_artifact_cachedir(settings): # pragma: no cover + '''Create a new directory for the local artifact cache.''' + + artifact_cachedir = os.path.join( + settings['cachedir'], 'artifacts') + if not os.path.exists(artifact_cachedir): + os.mkdir(artifact_cachedir) + return artifact_cachedir + + +def new_artifact_caches(settings): # pragma: no cover + '''Create new objects for local, remote artifact caches.''' + + create_cachedir(settings) + artifact_cachedir = create_artifact_cachedir(settings) + + lac = morphlib.localartifactcache.LocalArtifactCache(artifact_cachedir) + + rac_url = settings['cache-server'] + if rac_url: + rac = morphlib.remoteartifactcache.RemoteArtifactCache(rac_url) + else: + rac = None + return lac, rac + + +def new_repo_caches(app): # pragma: no cover + '''Create new objects for local, remote git repository caches.''' + + aliases = app.settings['repo-alias'] + cachedir = create_cachedir(app.settings) + gits_dir = os.path.join(cachedir, 'gits') + bundle_base_url = app.settings['bundle-server'] + repo_resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases) + lrc = morphlib.localrepocache.LocalRepoCache( + app, gits_dir, repo_resolver, bundle_base_url=bundle_base_url) + + url = app.settings['cache-server'] + if url: + rrc = morphlib.remoterepocache.RemoteRepoCache(url, repo_resolver) + else: + rrc = None + + return lrc, rrc |