fileminer 1.0.0RC2 → 1.0.0RC3

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: 1d91beff05e6ea886d8ae759e10c9c2eec3ff68b3956e0fde10feb776508992d
4
- data.tar.gz: 3ec5242e111743a162485e276ede29b35ad86eb9946305b0c40fe73aed6fe6fd
3
+ metadata.gz: 6899adc461f156ac6e112c5d6e72b45baf51f71d0fd480812b150f112538b6d3
4
+ data.tar.gz: cd461fe3a027047a9ffa63c8aedbe7352d1e700c14d243823080350649103fbc
5
5
  SHA512:
6
- metadata.gz: df1266173e4fa6e7a0afa87c64b186113e51da3b67f0a66e7f524428ec57489d723e31f6203f91e36d9ea1fe0e40431e888dea204372fc6fd8a33a68ee9959a3
7
- data.tar.gz: 1ba61ef7e12ac9163a98f15a50c896a6ae012a47b86435b974411e3cfd7e9f9cd6b7d847c82cad05c44a95dea3884bf504a5ce128a8afde75451bdd617cecfa3
6
+ metadata.gz: b6b00dbaaafabfc8869d2971cb5ce39977b48ee713b4acbd9910336e69f610c95930c68f6ad82f214b1d7696f7cf1cd836113bf5ba4f0d0846e5d4ee71de3aae
7
+ data.tar.gz: f7bebce4c3a21351f737651b0ea15f8292021a35a94055e8048f36430d9dd316931588b66d5bbb27390e69db828cd7277e744b267281a31dda1f03b3f9983247
data/bin/fileminer CHANGED
@@ -10,8 +10,9 @@ logger = Logger.new STDERR
10
10
 
11
11
  begin
12
12
  # Usage:
13
- # ruby -Ilib ./bin/fileminer /path/to/fileminer.yml
14
- yml = File.open(ARGV[0]) { |io| io.read }
13
+ # fileminer [/path/to/fileminer.yml]
14
+ path = ARGV.empty? ? '/etc/fileminer/fileminer.yml' : ARGV[0]
15
+ yml = File.open(path) { |io| io.read }
15
16
  conf = YAML.load yml
16
17
  # create fileminer instance
17
18
  fileminer = FileMiner.new conf
@@ -23,9 +24,6 @@ begin
23
24
  fileminer.start_mining
24
25
  rescue => e
25
26
  logger.error e
26
- usage = <<-EOS
27
- Usage:
28
- ruby -Ilib ./bin/fileminer /path/to/fileminer.yml
29
- EOS
27
+ usage = 'Usage: fileminer [/path/to/fileminer.yml]'
30
28
  puts usage
31
29
  end
@@ -1,20 +1,93 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
 
4
+ require 'optparse'
4
5
  require_relative '../lib/fileminer/tools/io'
5
6
 
6
- current_path = File.absolute_path __FILE__
7
- bin_path = File.dirname current_path
8
- project_path = File.dirname bin_path
9
- default_file_path = File.join project_path, 'conf', 'fileminer_default.yml'
10
7
 
