grably 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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +2 -0
  4. data/exe/grably +2 -0
  5. data/lib/ext/class.rb +28 -0
  6. data/lib/grably.rb +83 -0
  7. data/lib/grably/cli.rb +46 -0
  8. data/lib/grably/core.rb +15 -0
  9. data/lib/grably/core/app/enchancer.rb +36 -0
  10. data/lib/grably/core/application.rb +8 -0
  11. data/lib/grably/core/colors.rb +86 -0
  12. data/lib/grably/core/commands.rb +23 -0
  13. data/lib/grably/core/commands/cp.rb +103 -0
  14. data/lib/grably/core/commands/digest.rb +12 -0
  15. data/lib/grably/core/commands/log.rb +19 -0
  16. data/lib/grably/core/commands/run.rb +85 -0
  17. data/lib/grably/core/commands/serialize.rb +16 -0
  18. data/lib/grably/core/configuration.rb +39 -0
  19. data/lib/grably/core/configuration/pretty_print.rb +22 -0
  20. data/lib/grably/core/digest.rb +93 -0
  21. data/lib/grably/core/dsl.rb +15 -0
  22. data/lib/grably/core/essentials.rb +49 -0
  23. data/lib/grably/core/module.rb +64 -0
  24. data/lib/grably/core/product.rb +301 -0
  25. data/lib/grably/core/task.rb +30 -0
  26. data/lib/grably/core/task/bucket.rb +29 -0
  27. data/lib/grably/core/task/enchancer.rb +50 -0
  28. data/lib/grably/core/task/expand.rb +15 -0
  29. data/lib/grably/core/task/jobs.rb +58 -0
  30. data/lib/grably/job.rb +28 -0
  31. data/lib/grably/job/class.rb +93 -0
  32. data/lib/grably/job/exceptions.rb +0 -0
  33. data/lib/grably/job/instance.rb +159 -0
  34. data/lib/grably/job/manifest.rb +67 -0
  35. data/lib/grably/jobs.rb +4 -0
  36. data/lib/grably/jobs/sync.rb +91 -0
  37. data/lib/grably/jobs/text.rb +4 -0
  38. data/lib/grably/jobs/text/erb.rb +40 -0
  39. data/lib/grably/jobs/text/json.rb +12 -0
  40. data/lib/grably/jobs/text/text.rb +21 -0
  41. data/lib/grably/jobs/text/yaml.rb +12 -0
  42. data/lib/grably/jobs/unzip.rb +1 -0
  43. data/lib/grably/jobs/upload.rb +1 -0
  44. data/lib/grably/jobs/zip.rb +2 -0
  45. data/lib/grably/jobs/zip/unzip.rb +24 -0
  46. data/lib/grably/jobs/zip/zip.rb +46 -0
  47. data/lib/grably/runner.rb +31 -0
  48. data/lib/grably/server.rb +83 -0
  49. data/lib/grably/utils/pretty_printer.rb +63 -0
  50. data/lib/grably/version.rb +12 -0
  51. metadata +164 -0
