mushy 0.4.1 → 0.6.0

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: 78f078fac4fc19b1ee58323ce2ceaed770613dd8c71901a8a9a7f4ba03c5b413
4
- data.tar.gz: f19bde198e025b8478400fd33bbd8471b688b33b6caac27ae1f78441441bd895
3
+ metadata.gz: dcfab01a12d0d1a59c024265891b2851943755a0cdb9468768dd71c3fbcc1c63
4
+ data.tar.gz: ed387d7e22cc0368e1d309326dd646cb284256b030ced1da44106a6dad3f1979
5
5
  SHA512:
6
- metadata.gz: 6aff2c9d3d21517c385a5d1f5d0464ae37c77f281c32ef3a5f520cd667ad6354399f3be8e589dcd5883e4a8c0c60d321709373dd174dcd27813c77cb99c1958f
7
- data.tar.gz: cc0c2218bc455af76721edf9f9358828a21a45635c31e4f5b6a049b03c98ba7f83ea2212567426fad6114042d29ccc0a02251ee502be69c16eeeca0763c9cb16
6
+ metadata.gz: d633be32aec24e036a0c8b6ffc185b743f95d78a9b986304dabaff72a642fdfe09a48ca86d3753b1e1dfb722347cccf33392fb651befbae28177e9dcc9889808
7
+ data.tar.gz: 0d54c907f8ec088f928fc0cd4ca88c72203e6080e0ccb5bc96b23b31dca329fa673b84168017effdc19a33dd8f5598100039675b34db20adfb7ee5c282cc7cd7
data/bin/mushy CHANGED
@@ -10,7 +10,8 @@ class MushyCLI < Thor
10
10
 
11
11
  desc "start FILE", "Run this workflow file."
12
12
  def start
13
- Mushy::Builder::Api.start file, values
13
+ v = values || {}
14
+ Mushy::Builder::Api.start file, v
14
15
  end
15
16
 
16
17
  desc "build FILE", 'Build a flow.'
@@ -40,16 +40,25 @@ module Mushy
40
40
  pwd = Dir.pwd
41
41
 
42
42
  if service_fluxes.any?
43
- calls = service_fluxes
43
+
44
+ things = service_fluxes
44
45
  .map { |s| { flux: s, proc: ->(e) do
45
46
  Dir.chdir pwd
46
47
  Mushy::Runner.new.start e, s, flow
47
- end } }
48
+ end,
49
+ run_method: (s.config[:run_strategy] == 'daemon' ? :run_this_as_a_daemon : :run_this_inline),
50
+ }
51
+ }.group_by { |x| x[:run_method] }
52
+
53
+ calls = (things[:run_this_as_a_daemon] || [])
48
54
  .map { |p| ->() { p[:flux].loop &p[:proc] } }
49
55
  .map { |x| ->() { loop &x } }
50
- .map { |x| run_as_a_daemon &x }
56
+ .map { |x| run_this_as_a_daemon &x }
51
57
 
52
- puts calls.inspect
58
+ (things[:run_this_inline] || [])
59
+ .map { |p| ->() { p[:flux].loop &p[:proc] } }
60
+ .map { |x| ->() { loop &x } }
61
+ .map { |x| run_this_inline &x }
53
62
 
54
63
  exit
55
64
  end
@@ -59,8 +68,11 @@ module Mushy
59
68
  Mushy::Runner.new.start event, cli_flux, flow
60
69
  end
61
70
 
62
- def self.run_as_a_daemon &block
63
- #block.call
71
+ def self.run_this_inline &block
72
+ block.call
73
+ end
74
+
75
+ def self.run_this_as_a_daemon &block
64
76
  Daemons.call(&block).pid.pid
65
77
  end
66
78
 
@@ -93,8 +105,27 @@ module Mushy
93
105
  details[:config][:limit] = { type: 'integer', shrink: true, description: 'Limit the number of events to this number.', default: '' }
94
106
  details[:config][:join] = { type: 'text', shrink: true, description: 'Join all of the events from this flux into one event, under this name.', default: '' }
95
107
  details[:config][:sort] = { type: 'text', shrink: true, description: 'Sort by this key.', default: '' }
108
+ details[:config][:ignore] = { type: 'text', shrink: true, description: 'Ignore these keys.', value: '', default: '' }
96
109
  details[:config][:model] = { type: 'keyvalue', shrink: true, description: 'Reshape the outgoing events.', value: {}, default: {} }