11
- dst = ARGV.empty? ? '/etc/fileminer/fileminer.yml' : File.absolute_path(ARGV[0])
12
- unless dst.end_with?('.yml') || dst.end_with?('.yaml')
13
- dst = File.join dst, 'fileminer.yml'
8
+ def gen_fileminer_conf(options)
9
+ current_path = File.absolute_path __FILE__
10
+ bin_path = File.dirname current_path
11
+ project_path = File.dirname bin_path
12
+ default_file_path = File.join project_path, 'conf', 'fileminer_default.yml'
13
+ if options.key? :out
14
+ out = options[:out]
15
+ dst = out.nil? ? '/etc/fileminer/fileminer.yml' : File.absolute_path(out)
16
+ unless dst.end_with?('.yml') || dst.end_with?('.yaml')
17
+ dst = File.join dst, 'fileminer.yml'
18
+ end
19
+
20
+ dst_dir = File.dirname dst
21
+ Dir.mkdirs dst_dir unless Dir.exist? dst_dir
22
+
23
+ File.copy_stream default_file_path, dst
24
+ puts "generated config file: #{dst}"
25
+ else
26
+ content = File.open(default_file_path) { |io| io.read }
27
+ puts content
28
+ end
29
+ end
30
+
31
+ def gen_supervisor_conf(options)
32
+ wrapper_home = File.join ENV['GEM_HOME'], 'wrappers'
33
+ content = <<-EOS
34
+ [program:fileminer]
35
+ command=#{wrapper_home}/fileminer
36
+ autostart=true
37
+ autorestart=true
38
+ stopsinal=INT
39
+ user=root
40
+ EOS
41
+ if options.key? :out
42
+ out = options[:out]
43
+ dst = out.nil? ? './fileminer.ini' : File.absolute_path(out)
44
+ unless dst.end_with?('.ini') || dst.end_with?('.conf')
45
+ dst = File.join dst, 'fileminer.ini'
46
+ end
47
+
48
+ dst_dir = File.dirname dst
49
+ Dir.mkdirs dst_dir unless Dir.exists? dst_dir
50
+ File.open(dst, 'w') { |io| io.write content }
51
+ else
52
+ puts content
53
+ end
14
54
  end
15
55
 
16
- dst_dir = File.dirname dst
17
- Dir.mkdirs dst_dir unless Dir.exist? dst_dir
18
56
 
19
- File.copy_stream default_file_path, dst
20
- puts "generated config file: #{dst}"
57
+ options = Hash.new
58
+ OptionParser.new do |opts|
59
+ # banner
60
+ opts.banner = "Usage: fileminer-genconf [options]"
61
+ opts.separator ''
62
+ opts.separator 'Options:'
63
+
64
+ # help
65
+ opts.on_tail('-h', '--help', 'Print help') do
66
+ puts opts
67
+ puts ''
68
+ exit
69
+ end
70
+
71
+ # type
72
+ options[:type] = :fileminer
73
+ opts.on('-t', '--type fileminer|supervisor', [:fileminer, :supervisor],
74
+ 'Type of the config file to be generated', 'Default is fileminer') do |value|
75
+ options[:type] = value
76
+ end
77
+
78
+ # out
79
+ opts.on('-o', '--out [path]',
80
+ 'Output content to a file',
81
+ 'For type fileminer, default is /etc/fileminer/fileminer.yml',
82
+ 'For type supervisor, default is ./fileminer.ini') do |value|
83
+ options[:out] = value
84
+ end
85
+
86
+ end.parse!
87
+
88
+ case options[:type]
89
+ when :fileminer
90
+ gen_fileminer_conf options
91
+ when :supervisor
92
+ gen_supervisor_conf options
93
+ end
@@ -1,5 +1,5 @@
1
1
  class FileMiner
2
2
 
3
- VERSION = '1.0.0RC2'
3
+ VERSION = '1.0.0RC3'
4
4
 
5
- end
5
+ end
data/lib/fileminer.rb CHANGED
@@ -1,6 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
-
4
1
  require 'logger'
5
2
  require_relative 'fileminer/miner'
6
3
  require_relative 'fileminer/plugins'
@@ -215,15 +212,3 @@ class FileMiner
215
212
  end
216
213
 
217
214
  end
218
-
219
-
220
- if __FILE__ == $0
221
- # Usage:
222
- # ruby fileminer.rb /etc/fileminer/fileminer.yml
223
- require 'yaml'
224
- yml = File.open(ARGV[0]) { |io| io.read }
225
- conf = YAML.load yml
226
- fileminer = FileMiner.new conf
227
- trap(:INT) { fileminer.stop_mining }
228
- fileminer.start_mining
229
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fileminer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0RC2
4
+ version: 1.0.0RC3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fang MinJie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple file/log transfer tool coding by ruby.
14
14
  email: