eventhub-command 0.4.1 → 0.5.0
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.
- checksums.yaml +4 -4
- data/lib/eh/commands/generate.rb +91 -0
- data/lib/eh/commands/package.rb +37 -0
- data/lib/eh/version.rb +1 -1
- data/lib/eh-commands.rb +2 -3
- data/lib/eh.rb +12 -11
- data/lib/packager/rails.rb +60 -0
- data/lib/packager/ruby.rb +137 -0
- data/lib/packager.rb +4 -0
- metadata +6 -4
- data/lib/eh/commands/generate_processor.rb +0 -90
- data/lib/eh/commands/package_rails.rb +0 -23
- data/lib/eh/commands/package_ruby.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24eedb865c6d138112f24cc2ddde9eeb2d2c3169
|
4
|
+
data.tar.gz: 035a36ace907437d1b7c608f55c0f6360e73293d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9e38cacb2d1eaee3855a9256af3aceac25515e547f2f16f27454f5d36e8016228a7d639c232fccb5e1748599eb9735973799c98116fdfdbfc8dbfa686158972
|
7
|
+
data.tar.gz: 14d58405c1e74c1643ae24cefedb38cb5f78705cfaff319309b27c4a80e6b60d270a73ead3e0266cf882916ad9271bdf8eadf632e4cf950c668489eb9a78843a
|
@@ -0,0 +1,91 @@
|
|
1
|
+
desc 'Generates a template for a processor'
|
2
|
+
arg_name 'module_name processor_name'
|
3
|
+
command :generate do |c|
|
4
|
+
c.command :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
|
91
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
desc 'package commands'
|
2
|
+
command :package do |c|
|
3
|
+
c.flag([:s, :source], :desc => "Source directory to read processors from.")
|
4
|
+
c.flag([:d, :destination], :desc => "Destination directory to place created zip files.")
|
5
|
+
|
6
|
+
c.desc 'Packages processors to zip files. '
|
7
|
+
c.arg_name '[processor_name,[other_processor_name,pattern*]]'
|
8
|
+
c.command :ruby do |c|
|
9
|
+
c.flag([:i, :include], :desc => "Include processors by name format: [processor_name,[other_processor_name,pattern*]]", :type => String, :long_desc => "You can specify multiple processors by providing a comma-separated list as well as pattern using '*'")
|
10
|
+
c.flag([:x, :exclude], :desc => "Exclude processors by name format: [processor_name,[other_processor_name,pattern*]]", :type => String, :long_desc => "You can specify multiple processors by providing a comma-separated list as well as pattern using '*'")
|
11
|
+
|
12
|
+
c.action do |global_options, options, args|
|
13
|
+
options['s'] ||= Eh::Settings.current.processors_src_dir
|
14
|
+
options['d'] ||= Eh::Settings.current.ruby_release_dir
|
15
|
+
source_dir = options.fetch('s')
|
16
|
+
destination_dir = options.fetch('d')
|
17
|
+
include_pattern = options['i'] || args[0]
|
18
|
+
exclude_pattern = options['x']
|
19
|
+
packager = Packager::Ruby.new(source_dir, destination_dir, include_pattern, exclude_pattern)
|
20
|
+
packager.package
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
c.command :rails do |c|
|
26
|
+
c.action do |global_options, options, args|
|
27
|
+
options['s'] ||= Eh::Settings.current.rails_src_dir
|
28
|
+
options['d'] ||= Eh::Settings.current.rails_release_dir
|
29
|
+
source_dir = options.fetch('s')
|
30
|
+
destination_dir = options.fetch('d')
|
31
|
+
|
32
|
+
packager = Packager::Rails.new(source_dir, destination_dir)
|
33
|
+
packager.package
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/eh/version.rb
CHANGED
data/lib/eh-commands.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# All commands are required here
|
2
2
|
if Eh::Settings.current.repository
|
3
|
-
require 'eh/commands/
|
4
|
-
require 'eh/commands/package_ruby'
|
5
|
-
require 'eh/commands/package_rails'
|
3
|
+
require 'eh/commands/generate'
|
6
4
|
require 'eh/commands/stage'
|
7
5
|
require 'eh/commands/dump'
|
8
6
|
require 'eh/commands/db'
|
9
7
|
require 'eh/commands/proxy'
|
10
8
|
require 'eh/commands/deploy'
|
9
|
+
require 'eh/commands/package'
|
11
10
|
require 'eh/proxy/proxy'
|
12
11
|
else
|
13
12
|
# remove unused settings for this version
|
data/lib/eh.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
module Eh
|
2
|
-
end
|
3
|
-
|
4
|
-
require 'zip'
|
5
|
-
require 'pathname'
|
6
|
-
|
7
|
-
require 'eh/version'
|
8
|
-
require 'eh/settings'
|
9
|
-
require 'yaml'
|
10
|
-
|
11
|
-
require_relative 'deployer'
|
1
|
+
module Eh
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'zip'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
require 'eh/version'
|
8
|
+
require 'eh/settings'
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
require_relative 'deployer'
|
12
|
+
require_relative 'packager'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Packager::Rails
|
2
|
+
def initialize(source_dir, destination_dir)
|
3
|
+
@source_dir = source_dir
|
4
|
+
@destination_dir = destination_dir
|
5
|
+
end
|
6
|
+
|
7
|
+
def package
|
8
|
+
|
9
|
+
app_directories.each do |dir|
|
10
|
+
included = files_and_dirs.map do |s|
|
11
|
+
File.join(app_name(dir), s)
|
12
|
+
end.join(' ')
|
13
|
+
remove_destination_file(dir)
|
14
|
+
cmd = "cd #{File.join(dir, '..')} && zip -r #{destination_file_name(dir)} #{included} >> /dev/null"
|
15
|
+
ret = system cmd
|
16
|
+
puts "Packaged: #{app_name(dir).blue} to #{destination_file_name(dir)}: #{ret ? 'OK'.green : 'ERROR'.red}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :source_dir, :destination_dir
|
23
|
+
|
24
|
+
def app_directories
|
25
|
+
Dir.glob(source_dir)
|
26
|
+
end
|
27
|
+
|
28
|
+
def app_name(dir)
|
29
|
+
File.basename(dir)
|
30
|
+
end
|
31
|
+
|
32
|
+
def destination_file_name(dir)
|
33
|
+
app_name = app_name(dir)
|
34
|
+
File.join(destination_dir, "#{app_name}.zip")
|
35
|
+
end
|
36
|
+
|
37
|
+
def files_and_dirs
|
38
|
+
%w{Capfile Gemfile Gemfile.lock README.rdoc Rakefile app bin db lib public spec vendor}
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_destination_file(dir)
|
42
|
+
FileUtils.rm destination_file_name(dir), force: true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# files_and_dirs =
|
48
|
+
# source = options[:source]
|
49
|
+
#
|
50
|
+
# dirs = Dir.glob("#{source}")
|
51
|
+
# dirs.each do |dir|
|
52
|
+
# app = File.basename(dir)
|
53
|
+
# destination = File.join(options[:d], "#{app}.zip")
|
54
|
+
# included = files_and_dirs.map do |s|
|
55
|
+
# File.join(app, s)
|
56
|
+
# end.join(' ')
|
57
|
+
# cmd = "cd #{File.join(dir, '..')} && zip -r #{destination} #{included}"
|
58
|
+
# ret = system cmd
|
59
|
+
# puts "Packaged #{app}: #{ret}"
|
60
|
+
# end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
class Packager::Ruby
|
2
|
+
def initialize(source_dir, destination_dir, include_pattern_string, exclude_pattern_string)
|
3
|
+
@source_dir = Pathname.new(source_dir)
|
4
|
+
@destination_dir = Pathname.new(destination_dir)
|
5
|
+
@include_pattern_string = include_pattern_string
|
6
|
+
@exclude_pattern_string = exclude_pattern_string
|
7
|
+
end
|
8
|
+
|
9
|
+
def package
|
10
|
+
assert_at_least_one_processor!
|
11
|
+
create_destination_dir
|
12
|
+
copy_deployment_management_files
|
13
|
+
package_processors
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :source_dir, :destination_dir, :include_pattern_string, :exclude_pattern_string
|
19
|
+
|
20
|
+
def package_processors
|
21
|
+
puts "Start packaging"
|
22
|
+
processor_names.each do |processor_name|
|
23
|
+
package_processor(processor_name)
|
24
|
+
end
|
25
|
+
puts "Done packaging #{processor_names.size} processors"
|
26
|
+
end
|
27
|
+
|
28
|
+
def package_processor(processor_name)
|
29
|
+
print "Package: #{processor_name.light_blue} "
|
30
|
+
remove_destination_file(processor_name)
|
31
|
+
|
32
|
+
Zip::File.open(destination_file_name(processor_name), Zip::File::CREATE) do |zipfile|
|
33
|
+
files = files_to_zip(processor_name)
|
34
|
+
files.each do |file|
|
35
|
+
relative_filename = file.relative_path_from(source_dir)
|
36
|
+
zipfile.add(relative_filename, file)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
puts " done".green
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def files_to_zip(processor_name)
|
44
|
+
exclude_directories = %w{logs/ log/ exceptions/ pids/ tmp/}
|
45
|
+
files = Dir.glob(File.join(processor_source_dir(processor_name), '**', '*')).select do |name|
|
46
|
+
exclude_directories.none? do |exclude|
|
47
|
+
prefix = File.join(processor_source_dir(processor_name), exclude)
|
48
|
+
name.start_with?(prefix)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
files.map do |file|
|
52
|
+
Pathname.new(file)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def processor_source_dir(processor_name)
|
57
|
+
File.join(source_dir, processor_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_destination_dir
|
61
|
+
FileUtils.mkdir_p(destination_dir)
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_destination_file(processor_name)
|
65
|
+
FileUtils.rm destination_file_name(processor_name), force: true
|
66
|
+
end
|
67
|
+
|
68
|
+
def destination_file_name(processor_name)
|
69
|
+
File.join(destination_dir, "#{processor_name}.zip")
|
70
|
+
end
|
71
|
+
|
72
|
+
def copy_deployment_management_files
|
73
|
+
Eh::Settings.current.deployment_management_files.each do |file|
|
74
|
+
FileUtils.cp(file, destination_dir)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def assert_at_least_one_processor!
|
79
|
+
if processor_names.empty?
|
80
|
+
raise "There are no processor names. Either your -s directory is empty or you specified a strange combination of include and exclude pattern."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def processor_names
|
85
|
+
included_names = existing_processor_names
|
86
|
+
included_names = included_processor_names(included_names)
|
87
|
+
excluded_names = excluded_processor_names(included_names)
|
88
|
+
included_names - excluded_names
|
89
|
+
end
|
90
|
+
|
91
|
+
def existing_processor_names
|
92
|
+
Dir["#{source_dir}/*"].map do |dir|
|
93
|
+
File.basename(dir)
|
94
|
+
end.delete_if do |item|
|
95
|
+
!File.directory?("#{source_dir}/#{item}")
|
96
|
+
end.sort
|
97
|
+
end
|
98
|
+
|
99
|
+
def included_processor_names(names)
|
100
|
+
# if processor names are given as arguments then use them.
|
101
|
+
# can contain wildcards like "console.*" to include all processors
|
102
|
+
# starting with "console.".
|
103
|
+
names.select do |name|
|
104
|
+
include_patterns.empty? || include_patterns.any? do |pattern|
|
105
|
+
wildcard_pattern_match?(pattern, name) || pattern_match?(pattern, name)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def excluded_processor_names(names)
|
111
|
+
names.select do |name|
|
112
|
+
exclude_patterns.any? && exclude_patterns.any? do |pattern|
|
113
|
+
wildcard_pattern_match?(pattern, name) || pattern_match?(pattern, name)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def include_patterns
|
119
|
+
(include_pattern_string || '').split(',').map { |part| part.strip }
|
120
|
+
end
|
121
|
+
|
122
|
+
def exclude_patterns
|
123
|
+
(exclude_pattern_string || '').split(',').map { |part| part.strip }
|
124
|
+
end
|
125
|
+
|
126
|
+
def wildcard_pattern?(pattern)
|
127
|
+
pattern.end_with?('*')
|
128
|
+
end
|
129
|
+
|
130
|
+
def wildcard_pattern_match?(pattern, name)
|
131
|
+
wildcard_pattern?(pattern) && name.start_with?(pattern.gsub('*', ''))
|
132
|
+
end
|
133
|
+
|
134
|
+
def pattern_match?(pattern, name)
|
135
|
+
pattern == name
|
136
|
+
end
|
137
|
+
end
|
data/lib/packager.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventhub-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal Betz
|
@@ -184,9 +184,8 @@ files:
|
|
184
184
|
- lib/eh/commands/db.rb
|
185
185
|
- lib/eh/commands/deploy.rb
|
186
186
|
- lib/eh/commands/dump.rb
|
187
|
-
- lib/eh/commands/
|
188
|
-
- lib/eh/commands/
|
189
|
-
- lib/eh/commands/package_ruby.rb
|
187
|
+
- lib/eh/commands/generate.rb
|
188
|
+
- lib/eh/commands/package.rb
|
190
189
|
- lib/eh/commands/proxy.rb
|
191
190
|
- lib/eh/commands/repository.rb
|
192
191
|
- lib/eh/commands/stage.rb
|
@@ -196,6 +195,9 @@ files:
|
|
196
195
|
- lib/eh/proxy/settings/svn.rb
|
197
196
|
- lib/eh/settings.rb
|
198
197
|
- lib/eh/version.rb
|
198
|
+
- lib/packager.rb
|
199
|
+
- lib/packager/rails.rb
|
200
|
+
- lib/packager/ruby.rb
|
199
201
|
- test/default_test.rb
|
200
202
|
- test/test_helper.rb
|
201
203
|
- todo.txt
|
@@ -1,90 +0,0 @@
|
|
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,23 +0,0 @@
|
|
1
|
-
desc 'Packages processors to zip files'
|
2
|
-
command :package_rails do |c|
|
3
|
-
c.flag([:d, :destination], :desc => "Destination directory to place created zip files.", :default_value => Eh::Settings.current.rails_release_dir)
|
4
|
-
c.flag([:s, :source], :desc => "Source directory to read rails apps from.", :default_value => Eh::Settings.current.rails_src_dir)
|
5
|
-
|
6
|
-
c.action do |global_options, options, args|
|
7
|
-
files_and_dirs = %w{Capfile Gemfile Gemfile.lock README.rdoc Rakefile app bin db lib public spec vendor}
|
8
|
-
source = options[:source]
|
9
|
-
|
10
|
-
dirs = Dir.glob("#{source}")
|
11
|
-
dirs.each do |dir|
|
12
|
-
app = File.basename(dir)
|
13
|
-
destination = File.join(options[:d], "#{app}.zip")
|
14
|
-
included = files_and_dirs.map do |s|
|
15
|
-
File.join(app, s)
|
16
|
-
end.join(' ')
|
17
|
-
cmd = "cd #{File.join(dir, '..')} && zip -r #{destination} #{included}"
|
18
|
-
ret = system cmd
|
19
|
-
puts "Packaged #{app}: #{ret}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,113 +0,0 @@
|
|
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
|