summaryrefslogtreecommitdiff
path: root/morphlib/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/util.py')
-rw-r--r--morphlib/util.py56
1 files changed, 56 insertions, 0 deletions
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