@@ -0,0 +1,4 @@
1
+ require_relative 'text/text'
2
+ require_relative 'text/json'
3
+ require_relative 'text/yaml'
4
+ require_relative 'text/erb'
@@ -0,0 +1,40 @@
1
+ require 'erb'
2
+ require_relative 'text'
3
+
4
+ module Grably
5
+ class ErbJob < TextJob # :nodoc:
6
+ class ErbBinder < OpenStruct # :nodoc:
7
+ def eval(template)
8
+ ERB.new(template).result(binding)
9
+ end
10
+ end
11
+
12
+ call_as :erb
13
+
14
+ src :template
15
+ opt :content
16
+ opt :filename
17
+ opt :context
18
+
19
+ def setup(template:, context:)
20
+ @template = template
21
+ @content = read(template)
22
+ @filename = basename(template, '.erb')
23
+ @context = context
24
+ end
25
+
26
+ def dump(content, io)
27
+ io << ErbBinder.new(context).eval(content)
28
+ end
29
+
30
+ def read(src)
31
+ src = src.src if src.is_a?(Product)
32
+ IO.read(src)
33
+ end
34
+
35
+ def basename(file, ext = nil)
36
+ file = file.src if file.is_a? Product
37
+ File.basename(file, ext)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ require 'json'
2
+ require_relative 'text'
3
+
4
+ module Grably
5
+ class JsonJob < TextJob # :nodoc:
6
+ call_as :json
7
+
8
+ def dump(content, io)
9
+ JSON.dump(content, io)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module Grably
2
+ class TextJob # :nodoc:
3
+ include Grably::Job
4
+
5
+ call_as :text
6
+ opt :content
7
+ opt :filename
8
+
9
+ def build
10
+ out = job_dir(filename)
11
+ File.open(out, 'w') do |f|
12
+ dump(content, f)
13
+ end
14
+ out
15
+ end
16
+
17
+ def dump(content, io)
18
+ io << content
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ require 'yaml'
2
+ require_relative 'text'
3
+
4
+ module Grably
5
+ class YamlJob < TextJob # :nodoc:
6
+ call_as :yaml
7
+
8
+ def dump(content, io)
9
+ YAML.dump(content, io)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ unzip.rb
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,2 @@
1
+ require_relative 'zip/zip'
2
+ require_relative 'zip/unzip'
@@ -0,0 +1,24 @@
1
+ module Grably # :nodoc:
2
+ # TBD
3
+ class UnzipJob
4
+ include Grably::Job
5
+
6
+ srcs :files
7
+
8
+ def setup(files)
9
+ @files = files
10
+ end
11
+
12
+ def build
13
+ log 'Unpacking files'
14
+ out = job_dir('out')
15
+ FileUtils.mkdir_p(out)
16
+
17
+ files.each do |s|
18
+ ['unzip', '-d', out, s.src].run
19
+ end
20
+
21
+ out
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,46 @@
1
+ module Grably # :nodoc:
2
+ # TBD
3
+ class ZipJob
4
+ include Grably::Job
5
+
6
+ OPTIONS = {
7
+ compression_level: ->(value) { "-r#{value}" }
8
+ }.freeze
9
+
10
+ srcs :files
11
+ opt :dst
12
+ opt :meta
13
+
14
+ def setup(srcs, dst, meta = {})
15
+ @files = srcs
16
+ @dst = dst
17
+ @meta = meta
18
+ end
19
+
20
+ def build
21
+ if files.empty?
22
+ warn 'No files to zip'
23
+ return []
24
+ end
25
+
26
+ log "Zipping #{files.size} files into #{File.basename(dst)}"
27
+
28
+ src_dir = job_dir('src')
29
+ ln(files, src_dir)
30
+ zip(src_dir)
31
+ end
32
+
33
+ def zip(dir)
34
+ Dir.chdir(dir) do
35
+ ['zip', cflags, File.join('..', File.basename(dst)), '.'].run
36
+ end
37
+ Product.new(job_dir(File.basename(dst)), dst, meta)
38
+ end
39
+
40
+ def cflags
41
+ OPTIONS
42
+ .select { |k, _v| meta.key?(k) }
43
+ .map { |k, _v| OPTIONS[k].call(meta[k]) }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rake'
4
+
5
+ module Rake
6
+ class Application # :nodoc:
7
+ def run_tasks(tasks)
8
+ standard_exception_handling do
9
+ collect_command_line_tasks(tasks)
10
+ top_level
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ rake = Rake.application
17
+ rake.init
18
+ ENV['EXPORT'] = '1'
19
+ rake.load_rakefile
20
+
21
+ $stdin.each do |l|
22
+ cmds = l.strip.split('|')
23
+ cmd = cmds.shift
24
+ exit(0) if cmd == 'exit'
25
+ exit(1) unless cmd == 'build'
26
+ Grably.export_path = cmds.shift
27
+ Grably.export_tasks = cmds
28
+ rake.run_tasks(cmds)
29
+ puts 'remote_grab_finished'
30
+ $stdout.flush
31
+ end
@@ -0,0 +1,83 @@
1
+ require 'tempfile'
2
+ require 'open3'
3
+
4
+ module Grably
5
+ # Entry point to submodule task management
6
+ class Server
7
+ EXPORT_FILENAME = 'grably.export'.freeze
8
+ def initialize
9
+ @child_processes = {}
10
+ end
11
+
12
+ def schedule(call)
13
+ ->(dir) { remote_result(call, File.expand_path(File.join(dir, EXPORT_FILENAME))) }
14
+ end
15
+
16
+ def remote_result(call, out_file)
17
+ execute(call, out_file)
18
+ load_obj(out_file)
19
+ end
20
+
21
+ # rubocop:disable all
22
+ def execute(call, out_file, prefix: ' ')
23
+ rakefile = call.path
24
+
25
+ profile = *call.profile.map(&:to_s)
26
+
27
+ if Grably.export_path
28
+ data = [ rakefile, out_file, { 'target' => call.task, 'profile' => profile, 'params' => params } ]
29
+ puts "remote_mbuild_request:#{JSON.generate(data)}"
30
+ $stdout.flush
31
+ $stdin.each do |l|
32
+ raise "error in remote (slave) grably" unless l.strip == 'remote_grab_finished'
33
+ break
34
+ end
35
+ else
36
+ key = { rakefile: rakefile, profile: profile }
37
+
38
+ process = @child_processes[key]
39
+
40
+ unless process
41
+ env = { 'config' => nil }
42
+ cmd = [
43
+ RbConfig.ruby,
44
+ File.expand_path(File.join(__dir__, 'runner.rb')),
45
+ '-f',
46
+ File.basename(rakefile),
47
+ "mp=#{profile.join(',')}"
48
+ ]
49
+ cmd << "--trace" if Rake.application.options.trace
50
+
51
+ stdin, stdout, thread = Open3.popen2(*[env, cmd, { :err => [ :child, :out], :chdir => File.dirname(rakefile) }].flatten)
52
+ stdout.sync = true
53
+ stdin.sync = true
54
+
55
+ process = { stdin: stdin, stdout: stdout, thread: thread }
56
+ @child_processes[key] = process
57
+ end
58
+
59
+ process[:stdin].puts("build|#{out_file}|#{[call.task].flatten.join('|')}")
60
+
61
+ ok = false
62
+ process[:stdout].each do |l|
63
+ ls = l.strip
64
+ if ls == 'remote_grab_finished'
65
+ ok = true
66
+ break
67
+ end
68
+
69
+ if ls.start_with?('remote_grab_request:')
70
+ data = JSON.parse(ls['remote_grab_request:'.size..-1])
71
+ execute(data[0], data[1], "#{prefix} ", { target: data[2]['target'], profile: data[2]['profile'], params: data[2]['params']})
72
+ process[:stdin].puts('remote_grab_finished')
73
+ else
74
+ log "#{prefix}#{l}"
75
+ end
76
+ end
77
+
78
+ raise 'error in remote grab' unless ok
79
+ end
80
+ end
81
+ # rubocop:enable all
82
+ end
83
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ module Grably
3
+ module Utils
4
+ # Profile structure printer
5
+ module PrettyPrinter
6
+ def print(hash, buffer, ident)
7
+ hash.each do |key, value|
8
+ v = value[:value]
9
+ r = value[:raw_value] # raw value for interpolated strings
10
+ print_top_level(key, v, r, buffer, ident)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def print_top_level(key, value, raw, buffer, ident)
17
+ buffer << "#{ident}#{key}: "
18
+ if value.is_a?(Hash) || value.is_a?(Array)
19
+ buffer << "\n"
20
+ print_value(value, buffer, ident + ' ')
21
+ else
22
+ buffer << value.to_s
23
+ buffer << "(raw: #{raw})" if raw
24
+ buffer << "\n"
25
+ end
26
+ end
27
+
28
+ def print_value(v, buffer, ident, skip = false)
29
+ if v.is_a? Array
30
+ print_array(v, buffer, ident, skip)
31
+ elsif v.is_a? Hash
32
+ print_hash(v, buffer, ident, skip)
33
+ else
34
+ print_string(v, buffer, ident, skip)
35
+ end
36
+ end
37
+
38
+ def print_string(v, buffer, _, _ = false)
39
+ buffer << v
40
+ buffer << "\n"
41
+ end
42
+
43
+ def print_hash(v, buffer, ident, skip_first = false)
44
+ i = skip_first ? '' : ident
45
+ v.each do |k, e|
46
+ buffer << "#{i}#{k}: "
47
+ print_value(e, buffer, ident + ' ', !e.is_a?(Array))
48
+ i = ident
49
+ end
50
+ end
51
+
52
+ def print_array(v, buffer, ident, skip_first = false)
53
+ i = skip_first ? '' : ident
54
+ v.each do |e|
55
+ buffer << "#{i}- "
56
+ buffer << "\n" if e.is_a?(Array)
57
+ print_value(e, buffer, ident + ' ', !e.is_a?(Array))
58
+ i = ident
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,12 @@
1
+ module Grably # :nodoc:
2
+ class << self
3
+ # Current grably version identifier
4
+ VERSION = [0, 0, 1].freeze
5
+
6
+ # Returns grably version string
7
+ # @return [String] version string
8
+ def version
9
+ VERSION.join('.')
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grably
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Arkhanhelsky
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: jac
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: powerpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email: ilya.arkhanhelsky@vizor-games.com
85
+ executables:
86
+ - grably
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - exe/grably
93
+ - lib/ext/class.rb
94
+ - lib/grably.rb
95
+ - lib/grably/cli.rb
96
+ - lib/grably/core.rb
97
+ - lib/grably/core/app/enchancer.rb
98
+ - lib/grably/core/application.rb
99
+ - lib/grably/core/colors.rb
100
+ - lib/grably/core/commands.rb
101
+ - lib/grably/core/commands/cp.rb
102
+ - lib/grably/core/commands/digest.rb
103
+ - lib/grably/core/commands/log.rb
104
+ - lib/grably/core/commands/run.rb
105
+ - lib/grably/core/commands/serialize.rb
106
+ - lib/grably/core/configuration.rb
107
+ - lib/grably/core/configuration/pretty_print.rb
108
+ - lib/grably/core/digest.rb
109
+ - lib/grably/core/dsl.rb
110
+ - lib/grably/core/essentials.rb
111
+ - lib/grably/core/module.rb
112
+ - lib/grably/core/product.rb
113
+ - lib/grably/core/task.rb
114
+ - lib/grably/core/task/bucket.rb
115
+ - lib/grably/core/task/enchancer.rb
116
+ - lib/grably/core/task/expand.rb
117
+ - lib/grably/core/task/jobs.rb
118
+ - lib/grably/job.rb
119
+ - lib/grably/job/class.rb
120
+ - lib/grably/job/exceptions.rb
121
+ - lib/grably/job/instance.rb
122
+ - lib/grably/job/manifest.rb
123
+ - lib/grably/jobs.rb
124
+ - lib/grably/jobs/sync.rb
125
+ - lib/grably/jobs/text.rb
126
+ - lib/grably/jobs/text/erb.rb
127
+ - lib/grably/jobs/text/json.rb
128
+ - lib/grably/jobs/text/text.rb
129
+ - lib/grably/jobs/text/yaml.rb
130
+ - lib/grably/jobs/unzip.rb
131
+ - lib/grably/jobs/upload.rb
132
+ - lib/grably/jobs/zip.rb
133
+ - lib/grably/jobs/zip/unzip.rb
134
+ - lib/grably/jobs/zip/zip.rb
135
+ - lib/grably/runner.rb
136
+ - lib/grably/server.rb
137
+ - lib/grably/utils/pretty_printer.rb
138
+ - lib/grably/version.rb
139
+ homepage: https://rubygems.org/gems/grably
140
+ licenses:
141
+ - Apache-2.0
142
+ metadata:
143
+ source_code_uri: https://github.com/vizor-games/grably
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.7.6
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Ruby library turning Rake into extreemly powerful build tool
164
+ test_files: []