mushy 0.2.5 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76db9c933d82210929659d12c7e003926a9e6616bffa13b3bf52a10748397a77
4
- data.tar.gz: 619f6c29844f159327805bad1b5ab0a7c73b4292008bab772686af8caf90abb5
3
+ metadata.gz: 78f078fac4fc19b1ee58323ce2ceaed770613dd8c71901a8a9a7f4ba03c5b413
4
+ data.tar.gz: f19bde198e025b8478400fd33bbd8471b688b33b6caac27ae1f78441441bd895
5
5
  SHA512:
6
- metadata.gz: edfffd82e02a0e3e1bca89e7b448f4648c57ed130ab09228b743b494d4f78dd3fb995c6cee7277033702206bd96c3a62a193879cc71fc7c6342844cc45c49bcf
7
- data.tar.gz: ff241f80dbb70b03c7347895437f64e66765b94c99e3ec32a303e9dd6f36c43015c3d1b6935ccd7fc3f73719f4f726e68f2d4be0016ee5125e65e0c802fe6fff
6
+ metadata.gz: 6aff2c9d3d21517c385a5d1f5d0464ae37c77f281c32ef3a5f520cd667ad6354399f3be8e589dcd5883e4a8c0c60d321709373dd174dcd27813c77cb99c1958f
7
+ data.tar.gz: cc0c2218bc455af76721edf9f9358828a21a45635c31e4f5b6a049b03c98ba7f83ea2212567426fad6114042d29ccc0a02251ee502be69c16eeeca0763c9cb16
@@ -1,3 +1,5 @@
1
+ require 'daemons'
2
+
1
3
  module Mushy
2
4
 
3
5
  module Builder
@@ -32,9 +34,34 @@ module Mushy
32
34
  file = "#{file}.json" unless file.downcase.end_with?('.json')
33
35
  flow = File.open(file).read
34
36
  flow = Mushy::Flow.parse flow
35
- flux = flow.fluxs.select { |x| x.type == 'Cli' }.first
36
37
 
37
- Mushy::Runner.new.start event, flux, flow
38
+ service_fluxes = flow.fluxs.select { |x| x.respond_to? :loop }
39
+
40
+ pwd = Dir.pwd
41
+
42
+ if service_fluxes.any?
43
+ calls = service_fluxes
44
+ .map { |s| { flux: s, proc: ->(e) do
45
+ Dir.chdir pwd
46
+ Mushy::Runner.new.start e, s, flow
47
+ end } }
48
+ .map { |p| ->() { p[:flux].loop &p[:proc] } }
49
+ .map { |x| ->() { loop &x } }
50
+ .map { |x| run_as_a_daemon &x }
51
+
52
+ puts calls.inspect
53
+
54
+ exit
55
+ end
56
+
57
+ cli_flux = flow.fluxs.select { |x| x.kind_of?(Mushy::Cli) }.first
58
+
59
+ Mushy::Runner.new.start event, cli_flux, flow
60
+ end
61
+
62
+ def self.run_as_a_daemon &block
63
+ #block.call
64
+ Daemons.call(&block).pid.pid
38
65
  end
39
66
 
40
67
  def self.get_flow file
@@ -0,0 +1,30 @@
1
+ module Mushy
2
+
3
+ module DateParts
4
+
5
+ def self.parse now
6
+ {
7
+ year: nil,
8
+ month: nil,
9
+ day: nil,
10
+ hour: nil,
11
+ minute: :min,
12
+ second: :sec,
13
+ nanosecond: :nsec,
14
+ utc_offset: nil,
15
+ weekday: :wday,
16
+ day_of_month: :mday,
17
+ day_of_year: :yday,
18
+ string: :to_s,
19
+ epoch_integer: :to_i,
20
+ epoch_float: :to_f,
21
+ }.reduce({}) do |t, i|
22
+ method = i[1] || i[0]
23
+ t[i[0]] = now.send method
24
+ t
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -18,7 +18,7 @@ module Mushy
18
18
  description: 'Run this browser headless.',
19
19
  type: 'boolean',
20
20
  shrink: true,
21
- value: 'true',
21
+ value: '',
22
22
  },
