ctpl 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 39f9ba2aa1c4a4447e103877e3359da29014a1abbea37a6b5488943b70402c49
4
+ data.tar.gz: 8df159dc2c6ed9df666d08f4ee5c3c0a7551ae4391e9448e7e2f7cee128f4329
5
+ SHA512:
6
+ metadata.gz: 2d1bf9aa0c7bb316f242251eb98a58ac897af1d1c7444d9690685193aa954bb49961d4ab5255648a7fd669cc06dc0d82357b9085945285dba9995938e770396f
7
+ data.tar.gz: 1286c803991fe936ddc6db8b6324b875eef4a3507ae9de1a1a257e41b863df813e50122b27cacfc71655961b1153df3cdf41b9942eb0f5b3ee4ee963d6423340
data/Thorfile ADDED
@@ -0,0 +1,15 @@
1
+ main = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
2
+ main = File.dirname(main)
3
+ lib = File.expand_path('./lib', main)
4
+ thor = File.expand_path('./thor', main)
5
+
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ $dwm_root = File.expand_path('./', __dir__)
8
+
9
+
10
+ require 'ctpl/parser/pipeline'
11
+
12
+ Dir.glob(File.join(thor, '/**/*.thor')).each { |taskfile|
13
+ # noinspection RubyResolve
14
+ load taskfile
15
+ }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/ctpl ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ main = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
3
+ main = File.dirname(main)
4
+ lib = File.expand_path('../lib', main)
5
+ thor = File.expand_path('../thor', main)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ $dwm_root = Gem::Specification.find_by_name('dwm').gem_dir
8
+
9
+ require 'thor'
10
+
11
+ Dir.glob(File.join(thor, '/**/*.thor')).each { |taskfile|
12
+ load taskfile
13
+ }
14
+
15
+ if Process.uid == 0
16
+ puts 'Error: Do not run dwm as root'
17
+ exit 1
18
+ end
19
+
20
+ begin
21
+ # show the generate help by default
22
+ if ARGV[0] == "help" || ARGV[0] == "--help" || ARGV[0] == "-?"
23
+ ARGV.unshift("generate")
24
+ ARGV.unshift("help")
25
+ elsif ARGV[0] != "generate" # default to generate if nothing else passed
26
+ ARGV.unshift("generate")
27
+ end
28
+
29
+ Ctpl::Generate.start(ARGV)
30
+ rescue Exception => e
31
+ puts e
32
+ if ARGV.include?('-v') || ARGV.include?('--verbose')
33
+ puts e.backtrace.join("\n")
34
+ end
35
+
36
+ exit 1
37
+ end
@@ -0,0 +1,83 @@
1
+ require 'yaml'
2
+
3
+ class PipelineMerger
4
+ include Thor::Shell
5
+
6
+ def initialize(mainPipelinePath, globalAliasesPath, partialsFolder)
7
+ loadGlobalAliases(globalAliasesPath)
8
+ loadMainPipeline(mainPipelinePath)
9
+ loadPartials(partialsFolder)
10
+ end
11
+
12
+ def merge
13
+ pipeline = {}
14
+ pipeline = parseToYaml(@mainPipeline) unless @mainPipeline == ""
15
+
16
+ # that is our one level merger for the special keys we support
17
+ @partials.each do |filename, partialContent|
18
+ say_status 'ok', "merging partial #{filename}", :white
19
+ partialAsHashmap = parseToYaml(partialContent)
20
+
21
+ %w(jobs resources resource_types groups).each do |mergeKey|
22
+ if partialAsHashmap.key?(mergeKey)
23
+ pipeline[mergeKey] = [] unless pipeline.key?(mergeKey)
24
+ pipeline[mergeKey].concat partialAsHashmap[mergeKey]
25
+ partialAsHashmap.delete(mergeKey)
26
+ end
27
+ end
28
+
29
+ # now put all the others which should not be conflicting. We might do this manually per key to inform
30
+ # when we have conflicts .. since this will override existing keys
31
+ pipeline.merge(partialAsHashmap)
32
+ end
33
+
34
+ raise "The pipeline-file is empty, most probably your baseFolder was wrong or it is empty" if pipeline.empty?
35
+ pipeline
36
+ end
37
+
38
+ def parseToYaml(body)
39
+ # add our global aliases before you transform to yaml to ensure we can lookup those
40
+ YAML.load(body)
41
+ end
42
+
43
+ def loadGlobalAliases(globalAliasesPath)
44
+ if File.exist?(globalAliasesPath)
45
+ say_status 'success', "Global alias file found and loaded from #{globalAliasesPath}", :green
46
+
47
+ @globalAliases = File.read(globalAliasesPath)
48
+ else
49
+ say_status 'ok', "No global alias file found at #{globalAliasesPath}", :white
50
+ @globalAliases = ""
51
+ end
52
+ end
53
+
54
+ def loadMainPipeline(mainPipelinePath)
55
+ if File.exist?(mainPipelinePath)
56
+ say_status 'success', "Main pipeline file found and loaded from #{mainPipelinePath}", :green
57
+
58
+ @mainPipeline = @globalAliases + "\n" + File.read(mainPipelinePath)
59
+ else
60
+ say_status 'ok', "No Main pipeline file found at #{mainPipelinePath}", :white
61
+ @mainPipeline = ""
62
+ end
63
+ end
64
+
65
+ def loadPartials(partialsFolder)
66
+ say_status 'warning', "Partial folder not found at #{partialsFolder}", :yellow unless Dir.exist?(partialsFolder)
67
+
68
+ @partials = {}
69
+ # our partials must start with _
70
+ Dir.glob("#{partialsFolder}/**/_*.yaml") do |f|
71
+ content = File.read(f)
72
+ @partials[f] = @globalAliases + "\n" + content if content
73
+ end
74
+ end
75
+
76
+ def globalAliases
77
+ @globalAliases
78
+ end
79
+
80
+ def mainPipeline
81
+ @mainPipeline
82
+ end
83
+ end
@@ -0,0 +1,22 @@
1
+ require 'ctpl/merger'
2
+
3
+ module Ctpl
4
+ class Generate < Thor
5
+ include Thor::Actions
6
+ class_option :verbose, :type => :boolean, :aliases => '-v', :default => false, :banner => 'Activate verbose mode', :desc => 'If used show errors, stacktraces and more'
7
+
8
+ desc 'generate', 'Handle all marked instances, either to install or install'
9
+ method_option :basefolder, :aliases => 'b', :required => false, :type => :string, :default => './', :desc => "Optional - defaults to ./pipeline, falls back to PWD. The base-folder the pipeline.yaml, alias.yaml and the partials are located. \nIf you pass /tmp/foo we will look for /tmp/foo/pipeline.yaml, optionally for /tmp/foo/aliases.yaml and all /tmp/foo/*_.yaml files as partials"
10
+ method_option :output, :aliases => 'o', :required => false, :type => :string, :default => './pipeline.yml', :desc => "Optional, defaults to pipeline.yml. Output path to save the merged yaml in"
11
+ def generate
12
+ baseFolder = options[:basefolder]
13
+ merger = PipelineMerger.new("#{baseFolder}/pipeline.yaml", "#{baseFolder}/aliases.yaml", baseFolder)
14
+ p = merger.merge
15
+ say_status 'ok', "Transforming back to yaml ", :white
16
+ yaml = p.to_yaml
17
+ say_status 'ok', "Saving to #{options[:output]} ", :white
18
+ File.write(options[:output], yaml)
19
+ end
20
+ end
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ctpl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eugen Mayer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.20.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.20'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.20.0
33
+ description: ctpl
34
+ email: eugen.mayer@kontextwork.de
35
+ executables:
36
+ - ctpl
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - Thorfile
41
+ - VERSION
42
+ - bin/ctpl
43
+ - lib/ctpl/merger.rb
44
+ - thor/generate.thor
45
+ homepage: ''
46
+ licenses:
47
+ - GPL
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.7.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: ctpl
69
+ test_files: []