summaryrefslogtreecommitdiff
path: root/morphlib/util.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-07-31 14:51:52 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-08-01 13:19:12 +0000
commitf968ecadfd972c6d032a519259cfa43dec020eac (patch)
treee99acdba01188bcada20dd493fd8aa0bd52cb065 /morphlib/util.py
parenta24f546197206774f846d4135285f7a918127475 (diff)
downloadmorph-f968ecadfd972c6d032a519259cfa43dec020eac.tar.gz
Move utility functions for creating caches
Code for creating caches is repeated through the codebase because there wasn't a useful function for creating caches. Now the functions in BuildCommand have been moved into morphlib.util, where they will be more usefully reachable. Stubs have been left in BuildCommand so they can be overridden by subclasses of BuildCommand and not break external plugins.
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