23
23
  timeout: {
24
24
  description: 'The default timeout (in seconds) before closing the browser. Default is 5 seconds.',
@@ -0,0 +1,28 @@
1
+ module Mushy
2
+
3
+ class Environment < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Environment',
8
+ description: 'Pull environment variables.',
9
+ config: {
10
+ variables: {
11
+ description: 'Map the environment variables to a new event.',
12
+ type: 'keyvalue',
13
+ value: {},
14
+ },
15
+ },
16
+ }
17
+ end
18
+
19
+ def process event, config
20
+ config[:variables].reduce({}) do |t, i|
21
+ t[i[0]] = ENV[i[1]]
22
+ t
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,86 @@
1
+ module Mushy
2
+
3
+ class GitLog < Bash
4
+
5
+ def self.details
6
+ {
7
+ name: 'GitLog',
8
+ description: 'Return git logs.',
9
+ config: {
10
+ directory: {
11
+ description: 'The working directory in which the command will be run.',
12
+ type: 'text',
13
+ shrink: true,
14
+ value: '',
15
+ },
16
+ after: {
17
+ description: 'Filter for commits after this',
18
+ type: 'text',
19
+ shrink: true,
20
+ value: '',
21
+ },
22
+ before: {
23
+ description: 'Filter for commits before this',
24
+ type: 'text',
25
+ shrink: true,
26
+ value: '',
27
+ },
28
+ author: {
29
+ description: 'Filter for commits by this author',
30
+ type: 'text',
31
+ shrink: true,
32
+ value: '',
33
+ },
34
+ committer: {
35
+ description: 'Filter for commits by this committer',
36
+ type: 'text',
37
+ shrink: true,
38
+ value: '',
39
+ },
40
+ },
41
+ }
42
+ end
43
+
44
+ def process event, config
45
+
46
+ config[:command] = 'git log'
47
+
48
+ if config[:directory].to_s != ''
49
+ config[:command] = "cd \"#{config[:directory]}\";#{config[:command]}"
50
+ end
51
+
52
+ [:after, :before, :author, :committer]
53
+ .select { |x| config[x].to_s != ''}
54
+ .each { |k| config[:command] = "#{config[:command]} --#{k}=\"#{config[k]}\"" }
55
+
56
+ result = super event, config
57
+
58
+ return result unless result[:success]
59
+
60
+ result[:text].split("\n\n").reduce([]) do |results, line|
61
+ if line.start_with? 'commit'
62
+ results << { message: line.sub('commit', 'commit:') }
63
+ else
64
+ results[-1][:message] = results[-1][:message] + "\nMessage: " + line.strip
65
+ end
66
+ results
67
+ end.map { |x| x[:message] }.map do |line|
68
+ line.split("\n").reduce({}) do |t, i|
69
+ segments = i.split ':'
70
+ key = segments.shift.strip.downcase.to_sym
71
+ t[key] = segments.map { |y| y.strip }.join ':'
72
+ t
73
+ end
74
+ end.map do |commit|
75
+ commit.tap do |x|
76
+ segments = x[:author].split '<'
77
+ x[:author_name] = segments.shift.strip
78
+ x[:author_email] = segments.join('').strip.gsub('>', '')
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,56 @@
1
+ require 'csv'
2
+
3
+ module Mushy
4
+
5
+ class Interval < Flux
6
+
7
+ def self.setup
8
+ {
9
+ seconds: ->(x) { x },
10
+ minutes: ->(x) { x * 60 },
11
+ hours: ->(x) { x * 60 * 60 },
12
+ days: ->(x) { x * 60 * 60 * 24 },
13
+ weeks: ->(x) { x * 60 * 60 * 24 * 7 },
14
+ }
15
+ end
16
+
17
+ def self.details
18
+ {
19
+ name: 'Interval',
20
+ description: 'Fire an event every X minutes.',
21
+ config: {},
22
+ }.tap do |c|
23
+ setup.keys.each do |key|
24
+ c[:config][key] = {
25
+ description: "#{key.to_s.capitalize} until the job is fired again.",
26
+ type: 'integer',
27
+ shrink: true,
28
+ value: '',
29
+ }
30
+ end
31
+ end
32
+ end
33
+
34
+ def loop &block
35
+ event = { time: time }
36
+ block.call event
37
+ sleep time
38
+ end
39
+
40
+ def time
41
+ the_time = self.class.setup.keys
42
+ .select { |x| config[x].to_s != '' }
43
+ .map { |x| self.class.setup[x].call(config[x].to_i) }
44
+ .sum
45
+
46
+ the_time > 0 ? the_time : 60
47
+ end
48
+
49
+ def process event, config
50
+ now = Time.now
51
+ Mushy::DateParts.parse now
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -6,30 +6,82 @@ module Mushy
6
6
  {
7
7
  name: 'Ls',
8
8
  description: 'Run the "ls" command.',
9
- config: {
10
- directory: {
11
- description: 'The working directory in which the command will be run.',
12
- type: 'text',
13
- value: '',
14
- },
15
- },
16
- }
9
+ config: Mushy::Bash.details[:config].tap { |c| c.delete :command },
10
+ }.tap do |c|
11
+ c[:config][:recursive] = {
12
+ description: 'Pull files recursively.',
13
+ type: 'boolean',
14
+ shrink: true,
15
+ value: '',
16
+ }
17
+ end
17
18
  end
