summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-10-06 13:22:47 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-10-07 11:29:40 +0100
commit4e2f04721d4724ad74cce3645a59eedb84c8fc6d (patch)
tree61a5c802b7b7011e75ba7071c9eecf4790ef29e3
parentd9fa855e5b5a6fca890ec8426daefbf49c2352d6 (diff)
downloadmorph-4e2f04721d4724ad74cce3645a59eedb84c8fc6d.tar.gz
import: make omnibus.to_chunk work
-rw-r--r--import/main.py24
-rwxr-xr-ximport/omnibus.to_chunk39
-rwxr-xr-ximport/omnibus.to_lorry18
3 files changed, 57 insertions, 24 deletions
diff --git a/import/main.py b/import/main.py
index 767deef1..cf5836c1 100644
--- a/import/main.py
+++ b/import/main.py
@@ -321,6 +321,9 @@ def run_extension(filename, args, cwd='.'):
main_path = os.path.dirname(os.path.realpath(__file__))
extension_path = os.path.join(main_path, filename)
+ logging.debug(
+ "Running %s %s with cwd %s, env %s" % (extension_path, args, cwd,
+ os.environ))
returncode = ext.run(extension_path, args, cwd, os.environ)
if returncode == 0:
@@ -539,7 +542,7 @@ class BaserockImportApplication(cliapp.Application):
chunk_morph = self.find_or_create_chunk_morph(
morph_set, goal_name, kind, name, checked_out_version,
- package_definition_repo, url, ref)
+ package_definition_repo, url, ref, definitions_dir)
current_item.set_morphology(chunk_morph)
@@ -693,20 +696,28 @@ class BaserockImportApplication(cliapp.Application):
return version, ref
def generate_chunk_morph_for_package(self, kind, source_repo, name,
- version, filename):
+ version, filename, definitions_dir):
tool = '%s.to_chunk' % kind
self.status('Calling %s to generate chunk morph for %s', tool, name)
- args = [source_repo.dirname, name]
+ if definitions_dir is None:
+ cwd = '.'
+ args = [source_repo.dirname, name]
+ else:
+ cwd = definitions_dir.rsplit('#')[0]
+ args = [definitions_dir, name]
+
if version != 'master':
args.append(version)
- text = run_extension(tool, args)
+
+ text = run_extension(tool, args, cwd=cwd)
loader = morphlib.morphloader.MorphologyLoader()
return loader.load_from_string(text, filename)
def find_or_create_chunk_morph(self, morph_set, goal_name, kind, name,
- version, source_repo, repo_url, named_ref):
+ version, source_repo, repo_url, named_ref,
+ definitions_dir):
morphology_filename = 'strata/%s/%s-%s.morph' % (
goal_name, name, version)
#sha1 = source_repo.resolve_ref_to_commit(named_ref)
@@ -714,7 +725,8 @@ class BaserockImportApplication(cliapp.Application):
def generate_morphology():
morphology = self.generate_chunk_morph_for_package(
- kind, source_repo, name, version, morphology_filename)
+ kind, source_repo, name, version, morphology_filename,
+ definitions_dir)
morph_set.save_morphology(morphology_filename, morphology)
return morphology
diff --git a/import/omnibus.to_chunk b/import/omnibus.to_chunk
index 142370ab..c086381e 100755
--- a/import/omnibus.to_chunk
+++ b/import/omnibus.to_chunk
@@ -26,9 +26,14 @@ require 'shellwords'
require_relative 'importer_base'
-TARGET_PROJECT = 'chefdk' # should come from args
+# This DEFINITIONS#PROJECT thing is a bit shit. Make main.py smarter about
+# being able to pass extra arguments to import extensions instead of forcing
+# everything into two arguments.
+BANNER = "Usage: omnibus.to_chunk DEFINITIONS_DIR#PROJECT_NAME SOFTWARE_NAME"
-TARGET_SOFTWARE = 'chefdk' # should come from args
+DESCRIPTION = <<-END
+Generate a .morph file for a given Omnibus software component.
+END
class Omnibus::Builder
# It's possible to use `gem install` in build commands, which is a great
@@ -64,6 +69,26 @@ class Omnibus::Builder
end
class OmnibusChunkMorphologyGenerator < Importer::Base
+ def parse_options(arguments)
+ opts = create_option_parser(BANNER, DESCRIPTION)
+
+ parsed_arguments = opts.parse!(arguments)
+
+ if parsed_arguments.length != 2 and parsed_arguments.length != 3
+ STDERR.puts "Expected 2 or 3 arguments, got #{parsed_arguments}."
+ opts.parse(['-?'])
+ exit 255
+ end
+
+ project_dir_and_name, software_name, expected_version = parsed_arguments
+ project_dir, _, project_name = project_dir_and_name.rpartition('#')
+ # Not yet implemented
+ #if expected_version != nil
+ # expected_version = Gem::Version.new(expected_version)
+ #end
+ [project_dir, project_name, software_name, expected_version]
+ end
+
def deps_for_software(software)
deps = Hash.new
software.dependencies.each do |dep|
@@ -99,9 +124,15 @@ class OmnibusChunkMorphologyGenerator < Importer::Base
end
def run
- project = Omnibus::Project.load(TARGET_PROJECT)
+ project_dir, project_name, software_name = parse_options(ARGV)
+
+ log.info("Creating chunk morph for #{software_name} from project " +
+ "#{project_name}, defined in #{project_dir}")
+ log.debug("Running in: #{Dir.getwd}")
+
+ project = Omnibus::Project.load(project_name)
- software = Omnibus::Software.load(project, TARGET_SOFTWARE)
+ software = Omnibus::Software.load(project, software_name)
morph = generate_chunk_morph_for_software(software)
diff --git a/import/omnibus.to_lorry b/import/omnibus.to_lorry
index 0172faad..249bfd31 100755
--- a/import/omnibus.to_lorry
+++ b/import/omnibus.to_lorry
@@ -26,11 +26,9 @@ require 'shellwords'
require_relative 'importer_base'
-TARGET_PROJECT = 'chefdk' # should come from args
-
-TARGET_SOFTWARE = 'chefdk' # should come from args
-
-# This DEFINITIONS#PROJECT thing is a bit shit. Make main.py smarter.
+# This DEFINITIONS#PROJECT thing is a bit shit. Make main.py smarter about
+# being able to pass extra arguments to import extensions instead of forcing
+# everything into two arguments.
BANNER = "Usage: omnibus.to_lorry DEFINITIONS_DIR#PROJECT_NAME SOFTWARE_NAME"
DESCRIPTION = <<-END
@@ -77,19 +75,11 @@ class OmnibusLorryGenerator < Importer::Base
end
def run
- STDERR.puts("Current working directory: #{Dir.getwd}")
- log.info("Current working directory: #{Dir.getwd}")
project_dir, project_name, software_name = parse_options(ARGV)
log.info("Creating lorry for #{software_name} from project " +
"#{project_name}, defined in #{project_dir}")
-
- # Omnibus definitions are spread across multiple repos, and there is
- # no stability guarantee for the definition format. The official advice
- # is to use Bundler to execute Omnibus, so let's do that.
- ensure_running_inside_bundler_exec(project_dir)
-
- STDERR.puts Omnibus.projects()
+ log.debug("Running in: #{Dir.getwd}")
project = Omnibus::Project.load(project_name)