Skip to content

Commit 02080bb

Browse files
committed
Merge pull request #205 from Tereci/master
Updating process.rb to enable deploying and redeploying ZIP archives and...
2 parents b659283 + 4629042 commit 02080bb

1 file changed

Lines changed: 44 additions & 25 deletions

File tree

lib/gooddata/models/process.rb

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,54 @@ def with_deploy(dir, options = {}, &block)
4242
end
4343
end
4444

45-
def upload_package(dir, files_to_exclude)
46-
Tempfile.open('deploy-graph-archive') do |temp|
47-
Zip::OutputStream.open(temp.path) do |zio|
48-
FileUtils.cd(dir) do
49-
50-
files_to_pack = Dir.glob('./**/*').reject { |f| files_to_exclude.include?(Pathname(dir) + f) }
51-
files_to_pack.each do |item|
52-
# puts "including #{item}" if verbose
53-
unless File.directory?(item)
54-
zio.put_next_entry(item)
55-
zio.print IO.read(item)
45+
def upload_package(path, files_to_exclude)
46+
if !path.directory?
47+
GoodData.upload_to_user_webdav(path)
48+
path
49+
else
50+
Tempfile.open('deploy-graph-archive') do |temp|
51+
Zip::OutputStream.open(temp.path) do |zio|
52+
FileUtils.cd(path) do
53+
54+
files_to_pack = Dir.glob('./**/*').reject { |f| files_to_exclude.include?(Pathname(path) + f) }
55+
files_to_pack.each do |item|
56+
# puts "including #{item}" if verbose
57+
unless File.directory?(item)
58+
zio.put_next_entry(item)
59+
zio.print IO.read(item)
60+
end
5661
end
5762
end
5863
end
64+
GoodData.upload_to_user_webdav(temp.path)
65+
temp.path
5966
end
60-
GoodData.upload_to_user_webdav(temp.path)
61-
temp
6267
end
6368
end
6469

65-
def deploy(dir, options = {})
66-
dir = Pathname(dir) || fail('Directory is not specified')
67-
fail "\"#{dir}\" is not a directory" unless dir.directory?
68-
files_to_exclude = options[:files_to_exclude].map { |p| Pathname(p) }
70+
# Deploy a new process or redeploy existing one.
71+
#
72+
# @param path [String] Path to ZIP archive or to a directory containing files that should be ZIPed
73+
# @option options [String] :files_to_exclude
74+
# @option options [String] :process_id ('nobody') From address
75+
# @option options [String] :type ('GRAPH') Type of process - GRAPH or RUBY
76+
# @option options [String] :name Readable name of the process
77+
# @option options [String] :process_id ID of a process to be redeployed (do not set if you want to create a new process)
78+
# @option options [Boolean] :verbose (false) Switch on verbose mode for detailed logging
79+
def deploy(path, options = {})
80+
path = Pathname(path) || fail('Path is not specified')
81+
files_to_exclude = options[:files_to_exclude].nil? ? [] : options[:files_to_exclude].map { |p| Pathname(p) }
6982
process_id = options[:process_id]
7083

7184
type = options[:type] || 'GRAPH'
7285
deploy_name = options[:name]
7386
verbose = options[:verbose] || false
74-
puts HighLine.color("Deploying #{dir}", HighLine::BOLD) if verbose
75-
deployed_path = Process.upload_package(dir, files_to_exclude)
87+
puts HighLine.color("Deploying #{path}", HighLine::BOLD) if verbose
88+
deployed_path = Process.upload_package(path, files_to_exclude)
7689
data = {
7790
:process => {
7891
:name => deploy_name,
79-
:path => "/uploads/#{File.basename(deployed_path.path)}",
92+
:path => "/uploads/#{File.basename(deployed_path)}",
8093
:type => type
8194
}
8295
}
@@ -86,7 +99,7 @@ def deploy(dir, options = {})
8699
GoodData.put("/gdc/projects/#{GoodData.project.pid}/dataload/processes/#{process_id}", data)
87100
end
88101
process = Process.new(res)
89-
puts HighLine.color("Deploy DONE #{dir}", HighLine::GREEN) if verbose
102+
puts HighLine.color("Deploy DONE #{path}", HighLine::GREEN) if verbose
90103
process
91104
end
92105
end
@@ -99,10 +112,16 @@ def delete
99112
GoodData.delete(uri)
100113
end
101114

102-
def deploy(dir, options = {})
103-
process = Process.upload(dir, options.merge(:process_id => process_id))
104-
puts HighLine.color("Deploy DONE #{dir}", HighLine::GREEN) if verbose
105-
process
115+
# Redeploy existing process.
116+
#
117+
# @param path [String] Path to ZIP archive or to a directory containing files that should be ZIPed
118+
# @option options [String] :files_to_exclude
119+
# @option options [String] :process_id ('nobody') From address
120+
# @option options [String] :type ('GRAPH') Type of process - GRAPH or RUBY
121+
# @option options [String] :name Readable name of the process
122+
# @option options [Boolean] :verbose (false) Switch on verbose mode for detailed logging
123+
def deploy(path, options = {})
124+
Process.deploy(path, options.merge(:process_id => process_id))
106125
end
107126

108127
def process

0 commit comments

Comments
 (0)