18
19
 
19
20
  def process event, config
20
21
 
21
- config[:command] = 'ls'
22
+ arguments = ['-A', '-l', '--full-time', '-i']
23
+ arguments << '-R' if config[:recursive].to_s == 'true'
24
+ config[:command] = "ls #{arguments.join(' ')}"
22
25
 
23
26
  result = super event, config
24
27
 
25
28
  return result unless result[:success]
26
29
 
27
- result[:text].split("\n").map do |x|
28
- {
29
- name: x,
30
- }
30
+ lines = result[:text].split("\n")
31
+ lines.shift
32
+
33
+ origin = config[:directory] || Dir.pwd
34
+ directory = origin
35
+ lines.map do |x|
36
+ segments = x.split ' '
37
+ result = if segments.count > 5
38
+ pull_file segments, directory
39
+ elsif segments.count == 1
40
+ dir_segments = segments[0].split("\/")
41
+ dir_segments[0] = origin if dir_segments[0] == '.'
42
+ dir_segments[-1] = dir_segments[-1].sub ':', ''
43
+ directory = dir_segments.join("\/")
44
+ nil
45
+ else
46
+ nil
47
+ end
48
+ end.select { |x| x }
49
+
50
+ end
51
+
52
+ def pull_file segments, directory
53
+ result = {}
54
+
55
+ [:inode, :help, :hard_links, :owner, :group, :size].each do |key|
56
+ result[key] = segments.shift; x = segments.join ' '
57
+ end
58
+
59
+ result.tap do |r|
60
+ r[:date] = []
61
+ 3.times { r[:date] << segments.shift }
62
+ r[:date] = r[:date].join ' '
63
+ r[:date] = Time.parse r[:date]
64
+ end
65
+
66
+ result[:name] = segments.shift
67
+
68
+ result.tap do |r|
69
+ help_segments = r[:help].split ''
70
+ r[:type] = help_segments[0]
71
+ r[:owner_permission] = [1, 2, 3].map { |i| help_segments[i] }.reduce('') { |t, i| t + i }
72
+ r[:group_permission] = [4, 5, 6].map { |i| help_segments[i] }.reduce('') { |t, i| t + i }
73
+ r[:other_permission] = [7, 8, 9].map { |i| help_segments[i] }.reduce('') { |t, i| t + i }
74
+ r.delete :help
31
75
  end
32
76
 
77
+ [:hard_links, :size].each { |x| result[x] = result[x].to_i }
78
+
79
+ result[:date_parts] = Mushy::DateParts.parse result[:date]
80
+
81
+ result[:directory] = directory
82
+ result[:path] = File.join result[:directory], result[:name]
83
+
84
+ result
33
85
  end
34
86
 
35
87
  end
@@ -0,0 +1,26 @@
1
+ module Mushy
2
+
3
+ class Print < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Print',
8
+ description: 'Print output to the screen.',
9
+ config: {
10
+ message: {
11
+ description: 'The message to display',
12
+ type: 'text',
13
+ value: '',
14
+ },
15
+ }
16
+ }
17
+ end
18
+
19
+ def process event, config
20
+ puts config[:message]
21
+ {}
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,29 @@
1
+ module Mushy
2
+
3
+ class Pwd < Bash
4
+
5
+ def self.details
6
+ {
7
+ name: 'Pwd',
8
+ description: 'Run the "pwd" command.',
9
+ config: Mushy::Bash.details[:config].tap { |c| c.delete :command },
10
+ }
11
+ end
12
+
13
+ def process event, config
14
+
15
+ config[:command] = 'pwd'
16
+
17
+ result = super event, config
18
+
19
+ return result unless result[:success]
20
+
21
+ {
22
+ pwd: result[:text].to_s.strip
23
+ }
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -7,11 +7,10 @@ module Mushy
7
7
  details['name'] = 'Screenshot'
8
8
  details['description'] = 'Take a screenshot of the browser.'
9
9
 
