eventhub-command 0.3.13 → 0.3.14

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.
@@ -1,25 +1,25 @@
1
- desc 'deploy a single ruby processor'
2
- arg_name '[processor_name,[other_processor_name,pattern*]]'
3
-
4
- command :deploy_ruby do |c|
5
- c.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage where processor is deployed to', default_value: Eh::Settings.current.default_stage)
6
- c.flag([:deploy_via], desc: 'how to get hold of the processor: scm or scp', type: String, long_desc: 'copy the processor zip file via scp from this machine or check it out from scm', default_value: 'svn')
7
- c.flag([:branch], desc: 'branch', type: String, long_desc: 'What branch to deploy. Only when deploy_via=scm', default_value: 'master')
8
- c.flag([:tag], desc: 'tag', type: String, long_desc: 'What tag to deploy. Only when deploy_via=scm', default_value: nil)
9
-
10
- c.switch([:v, :verbose], :desc => 'Show additional output.')
11
-
12
- c.action do |global_options, options, args|
13
- begin
14
- if args[0]
15
- processor_names = args[0].split(',').map(&:strip)
16
- else
17
- processor_names = nil
18
- end
19
- Deployer::RubyDeployer.new(processor_names, options).deploy!
20
- rescue => e
21
- puts e.message
22
- puts e.backtrace.join("\n")
23
- end
24
- end
25
- end
1
+ desc 'deploy a single ruby processor'
2
+ arg_name '[processor_name,[other_processor_name,pattern*]]'
3
+
4
+ command :deploy_ruby do |c|
5
+ c.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage where processor is deployed to', default_value: Eh::Settings.current.default_stage)
6
+ c.flag([:deploy_via], desc: 'how to get hold of the processor: scm or scp', type: String, long_desc: 'copy the processor zip file via scp from this machine or check it out from scm', default_value: 'svn')
7
+ c.flag([:branch], desc: 'branch', type: String, long_desc: 'What branch to deploy. Only when deploy_via=scm', default_value: 'master')
8
+ c.flag([:tag], desc: 'tag', type: String, long_desc: 'What tag to deploy. Only when deploy_via=scm', default_value: nil)
9
+
10
+ c.switch([:v, :verbose], :desc => 'Show additional output.')
11
+
12
+ c.action do |global_options, options, args|
13
+ begin
14
+ if args[0]
15
+ processor_names = args[0].split(',').map(&:strip)
16
+ else
17
+ processor_names = nil
18
+ end
19
+ Deployer::RubyDeployer.new(processor_names, options).deploy!
20
+ rescue => e
21
+ puts e.message
22
+ puts e.backtrace.join("\n")
23
+ end
24
+ end
25
+ end
@@ -1,90 +1,90 @@
1
- desc 'Generates a template for a processor'
2
- arg_name 'module_name processor_name'
3
-
4
- command :generate_processor do |c|
5
- c.action do |global_options, options, args|
6
- require 'active_support/core_ext/string/inflections'
7
- require 'fileutils'
8
- require 'erb'
9
-
10
- if args.size != 2
11
- puts "Needs exactly 2 arguments: eh generate_processor ModuleName ProcessorName"
12
- exit -1
13
- end
14
-
15
- processor_module_name = args[0].camelcase
16
- processor_class_name = args[1].camelcase
17
- underscored_processor_module_name = processor_module_name.underscore
18
- underscored_processor_class_name = processor_class_name.underscore
19
-
20
- destination_dir = Eh::Settings.current.processors_src_dir
21
- destination_dir = File.join(destination_dir, "#{underscored_processor_module_name}.#{underscored_processor_class_name}")
22
-
23
- if Dir.exists? destination_dir
24
- puts "#{destination_dir} already exists!"
25
- exit -1
26
- end
27
-
28
- template_tmp_dir = Eh::Settings.current.template_tmp_dir
29
- checkout_git_repo(template_tmp_dir)
30
-
31
- FileUtils.cp_r template_tmp_dir, destination_dir
32
- FileUtils.rm_rf File.join(destination_dir, ".git")
33
- FileUtils.rm File.join(destination_dir, 'README.md')
34
-
35
- puts "Generating processor #{processor_module_name}::#{processor_class_name} in #{destination_dir}"
36
- Dir.glob(destination_dir + "/**/*.erb") do |file|
37
- template = ERB.new(File.read(file))
38
-
39
- File.open(file, "w") do |writeable_file|
40
- writeable_file.puts template.result(binding)
41
- end
42
-
43
- FileUtils.mv file, File.join(File.dirname(file), File.basename(file, ".erb"))
44
- end
45
-
46
- replacements = [
47
- ["underscored_processor_module_name", underscored_processor_module_name],
48
- ["underscored_processor_class_name", underscored_processor_class_name],
49
- ["processor_module_name", processor_module_name],
50
- ["processor_class_name", processor_class_name]
51
- ]
52
-
53
- rename_files_with_replacements(destination_dir, replacements)
54
-
55
- FileUtils.rm_rf template_tmp_dir
56
-
57
- puts "Done."
58
- end
59
- end
60
-
61
- def shallow_clone_git_repository(source_url, destination_dir)
62
- system("git clone --depth 1 #{source_url} #{destination_dir}")
63
- end
64
-
65
- def rename_files_with_replacements(destination_dir, replacements)
66
- Dir.glob(destination_dir + "/**/*") do |src_file_path|
67
- if File.file? src_file_path
68
- dir = File.dirname src_file_path
69
- file_with_replacements = File.basename src_file_path
70
-
71
- replacements.each do |find_string, replace_string|
72
- file_with_replacements.sub!(find_string, replace_string)
73
- end
74
-
75
- dest_file_path = File.join(dir, file_with_replacements)
76
-
77
- if src_file_path != dest_file_path
78
- FileUtils.mv src_file_path, dest_file_path
79
- end
80
- end
81
- end
82
- end
83
-
84
- def checkout_git_repo(destination_dir)
85
- template_repository_url = Eh::Settings.current.processor_template_repository_url
86
- puts "Checking out latest template from #{template_repository_url}"
87
- FileUtils.rm_rf(destination_dir)
88
- FileUtils.mkdir(destination_dir)
89
- shallow_clone_git_repository(template_repository_url, destination_dir)
90
- end
1
+ desc 'Generates a template for a processor'
2
+ arg_name 'module_name processor_name'
3
+
4
+ command :generate_processor do |c|
5
+ c.action do |global_options, options, args|
6
+ require 'active_support/core_ext/string/inflections'
7
+ require 'fileutils'
8
+ require 'erb'
9
+
10
+ if args.size != 2
11
+ puts "Needs exactly 2 arguments: eh generate_processor ModuleName ProcessorName"
12
+ exit -1
13
+ end
14
+
15
+ processor_module_name = args[0].camelcase
16
+ processor_class_name = args[1].camelcase
17
+ underscored_processor_module_name = processor_module_name.underscore
18
+ underscored_processor_class_name = processor_class_name.underscore
19
+
20
+ destination_dir = Eh::Settings.current.processors_src_dir
21
+ destination_dir = File.join(destination_dir, "#{underscored_processor_module_name}.#{underscored_processor_class_name}")
22
+
23
+ if Dir.exists? destination_dir
24
+ puts "#{destination_dir} already exists!"
25
+ exit -1
26
+ end
27
+
28
+ template_tmp_dir = Eh::Settings.current.template_tmp_dir
29
+ checkout_git_repo(template_tmp_dir)
30
+
31
+ FileUtils.cp_r template_tmp_dir, destination_dir
32
+ FileUtils.rm_rf File.join(destination_dir, ".git")
33
+ FileUtils.rm File.join(destination_dir, 'README.md')
34
+
35
+ puts "Generating processor #{processor_module_name}::#{processor_class_name} in #{destination_dir}"
36
+ Dir.glob(destination_dir + "/**/*.erb") do |file|
37
+ template = ERB.new(File.read(file))
38
+
39
+ File.open(file, "w") do |writeable_file|
40
+ writeable_file.puts template.result(binding)
41
+ end
42
+
43
+ FileUtils.mv file, File.join(File.dirname(file), File.basename(file, ".erb"))
44
+ end
45
+
46
+ replacements = [
47
+ ["underscored_processor_module_name", underscored_processor_module_name],
48
+ ["underscored_processor_class_name", underscored_processor_class_name],
49
+ ["processor_module_name", processor_module_name],
50
+ ["processor_class_name", processor_class_name]
51
+ ]
52
+
53
+ rename_files_with_replacements(destination_dir, replacements)
54
+
55
+ FileUtils.rm_rf template_tmp_dir
56
+
57
+ puts "Done."
58
+ end
59
+ end
60
+
61
+ def shallow_clone_git_repository(source_url, destination_dir)
62
+ system("git clone --depth 1 #{source_url} #{destination_dir}")
63
+ end
64
+
65
+ def rename_files_with_replacements(destination_dir, replacements)
66
+ Dir.glob(destination_dir + "/**/*") do |src_file_path|
67
+ if File.file? src_file_path
68
+ dir = File.dirname src_file_path
69
+ file_with_replacements = File.basename src_file_path
70
+
71
+ replacements.each do |find_string, replace_string|
72
+ file_with_replacements.sub!(find_string, replace_string)
73
+ end
74
+
75
+ dest_file_path = File.join(dir, file_with_replacements)
76
+
77
+ if src_file_path != dest_file_path
78
+ FileUtils.mv src_file_path, dest_file_path
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def checkout_git_repo(destination_dir)
85
+ template_repository_url = Eh::Settings.current.processor_template_repository_url
86
+ puts "Checking out latest template from #{template_repository_url}"
87
+ FileUtils.rm_rf(destination_dir)
88
+ FileUtils.mkdir(destination_dir)
89
+ shallow_clone_git_repository(template_repository_url, destination_dir)
90
+ end
@@ -1,113 +1,113 @@
1
- desc 'Packages processors to zip files. '
2
- arg_name '[processor_name,[other_processor_name,pattern*]]'
3
- command :package_ruby do |c|
4
- c.flag([:x, :exclude], :desc => "Exclude processors by name.", :type => Array, :long_desc => "You can specify multiple processors by providing a comma-separated list.")
5
- c.flag([:d, :destination], :desc => "Destination directory to place created zip files.", :default_value => Eh::Settings.current.ruby_release_dir)
6
- c.flag([:s, :source], :desc => "Source directory to read processors from.", :default_value => Eh::Settings.current.processors_src_dir)
7
-
8
- c.action do |global_options, options, args|
9
- source_dir = options['s']
10
- destination_dir = options['d']
11
-
12
- puts "Will package processors from #{source_dir} to #{destination_dir}"
13
- # find all processors in the base directory
14
- processor_names = Dir["#{source_dir}/*"].map do |dir|
15
- File.basename(dir)
16
- end
17
-
18
- # Drop files, only use directories
19
- processor_names.delete_if do |item|
20
- !File.directory?("#{source_dir}/#{item}")
21
- end
22
-
23
- included_processor_names = processor_names
24
-
25
- # if processor names are given as arguments then use them.
26
- # can contain wildcards like "console.*" to include all processors
27
- # starting with "console.".
28
- if args[0]
29
- processor_names_from_arguments = args[0].split(',').map(&:strip)
30
-
31
- included_processor_names = included_processor_names.select do |processor_name|
32
- processor_names_from_arguments.any? do |query|
33
- if query.end_with?('*')
34
- processor_name.start_with?(query.gsub('*', ''))
35
- else
36
- processor_name == query
37
- end
38
- end
39
- end
40
- end
41
-
42
- # exclude processors specified by -x option, if option is given
43
- if options['x']
44
- # check if any processor has been excluded from packaging
45
- included_processor_names = included_processor_names.select do |processor_name|
46
- !options['x'].include?(processor_name)
47
- end
48
- end
49
-
50
- # make sure we have at least one processor
51
- if included_processor_names.empty?
52
- raise "There are no processor names. Either your -s directory is empty or you specified a strange combination of -x and -p"
53
- end
54
-
55
- # make sure destination directory exists
56
- FileUtils.mkdir_p(destination_dir)
57
-
58
- Eh::Settings.current.deployment_management_files.each do |file|
59
- FileUtils.cp(file, destination_dir)
60
- end
61
-
62
- # Zip all processors
63
- included_processor_names.each do |processor_name|
64
-
65
- directory = File.join(source_dir, processor_name) # last slash could be omitted
66
- zipfile_name = File.join(destination_dir, "#{processor_name}.zip")
67
-
68
- # remove zip before we create a new one
69
- FileUtils.rm zipfile_name, :force => true
70
-
71
- options = {"directories-recursively" => true}
72
-
73
- Zip::File.open(zipfile_name,Zip::File::CREATE) do |zipfile|
74
-
75
- [directory].each{ |file_to_be_zipped|
76
-
77
- if File.directory?(file_to_be_zipped)
78
- # should skip directories
79
- next if options["directories-skip"]
80
-
81
- # should recursively add directory
82
- if options["directories-recursively"]
83
- directory = file_to_be_zipped
84
- puts "zipper: archiving directory: #{directory}"
85
- directory_chosen_pathname = options["directories-recursively-splat"] ? directory : File.dirname(directory)
86
- directory_pathname = Pathname.new(directory_chosen_pathname)
87
- files = Dir[File.join(directory, '**', '**')]
88
-
89
- # pattern to exclude unwanted folders
90
- re = Regexp.new("^#{directory}/(log|logs|exceptions|pids|tmp)")
91
- files.delete_if {|filename| re.match(filename) if File.directory?(filename)}
92
-
93
- files.each do |file|
94
- file_pathname = Pathname.new(file)
95
- file_relative_pathname = file_pathname.relative_path_from(directory_pathname)
96
- zipfile.add(file_relative_pathname,file)
97
- end
98
- next
99
- end
100
- end
101
-
102
- filename = File.basename(file_to_be_zipped)
103
-
104
- puts "zipper: archiving #{file_to_be_zipped} as #{filename} into #{zipfile}"
105
-
106
- zipfile.add(filename,file_to_be_zipped)
107
- }
108
- end
109
- end
110
-
111
- puts "Done packaging #{included_processor_names.size} processors"
112
- end
113
- end
1
+ desc 'Packages processors to zip files. '
2
+ arg_name '[processor_name,[other_processor_name,pattern*]]'
3
+ command :package_ruby do |c|
4
+ c.flag([:x, :exclude], :desc => "Exclude processors by name.", :type => Array, :long_desc => "You can specify multiple processors by providing a comma-separated list.")
5
+ c.flag([:d, :destination], :desc => "Destination directory to place created zip files.", :default_value => Eh::Settings.current.ruby_release_dir)
6
+ c.flag([:s, :source], :desc => "Source directory to read processors from.", :default_value => Eh::Settings.current.processors_src_dir)
7
+
8
+ c.action do |global_options, options, args|
9
+ source_dir = options['s']
10
+ destination_dir = options['d']
11
+
12
+ puts "Will package processors from #{source_dir} to #{destination_dir}"
13
+ # find all processors in the base directory
14
+ processor_names = Dir["#{source_dir}/*"].map do |dir|
15
+ File.basename(dir)
16
+ end
17
+
18
+ # Drop files, only use directories
19
+ processor_names.delete_if do |item|
20
+ !File.directory?("#{source_dir}/#{item}")
21
+ end
22
+
23
+ included_processor_names = processor_names
24
+
25
+ # if processor names are given as arguments then use them.
26
+ # can contain wildcards like "console.*" to include all processors
27
+ # starting with "console.".
28
+ if args[0]
29
+ processor_names_from_arguments = args[0].split(',').map(&:strip)
30
+
31
+ included_processor_names = included_processor_names.select do |processor_name|
32
+ processor_names_from_arguments.any? do |query|
33
+ if query.end_with?('*')
34
+ processor_name.start_with?(query.gsub('*', ''))
35
+ else
36
+ processor_name == query
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # exclude processors specified by -x option, if option is given
43
+ if options['x']
44
+ # check if any processor has been excluded from packaging
45
+ included_processor_names = included_processor_names.select do |processor_name|
46
+ !options['x'].include?(processor_name)
47
+ end
48
+ end
49
+
50
+ # make sure we have at least one processor
51
+ if included_processor_names.empty?
52
+ raise "There are no processor names. Either your -s directory is empty or you specified a strange combination of -x and -p"
53
+ end
54
+
55
+ # make sure destination directory exists
56
+ FileUtils.mkdir_p(destination_dir)
57
+
58
+ Eh::Settings.current.deployment_management_files.each do |file|
59
+ FileUtils.cp(file, destination_dir)
60
+ end
61
+
62
+ # Zip all processors
63
+ included_processor_names.each do |processor_name|
64
+
65
+ directory = File.join(source_dir, processor_name) # last slash could be omitted
66
+ zipfile_name = File.join(destination_dir, "#{processor_name}.zip")
67
+
68
+ # remove zip before we create a new one
69
+ FileUtils.rm zipfile_name, :force => true
70
+
71
+ options = {"directories-recursively" => true}
72
+
73
+ Zip::File.open(zipfile_name,Zip::File::CREATE) do |zipfile|
74
+
75
+ [directory].each{ |file_to_be_zipped|
76
+
77
+ if File.directory?(file_to_be_zipped)
78
+ # should skip directories
79
+ next if options["directories-skip"]
80
+
81
+ # should recursively add directory
82
+ if options["directories-recursively"]
83
+ directory = file_to_be_zipped
84
+ puts "zipper: archiving directory: #{directory}"
85
+ directory_chosen_pathname = options["directories-recursively-splat"] ? directory : File.dirname(directory)
86
+ directory_pathname = Pathname.new(directory_chosen_pathname)
87
+ files = Dir[File.join(directory, '**', '**')]
88
+
89
+ # pattern to exclude unwanted folders
90
+ re = Regexp.new("^#{directory}/(log|logs|exceptions|pids|tmp)")
91
+ files.delete_if {|filename| re.match(filename) if File.directory?(filename)}
92
+
93
+ files.each do |file|
94
+ file_pathname = Pathname.new(file)
95
+ file_relative_pathname = file_pathname.relative_path_from(directory_pathname)
96
+ zipfile.add(file_relative_pathname,file)
97
+ end
98
+ next
99
+ end
100
+ end
101
+
102
+ filename = File.basename(file_to_be_zipped)
103
+
104
+ puts "zipper: archiving #{file_to_be_zipped} as #{filename} into #{zipfile}"
105
+
106
+ zipfile.add(filename,file_to_be_zipped)
107
+ }
108
+ end
109
+ end
110
+
111
+ puts "Done packaging #{included_processor_names.size} processors"
112
+ end
113
+ end