97
110
 
111
+ details[:config][:error_strategy] = {
112
+ description: 'Error strategy. (return to return an event with "exception" returning the error, or ignore to ignore the exception)',
113
+ type: 'select',
114
+ options: ['', 'return', 'ignore'],
115
+ value: '',
116
+ shrink: true,
117
+ }
118
+
119
+ if flux.new.respond_to? :loop
120
+ details[:config][:run_strategy] = {
121
+ description: 'Run this using this strategy. (select "daemon" if this should be run in the background)',
122
+ type: 'select',
123
+ options: ['', 'inline', 'daemon'],
124
+ value: '',
125
+ shrink: true,
126
+ }
127
+ end
128
+
98
129
  details[:config]
99
130
  .select { |_, v| v[:type] == 'keyvalue' }
100
131
  .select { |_, v| v[:editors].nil? }
@@ -106,7 +137,7 @@ module Mushy
106
137
  end
107
138
 
108
139
  details
109
- end
140
+ end.sort_by { |x| x[:name] }
110
141
  }
111
142
  end
112
143
 
@@ -22,6 +22,8 @@ module Mushy
22
22
  method = i[1] || i[0]
23
23
  t[i[0]] = now.send method
24
24
  t
25
+ end.tap do |hash|
26
+ hash[:seconds_ago] = Time.now - now
25
27
  end
26
28
  end
27
29
 
data/lib/mushy/flux.rb CHANGED
@@ -77,6 +77,10 @@ module Mushy
77
77
 
78
78
  returned_one_result ? results.first : results
79
79
 
80
+ rescue Exception => e
81
+ raise e if config[:error_strategy].to_s == ''
82
+ return [] if config[:error_strategy] == 'ignore'
83
+ { exception: e.message }
80
84
  end
81
85
 
82
86
  def standardize_these results
@@ -87,7 +91,7 @@ module Mushy
87
91
  end
88
92
 
89
93
  def shape_these results, event, config
90
- supported_shaping = [:merge, :outgoing_split, :group, :model, :join, :sort, :limit]
94
+ supported_shaping = [:merge, :outgoing_split, :group, :model, :ignore, :join, :sort, :limit]
91
95
 
92
96
  shaping = supported_shaping
93
97
  if (config[:shaping])
@@ -132,6 +136,13 @@ module Mushy
132
136
  results.map { |x| masher.mash by, x }
133
137
  end
134
138
 
139
+ def ignore_these_results results, event, by
140
+ return results if by.to_s == ''
141
+ ignore_fields = by.split ','
142
+ results.each { |r| ignore_fields.each { |f| r.delete f } }
143
+ results
144
+ end
145
+
135
146
  def merge_these_results results, event, by
136
147
  keys_to_merge = convert_this_to_an_array by
137
148
  keys_to_merge = event.keys.map { |x| x.to_s } if (keys_to_merge[0] == '*')
@@ -15,6 +15,7 @@ module Mushy
15
15
  directory: {
16
16
  description: 'The working directory in which the command will be run.',
17
17
  type: 'text',
18
+ shrink: true,
18
19
  value: '',
19
20
  },
20
21
  },
@@ -90,7 +90,9 @@ module Mushy
90
90
 
91
91
  browser.headers.add get_the_headers_from(event, config)
92
92
 
93
+ the_start = Time.now
93
94
  browser.goto config[:url]
95
+ time = Time.now - the_start
94
96
 
95
97
  browser.execute(config[:execute]) if config[:execute]
96
98
 
@@ -102,6 +104,7 @@ module Mushy
102
104
  title: browser.frames[0].title,
103
105
  cookies: browser.cookies.all.map { |k, v| v.instance_variable_get('@attributes') },
104
106
  headers: browser.headers.get,
107
+ time: time,
105
108
  body: browser.body
106
109
  }
107
110
 
@@ -0,0 +1,27 @@
1
+ module Mushy
2
+
3
+ class Document < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Document',
8
+ description: 'Create a multi-line document.',
9
+ config: {
10
+ document: {
11
+ description: 'The multi-line document you wish to create.',
12
+ type: 'textarea',
13
+ value: '',
14
+ },
15
+ },
16
+ }
17
+ end
18
+
19
+ def process event, config
20
+ {
21
+ document: config[:document],
22
+ }
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,46 @@
1
+ require 'listen'
2
+
3
+ module Mushy
4
+
5
+ class FileWatch < Flux
6
+
7
+ def self.details
8
+ {
9
+ name: 'FileWatch',
10
+ description: 'Watch for file changes.',
11
+ config: {
12
+ directory: {
13
+ description: 'The directory to watch.',
14
+ type: 'text',
15
+ value: '',
16
+ },
17
+ },
18
+ }
19
+ end
20
+
21
+ def loop &block
22
+
23
+ directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
24
+
25
+ listener = Listen.to(directory) do |modified, added, removed|
26
+ the_event = {
27
+ modified: modified,
28
+ added: added,
29
+ removed: removed,
30
+ }
31
+ block.call the_event
32
+ end
33
+
34
+ listener.start
35
+
36
+ sleep
37
+
38
+ end
39
+
40
+ def process event, config
41
+ event
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -14,31 +14,62 @@ module Mushy
14
14
  shrink: true,
15
15
  value: '',
16
16
  }
17
+ c[:config][:path] = {
18
+ description: 'Path, used to search for specific files.',
19
+ type: 'text',
20
+ shrink: true,
21
+ value: '',
22
+ }
17
23
  end
18
24
  end
19
25
 
20
26
  def process event, config
27
+ arguments = build_the_arguments_from config
21
28
 
29
+ config[:command] = build_the_command_from arguments
30
+ result = super event, config
31
+
32
+ things = turn_the_ls_output_to_events result, config, event
33
+ things
34
+ end
35
+
36
+ def build_the_command_from arguments
37
+ "ls #{arguments.join(' ')}"
38
+ end
39
+
40
+ def build_the_arguments_from config
22
41
  arguments = ['-A', '-l', '--full-time', '-i']
23
42
  arguments << '-R' if config[:recursive].to_s == 'true'
24
- config[:command] = "ls #{arguments.join(' ')}"
25
-
26
- result = super event, config
43
+ arguments << '-d' if config[:directory_only].to_s == 'true'
44
+ arguments << "'#{config[:path]}'" if config[:path].to_s != ''
45
+ arguments
46
+ end
27
47
 
28
- return result unless result[:success]
48
+ def turn_the_ls_output_to_events result, config, event
29
49
 
30
50
  lines = result[:text].split("\n")
31
- lines.shift
51
+
52
+ needs_special_work_for_path = config[:directory_only].to_s != 'true' &&
53
+ config[:path].to_s != '' &&
54
+ lines[0] &&
55
+ lines[0].start_with?('total ')
32
56
 
33
57
  origin = config[:directory] || Dir.pwd
34
- directory = origin
35
- lines.map do |x|
58
+ directory = needs_special_work_for_path ? '||DIRECTORY||' : origin
59
+
60
+ things = lines.map do |x|
36
61
  segments = x.split ' '
37
62
  result = if segments.count > 5
38
63
  pull_file segments, directory
39
64
  elsif segments.count == 1
40
65
  dir_segments = segments[0].split("\/")
41
- dir_segments[0] = origin if dir_segments[0] == '.'
66
+
67
+ if dir_segments[0] == '.'
68
+ dir_segments[0] = origin
69
+ else
70
+ dir_segments.unshift origin
71
+ end
72
+
42
73
  dir_segments[-1] = dir_segments[-1].sub ':', ''
43
74
  directory = dir_segments.join("\/")
44
75
  nil
@@ -47,6 +78,19 @@ module Mushy
47
78
  end
48
79
  end.select { |x| x }
49
80
 
81
+ if needs_special_work_for_path
82
+ config[:directory_only] = true
83
+ special_name = process(event, config)[0][:name]
84
+ things.each do |x|
85
+ [:directory, :path].each do |key|
86
+ if x[key].include?('||DIRECTORY||')
87
+ x[key].sub!('||DIRECTORY||', File.join(Dir.pwd, special_name))
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ things
50
94
  end
51
95
 
52
96
  def pull_file segments, directory
@@ -63,7 +107,7 @@ module Mushy
63
107
  r[:date] = Time.parse r[:date]
64
108
  end
65
109
 
66
- result[:name] = segments.shift
110
+ result[:name] = segments.join ' '
67
111
 
68
112
  result.tap do |r|
69
113
  help_segments = r[:help].split ''
@@ -76,10 +120,18 @@ module Mushy
76
120
 
77
121
  [:hard_links, :size].each { |x| result[x] = result[x].to_i }
78
122
 
79
- result[:date_parts] = Mushy::DateParts.parse result[:date]
123
+ result[:date] = Mushy::DateParts.parse result[:date]
80
124
 
81
125
  result[:directory] = directory
82
- result[:path] = File.join result[:directory], result[:name]
126
+
127
+ if result[:type] == 'd' && result[:directory] == result[:name]
128
+ result[:path] = result[:directory]
129
+ name_segments = result[:name].split "\/"
130
+ result[:name] = name_segments.pop
131
+ result[:directory] = name_segments.join "\/"
132
+ else
133
+ result[:path] = File.join result[:directory], result[:name]
134
+ end
83
135
 
84
136
  result
85
137
  end
@@ -18,8 +18,10 @@ module Mushy
18
18
 
19
19
  return result unless result[:success]
20
20
 
21
+ pwd = result[:text].to_s.strip
22
+
21
23
  {
22
- pwd: result[:text].to_s.strip
24
+ pwd: Mushy::Ls.new.process({}, { path: pwd, directory_only: true })[0]
23
25
  }
24
26
 
25
27
  end
@@ -32,7 +32,7 @@ module Mushy
32
32
  the_result = input[:result]
33
33
  the_config = input[:config]
34
34
 
35
- file = Mushy::WriteFile.get_file_from config
35
+ file = Mushy::WriteFile.get_file_from the_config
36
36
  options = {
37
37
  path: file,
38
38
  full: ['true', ''].include?(the_config[:full].to_s),
@@ -41,7 +41,10 @@ module Mushy
41
41
 
42
42
  the_browser.screenshot options
43
43
 
44
- options.merge the_result
44
+ the_result[:options] = options
45
+ the_result[:file] = Mushy::Ls.new.process({}, { path: file })[0]
46
+
47
+ the_result
45
48
 
46
49
  end
47
50
 
@@ -0,0 +1,29 @@
1
+ module Mushy
2
+
3
+ class Times < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Times',
8
+ description: 'Return the event passed to it, X times.',
9
+ config: {
10
+ times: {
11
+ description: 'The number of times this event should be returned.',
12
+ type: 'integer',
13
+ value: '1',
14
+ },
15
+ }
16
+ }
17
+ end
18
+
19
+ def process event, config
20
+ config[:times]
21
+ .to_i
22
+ .times
23
+ .each_with_index
24
+ .map { |x, i| event.dup.tap { |e| e[:index] = i } }
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -43,7 +43,9 @@ module Mushy
43
43
 
44
44
  File.open(file, 'w') { |f| f.write config[:data] }
45
45
 
46
- {}
46
+ {
47
+ file: Mushy::Ls.new.process({}, { path: file })[0]
48
+ }
47
49
  end
48
50
 
49
51
  end
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.4.1'
7
+ s.version = '0.6.0'
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.'
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_runtime_dependency 'faraday'
27
27
  s.add_runtime_dependency 'pony'
28
28
  s.add_runtime_dependency 'daemons'
29
+ s.add_runtime_dependency 'listen'
29
30
  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.4.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: listen
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: This tool assists in the creation and processing of workflows.
154
168
  email: darren@cauthon.com
155
169
  executables:
@@ -173,7 +187,9 @@ files:
173
187
  - lib/mushy/fluxs/build_csv.rb
174
188
  - lib/mushy/fluxs/cli.rb
175
189
  - lib/mushy/fluxs/collection.rb
190
+ - lib/mushy/fluxs/document.rb
176
191
  - lib/mushy/fluxs/environment.rb
192
+ - lib/mushy/fluxs/file_watch.rb
177
193
  - lib/mushy/fluxs/filter.rb
178
194
  - lib/mushy/fluxs/format.rb
179
195
  - lib/mushy/fluxs/get.rb
@@ -188,6 +204,7 @@ files:
188
204
  - lib/mushy/fluxs/read_file.rb
189
205
  - lib/mushy/fluxs/screenshot.rb
190
206
  - lib/mushy/fluxs/smtp.rb
207
+ - lib/mushy/fluxs/times.rb
191
208
  - lib/mushy/fluxs/write_file.rb
192
209
  - lib/mushy/masher.rb
193
210
  - lib/mushy/run.rb