10
- details[:config][:path] = {
11
- description: 'The path of the file to save.',
12
- type: 'text',
13
- value: 'picture.jpg',
14
- }
10
+ details[:config].merge!(Mushy::WriteFile.file_saving_config.tap do |x|
11
+ x[x.keys.first][:value] = 'file.jpg'
12
+ end)
13
+
15
14
  details[:config][:quality] = {
16
15
  description: 'The quality of the image, a value beteen 0-100. Only applies to jpg.',
17
16
  type: 'integer',
@@ -33,15 +32,16 @@ module Mushy
33
32
  the_result = input[:result]
34
33
  the_config = input[:config]
35
34
 
35
+ file = Mushy::WriteFile.get_file_from config
36
36
  options = {
37
- path: the_config[:path],
37
+ path: file,
38
38
  full: ['true', ''].include?(the_config[:full].to_s),
39
39
  quality: (the_config[:quality].to_s == '' ? '100' : the_config[:quality]).to_i
40
40
  }
41
41
 
42
42
  the_browser.screenshot options
43
43
 
44
- options
44
+ options.merge the_result
45
45
 
46
46
  end
47
47
 
@@ -6,30 +6,40 @@ module Mushy
6
6
  {
7
7
  name: 'WriteFile',
8
8
  description: 'Write a file.',
9
- config: {
10
- name: {
11
- description: 'The name of the file.',
12
- type: 'text',
13
- value: 'file.csv',
14
- },
15
- directory: {
16
- description: 'The directory in which to write the file. Leave blank for the current directory.',
17
- type: 'text',
18
- value: '',
19
- },
20
- data: {
21
- description: 'The text to write. You can use Liquid templating here to pull data from the event, or write hardcoded data.',
22
- type: 'text',
23
- value: '{{data}}',
24
- },
25
- },
9
+ config: file_saving_config.merge({
10
+ data: {
11
+ description: 'The text to write. You can use Liquid templating here to pull data from the event, or write hardcoded data.',
12
+ type: 'text',
13
+ value: '{{data}}',
14
+ },
15
+ }),
26
16
  }
27
17
  end
28
18
 
29
- def process event, config
30
- file = config[:name]
19
+ def self.file_saving_config
20
+ {
21
+ name: {
22
+ description: 'The name of the file.',
23
+ type: 'text',
24
+ value: 'file.csv',
25
+ },
26
+ directory: {
27
+ description: 'The directory in which to write the file. Leave blank for the current directory.',
28
+ shrink: true,
29
+ type: 'text',
30
+ value: '',
31
+ },
32
+ }
33
+ end
31
34
 
35
+ def self.get_file_from config
36
+ file = config[:name]
32
37
  file = File.join(config[:directory], file) if config[:directory].to_s != ''
38
+ file
39
+ end
40
+
41
+ def process event, config
42
+ file = self.class.get_file_from config
33
43
 
34
44
  File.open(file, 'w') { |f| f.write config[:data] }
35
45
 
data/mushy.gemspec CHANGED
@@ -4,7 +4,7 @@ require 'mushy/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'mushy'
7
- s.version = '0.2.5'
7
+ s.version = '0.4.1'
8
8
  s.date = '2020-11-23'
9
9
  s.summary = 'Process streams of work using common modules.'
10
10
  s.description = 'This tool assists in the creation and processing of workflows.'
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'nokogiri'
26
26
  s.add_runtime_dependency 'faraday'
27
27
  s.add_runtime_dependency 'pony'
28
+ s.add_runtime_dependency 'daemons'
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: daemons
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: This tool assists in the creation and processing of workflows.
140
154
  email: darren@cauthon.com
141
155
  executables:
@@ -150,6 +164,7 @@ files:
150
164
  - lib/mushy/builder/dark.rb
151
165
  - lib/mushy/builder/index.rb
152
166
  - lib/mushy/builder/vue.rb
167
+ - lib/mushy/date_parts.rb
153
168
  - lib/mushy/event.rb
154
169
  - lib/mushy/flow.rb
155
170
  - lib/mushy/flux.rb
@@ -158,12 +173,17 @@ files:
158
173
  - lib/mushy/fluxs/build_csv.rb
159
174
  - lib/mushy/fluxs/cli.rb
160
175
  - lib/mushy/fluxs/collection.rb
176
+ - lib/mushy/fluxs/environment.rb
161
177
  - lib/mushy/fluxs/filter.rb
162
178
  - lib/mushy/fluxs/format.rb
163
179
  - lib/mushy/fluxs/get.rb
180
+ - lib/mushy/fluxs/git_log.rb
181
+ - lib/mushy/fluxs/interval.rb
164
182
  - lib/mushy/fluxs/ls.rb
165
183
  - lib/mushy/fluxs/parse_html.rb
166
184
  - lib/mushy/fluxs/pdf.rb
185
+ - lib/mushy/fluxs/print.rb
186
+ - lib/mushy/fluxs/pwd.rb
167
187
  - lib/mushy/fluxs/read_csv.rb
168
188
  - lib/mushy/fluxs/read_file.rb
169
189
  - lib/mushy/fluxs/screenshot.rb