lib/gooddata/models/process.rb in gooddata-0.6.25 vs lib/gooddata/models/process.rb in gooddata-0.6.26
- old
+ new
@@ -4,17 +4,20 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
require 'pry'
require 'zip'
+require 'uri'
require_relative '../helpers/global_helpers'
require_relative '../rest/resource'
require_relative 'execution_detail'
require_relative 'schedule'
+APP_STORE_URL ||= 'https://github.com/gooddata/app_store'
+
module GoodData
class Process < Rest::Resource
attr_reader :data
alias_method :raw_data, :data
@@ -89,10 +92,12 @@
# @option options [String] :process_id ID of a process to be redeployed (do not set if you want to create a new process)
# @option options [Boolean] :verbose (false) Switch on verbose mode for detailed logging
def deploy(path, options = { :client => GoodData.client, :project => GoodData.project })
client, project = GoodData.get_client_and_project(options)
+ return deploy_brick(path, options) if path.to_s.start_with?(APP_STORE_URL)
+
path = Pathname(path) || fail('Path is not specified')
files_to_exclude = options[:files_to_exclude].nil? ? [] : options[:files_to_exclude].map { |pname| Pathname(pname) }
process_id = options[:process_id]
type = options[:type] || 'GRAPH'
@@ -120,10 +125,48 @@
process = client.create(Process, res, project: project)
puts HighLine.color("Deploy DONE #{path}", HighLine::GREEN) if verbose
process
end
+ def deploy_brick(path, options = { :client => GoodData.client, :project => GoodData.project })
+ client, project = GoodData.get_client_and_project(options)
+
+ brick_uri_parts = URI(path).path.split('/')
+ ref = brick_uri_parts[4]
+ brick_name = brick_uri_parts.last
+ brick_path = brick_uri_parts[5..-1].join('/')
+
+ Dir.mktmpdir do |dir|
+ Dir.chdir(dir) do
+ `git clone #{APP_STORE_URL}`
+ end
+
+ Dir.chdir(File.join(dir, 'app_store')) do
+ if ref
+ `git checkout #{ref}`
+
+ fail 'Wrong branch or tag specified!' if $CHILD_STATUS.to_i != 0
+ end
+
+ opts = {
+ :client => client,
+ :project => project,
+ :name => brick_name,
+ :type => 'RUBY'
+ }
+
+ full_brick_path = File.join(dir, 'app_store', brick_path)
+
+ unless File.exist?(full_brick_path)
+ fail "Invalid brick name specified - '#{brick_name}'"
+ end
+
+ return deploy(full_brick_path, opts)
+ end
+ end
+ end
+
# ----------------------------- Private Stuff
private
def with_zip(opts = {})
@@ -143,13 +186,16 @@
puts 'Creating package for upload'
if !path.directory? && (path.extname == '.grf' || path.extname == '.rb')
with_zip(opts) do |zipfile|
zipfile.add(File.basename(path), path)
end
-
elsif !path.directory?
- client.upload_to_user_webdav(path, opts)
- path
+ # this branch expects a zipped file. Since the filename on webdav is by default
+ # equal to the filename of a local file. I happened often that the name clashed
+ # if ran in parallel. Create a randomized name to mitigate that
+ randomized_filename = (0...16).map { (65 + rand(26)).chr }.join
+ client.upload_to_user_webdav(path, { filename: randomized_filename }.merge(opts))
+ randomized_filename
else
with_zip(opts) do |zipfile|
files_to_upload = Dir[File.join(path, '**', '**')].reject { |f| files_to_exclude.include?(Pathname(path) + f) }
puts "Uploading #{files_to_upload.count} files."
files_to_upload.each do |file|