corl 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/Gemfile +5 -10
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +1 -1
  4. data/Rakefile +3 -3
  5. data/VERSION +1 -1
  6. data/bin/corl +2 -54
  7. data/bootstrap/bootstrap.sh +91 -0
  8. data/bootstrap/lib/shell/LICENSE.txt +674 -0
  9. data/bootstrap/lib/shell/command.sh +214 -0
  10. data/bootstrap/lib/shell/filesystem.sh +139 -0
  11. data/bootstrap/lib/shell/load.sh +73 -0
  12. data/bootstrap/lib/shell/os.sh +67 -0
  13. data/bootstrap/lib/shell/script.sh +160 -0
  14. data/bootstrap/lib/shell/starter.sh +64 -0
  15. data/bootstrap/lib/shell/validators.sh +50 -0
  16. data/bootstrap/os/ubuntu/00_base.sh +5 -0
  17. data/bootstrap/os/ubuntu/01_git.sh +5 -0
  18. data/bootstrap/os/ubuntu/05_ruby.sh +7 -0
  19. data/bootstrap/os/ubuntu/06_puppet.sh +38 -0
  20. data/bootstrap/os/ubuntu/10_corl.sh +9 -0
  21. data/corl.gemspec +61 -124
  22. data/lib/{corl → CORL}/action/bootstrap.rb +13 -7
  23. data/lib/CORL/action/exec.rb +39 -0
  24. data/lib/CORL/action/image.rb +31 -0
  25. data/lib/{corl → CORL}/action/images.rb +1 -1
  26. data/lib/CORL/action/lookup.rb +34 -0
  27. data/lib/{corl → CORL}/action/machines.rb +1 -1
  28. data/lib/CORL/action/provision.rb +31 -0
  29. data/lib/{corl → CORL}/action/seed.rb +3 -3
  30. data/lib/{corl → CORL}/action/spawn.rb +2 -2
  31. data/lib/CORL/action/start.rb +31 -0
  32. data/lib/CORL/action/stop.rb +31 -0
  33. data/lib/{corl → CORL}/configuration/file.rb +1 -1
  34. data/lib/{corl → CORL}/event/puppet.rb +1 -1
  35. data/lib/{corl → CORL}/extension/puppetloader.rb +1 -1
  36. data/lib/{corl → CORL}/machine/fog.rb +3 -3
  37. data/lib/{corl → CORL}/machine/physical.rb +2 -2
  38. data/lib/{corl → CORL}/network/default.rb +1 -1
  39. data/lib/{corl → CORL}/node/aws.rb +0 -4
  40. data/lib/{corl → CORL}/node/google.rb +0 -4
  41. data/lib/{corl → CORL}/node/local.rb +1 -1
  42. data/lib/{corl → CORL}/node/rackspace.rb +0 -4
  43. data/lib/{corl → CORL}/provisioner/puppetnode.rb +1 -14
  44. data/lib/{corl → CORL}/provisioner/puppetnode/resource.rb +0 -0
  45. data/lib/{corl → CORL}/provisioner/puppetnode/resource_group.rb +0 -0
  46. data/lib/{corl → CORL}/template/environment.rb +1 -1
  47. data/lib/core/facade.rb +49 -0
  48. data/lib/{corl_core → core}/mixin/action/keypair.rb +10 -10
  49. data/lib/{corl_core → core}/mixin/lookup.rb +0 -0
  50. data/lib/{corl_core → core}/mod/hiera_backend.rb +0 -0
  51. data/lib/{corl_core/mixin/action/node.rb → core/plugin/action.rb} +66 -33
  52. data/lib/{corl_core → core}/plugin/configuration.rb +2 -2
  53. data/lib/{corl/node → core/plugin}/fog.rb +5 -1
  54. data/lib/{corl_core → core}/plugin/machine.rb +2 -2
  55. data/lib/{corl_core → core}/plugin/network.rb +4 -4
  56. data/lib/{corl_core → core}/plugin/node.rb +11 -9
  57. data/lib/{corl_core → core}/plugin/provisioner.rb +2 -2
  58. data/lib/{corl_core → core}/util/ssh.rb +1 -1
  59. data/lib/corl.rb +53 -112
  60. data/lib/puppet/parser/functions/ensure.rb +0 -4
  61. data/locales/en.yml +55 -148
  62. metadata +84 -222
  63. data/lib/corl/action/add.rb +0 -69
  64. data/lib/corl/action/clone.rb +0 -40
  65. data/lib/corl/action/create.rb +0 -55
  66. data/lib/corl/action/exec.rb +0 -41
  67. data/lib/corl/action/extract.rb +0 -49
  68. data/lib/corl/action/image.rb +0 -30
  69. data/lib/corl/action/lookup.rb +0 -35
  70. data/lib/corl/action/provision.rb +0 -37
  71. data/lib/corl/action/remove.rb +0 -51
  72. data/lib/corl/action/save.rb +0 -53
  73. data/lib/corl/action/start.rb +0 -37
  74. data/lib/corl/action/stop.rb +0 -30
  75. data/lib/corl/action/update.rb +0 -37
  76. data/lib/corl/command/shell.rb +0 -164
  77. data/lib/corl/event/regex.rb +0 -52
  78. data/lib/corl/project/git.rb +0 -465
  79. data/lib/corl/project/github.rb +0 -108
  80. data/lib/corl/template/json.rb +0 -16
  81. data/lib/corl/template/wrapper.rb +0 -16
  82. data/lib/corl/template/yaml.rb +0 -16
  83. data/lib/corl/translator/json.rb +0 -27
  84. data/lib/corl/translator/yaml.rb +0 -27
  85. data/lib/corl_core/codes.rb +0 -107
  86. data/lib/corl_core/config.rb +0 -337
  87. data/lib/corl_core/config/collection.rb +0 -57
  88. data/lib/corl_core/config/options.rb +0 -70
  89. data/lib/corl_core/core.rb +0 -59
  90. data/lib/corl_core/corl.rb +0 -254
  91. data/lib/corl_core/errors.rb +0 -84
  92. data/lib/corl_core/facade.rb +0 -126
  93. data/lib/corl_core/gems.rb +0 -72
  94. data/lib/corl_core/manager.rb +0 -425
  95. data/lib/corl_core/mixin/action/commit.rb +0 -58
  96. data/lib/corl_core/mixin/action/project.rb +0 -53
  97. data/lib/corl_core/mixin/action/push.rb +0 -52
  98. data/lib/corl_core/mixin/config/collection.rb +0 -53
  99. data/lib/corl_core/mixin/config/ops.rb +0 -53
  100. data/lib/corl_core/mixin/config/options.rb +0 -39
  101. data/lib/corl_core/mixin/macro/object_interface.rb +0 -361
  102. data/lib/corl_core/mixin/macro/plugin_interface.rb +0 -380
  103. data/lib/corl_core/mixin/settings.rb +0 -46
  104. data/lib/corl_core/mixin/sub_config.rb +0 -148
  105. data/lib/corl_core/mod/hash.rb +0 -29
  106. data/lib/corl_core/plugin/action.rb +0 -381
  107. data/lib/corl_core/plugin/base.rb +0 -374
  108. data/lib/corl_core/plugin/command.rb +0 -98
  109. data/lib/corl_core/plugin/event.rb +0 -53
  110. data/lib/corl_core/plugin/extension.rb +0 -12
  111. data/lib/corl_core/plugin/project.rb +0 -927
  112. data/lib/corl_core/plugin/template.rb +0 -80
  113. data/lib/corl_core/plugin/translator.rb +0 -38
  114. data/lib/corl_core/util/cli.rb +0 -352
  115. data/lib/corl_core/util/data.rb +0 -404
  116. data/lib/corl_core/util/disk.rb +0 -114
  117. data/lib/corl_core/util/git.rb +0 -47
  118. data/lib/corl_core/util/interface.rb +0 -319
  119. data/lib/corl_core/util/liquid.rb +0 -17
  120. data/lib/corl_core/util/package.rb +0 -93
  121. data/lib/corl_core/util/shell.rb +0 -239
  122. data/spec/corl_core/interface_spec.rb +0 -489
@@ -1,37 +0,0 @@
1
-
2
- module CORL
3
- module Action
4
- class Update < Plugin::Action
5
-
6
- include Mixin::Action::Project
7
-
8
- #-----------------------------------------------------------------------------
9
- # Update action interface
10
-
11
- def normalize
12
- super('corl update')
13
-
14
- codes :project_failure => 20
15
- end
16
-
17
- #-----------------------------------------------------------------------------
18
- # Action operations
19
-
20
- def parse(parser)
21
- project_options(parser, true, true)
22
- end
23
-
24
- #---
25
-
26
- def execute
27
- super do |node, network, status|
28
- info('corl.core.actions.update.start')
29
-
30
- project = project_load(Dir.pwd, true)
31
- status = code.project_failure unless project
32
- status
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,164 +0,0 @@
1
-
2
- module CORL
3
- module Command
4
- class Shell < Plugin::Command
5
-
6
- #-----------------------------------------------------------------------------
7
- # Command plugin interface
8
-
9
- def normalize
10
- super
11
- command = executable(self)
12
-
13
- logger.info("Setting command executable to #{command}")
14
- set(:command, command)
15
- end
16
-
17
- #-----------------------------------------------------------------------------
18
- # Command operations
19
-
20
- def build(components = {}, overrides = nil, override_key = false)
21
- command = string(components[:command])
22
- flags = array( components.has_key?(:flags) ? components[:flags] : [] )
23
- data = string_map(hash( components.has_key?(:data) ? components[:data] : {} ))
24
- args = array( components.has_key?(:args) ? components[:args] : [] )
25
- subcommand = hash( components.has_key?(:subcommand) ? components[:subcommand] : {} )
26
-
27
- override_key = command unless override_key
28
- override_key = override_key.to_sym
29
-
30
- command_string = command.dup
31
- subcommand_string = ''
32
-
33
- escape_characters = /[\'\"]+/
34
- escape_replacement = '\"'
35
-
36
- dash_pattern = /^([\-]+)/
37
- assignment_pattern = /\=$/
38
-
39
- logger.info("Building command #{command}")
40
- logger.debug("Command flags: #{flags.inspect}")
41
- logger.debug("Command options: #{data.inspect}")
42
- logger.debug("Command arguments: #{args.inspect}")
43
- logger.debug("Command has sub command") unless subcommand.empty?
44
-
45
- logger.debug("Overrides: #{overrides.inspect}")
46
- logger.debug("Override key: #{override_key}")
47
-
48
- # Flags
49
- if overrides && overrides.has_key?(:flags)
50
- if overrides[:flags].is_a?(Hash)
51
- if overrides[:flags].has_key?(override_key)
52
- flags = array(overrides[:flags][override_key])
53
- end
54
- else
55
- flags = array(overrides[:flags])
56
- end
57
- end
58
- flags.each do |flag|
59
- flag = string(flag)
60
- if ! flag.empty?
61
- if flag.match(dash_pattern)
62
- dashes = $1
63
- else
64
- dashes = ( flag.size == 1 ? '-' : '--' )
65
- end
66
- command_string << " #{dashes}#{flag}"
67
- end
68
- end
69
-
70
- # Data
71
- if overrides && overrides.has_key?(:data)
72
- if overrides[:data].has_key?(override_key)
73
- data = hash(overrides[:data][override_key])
74
- else
75
- override = true
76
- overrides[:data].each do |key, value|
77
- if ! value.is_a?(String)
78
- override = false
79
- end
80
- end
81
- data = hash(overrides[:data]) if override
82
- end
83
- end
84
- data.each do |key, value|
85
- key = string(key)
86
- value = string(value).strip.sub(escape_characters, escape_replacement)
87
-
88
- if key.match(dash_pattern)
89
- dashes = $1
90
- else
91
- dashes = ( key.size == 1 ? '-' : '--' )
92
- end
93
- space = ( key.match(assignment_pattern) ? '' : ' ' )
94
-
95
- command_string << " #{dashes}#{key}#{space}\"#{value}\""
96
- end
97
-
98
- # Arguments
99
- if overrides && overrides.has_key?(:args)
100
- unless overrides[:args].empty?
101
- if overrides[:args].is_a?(Hash)
102
- if overrides[:args].has_key?(override_key)
103
- args = array(overrides[:args][override_key])
104
- end
105
- else
106
- args = array(overrides[:args])
107
- end
108
- end
109
- end
110
- args.each do |arg|
111
- arg = string(arg).sub(escape_characters, escape_replacement)
112
-
113
- unless arg.empty?
114
- command_string << " \"#{arg}\""
115
- end
116
- end
117
-
118
- # Subcommand
119
- subcommand_overrides = ( overrides ? overrides[:subcommand] : nil )
120
- if subcommand && subcommand.is_a?(Hash) && ! subcommand.empty?
121
- subcommand_string = build(subcommand, subcommand_overrides)
122
- end
123
-
124
- command_string = (command_string + ' ' + subcommand_string).strip
125
-
126
- logger.debug("Rendered command: #{command_string}")
127
- return command_string
128
- end
129
-
130
- #---
131
-
132
- def exec(options = {}, overrides = nil)
133
- config = Config.ensure(options)
134
-
135
- logger.info("Executing command #{command}")
136
-
137
- config[:ui] = @ui
138
- result = Util::Shell.connection.exec(build(export, overrides), config) do |op, command, data|
139
- block_given? ? yield(op, command, data) : true
140
- end
141
-
142
- logger.warn("Command #{command} failed to execute") unless result.status == CORL.code.success
143
- return result
144
- end
145
-
146
- #-----------------------------------------------------------------------------
147
- # Utilities
148
-
149
- def executable(options)
150
- config = Config.ensure(options)
151
-
152
- if config.get(:corl, false)
153
- return 'corl ' + config[:corl]
154
-
155
- elsif config.get(:vagrant, false)
156
- return 'vagrant ' + config[:vagrant]
157
-
158
- elsif config.get(:command, false)
159
- return config[:command]
160
- end
161
- end
162
- end
163
- end
164
- end
@@ -1,52 +0,0 @@
1
-
2
- module CORL
3
- module Event
4
- class Regex < Plugin::Event
5
-
6
- #-----------------------------------------------------------------------------
7
- # Regular expression event interface
8
-
9
- def normalize
10
- super
11
-
12
- if get(:string)
13
- myself.pattern = delete(:string)
14
- end
15
- end
16
-
17
- #-----------------------------------------------------------------------------
18
- # Property accessors / modifiers
19
-
20
- def pattern(default = '')
21
- return get(:pattern, default)
22
- end
23
-
24
- #---
25
-
26
- def pattern=pattern
27
- set(:pattern, string(pattern))
28
- end
29
-
30
- #-----------------------------------------------------------------------------
31
- # Operations
32
-
33
- def render
34
- return "#{name}:#{pattern}"
35
- end
36
-
37
- #---
38
-
39
- def check(source)
40
- if pattern.empty?
41
- logger.warn("Can not check regex pattern because it is empty")
42
- else
43
- success = source.match(/#{pattern}/)
44
-
45
- logger.debug("Checking regex event with pattern #{pattern}: #{success.inspect}")
46
- return success
47
- end
48
- return true
49
- end
50
- end
51
- end
52
- end
@@ -1,465 +0,0 @@
1
-
2
- module CORL
3
- module Project
4
- class Git < Plugin::Project
5
-
6
- #-----------------------------------------------------------------------------
7
- # Project plugin interface
8
-
9
- def normalize
10
- super
11
- end
12
-
13
- #-----------------------------------------------------------------------------
14
- # Git interface (local)
15
-
16
- def ensure_git(reset = false)
17
- if reset || @git_lib.nil?
18
- @git_lib = nil
19
-
20
- if directory.empty?
21
- logger.warn("Can not manage Git project at #{directory} as it does not exist")
22
- else
23
- logger.debug("Ensuring Git instance to manage #{directory}")
24
- @git_lib = Util::Git.new(directory)
25
-
26
- if ! @git_lib.nil? && get(:create, false)
27
- unless File.directory?(directory) && @git_lib.git.exist?
28
- FileUtils.mkdir_p(directory) unless File.directory?(directory)
29
- @git_lib.git.init({ :bare => false })
30
- end
31
- end
32
- end
33
- end
34
- return myself
35
- end
36
- protected :ensure_git
37
-
38
- #-----------------------------------------------------------------------------
39
- # Checks
40
-
41
- def can_persist?
42
- ensure_git
43
- return true unless @git_lib.nil?
44
- return false
45
- end
46
-
47
- #---
48
-
49
- def top?(path)
50
- git_dir = File.join(path, '.git')
51
- if File.exist?(git_dir)
52
- return true if File.directory?(git_dir)
53
- elsif File.exist?(path) && (path =~ /\.git$/ && File.exist?(File.join(path, 'HEAD')))
54
- return true
55
- end
56
- return false
57
- end
58
-
59
- #---
60
-
61
- def subproject?(path)
62
- git_dir = File.join(path, '.git')
63
- if File.exist?(git_dir)
64
- unless File.directory?(git_dir)
65
- git_dir = Util::Disk.read(git_dir)
66
- unless git_dir.nil?
67
- git_dir = git_dir.gsub(/^gitdir\:\s*/, '').strip
68
- return true if File.directory?(git_dir)
69
- end
70
- end
71
- end
72
- return false
73
- end
74
-
75
- #---
76
-
77
- def project_directory?(path, require_top_level = false)
78
- path = File.expand_path(path)
79
- git_dir = File.join(path, '.git')
80
-
81
- if File.exist?(git_dir)
82
- if File.directory?(git_dir)
83
- return true
84
- elsif ! require_top_level
85
- git_dir = Util::Disk.read(git_dir)
86
- unless git_dir.nil?
87
- git_dir = git_dir.gsub(/^gitdir\:\s*/, '').strip
88
- return true if File.directory?(git_dir)
89
- end
90
- end
91
- elsif File.exist?(path) && (path =~ /\.git$/ && File.exist?(File.join(path, 'HEAD')))
92
- return true
93
- end
94
- return false
95
- end
96
-
97
- #---
98
-
99
- def new?(reset = false)
100
- if get(:new, nil).nil? || reset
101
- set(:new, git.native(:rev_parse, { :all => true }).empty?)
102
- end
103
- get(:new, false)
104
- end
105
-
106
- #-----------------------------------------------------------------------------
107
- # Property accessors / modifiers
108
-
109
- def lib
110
- return @git_lib
111
- end
112
-
113
- #---
114
-
115
- def git
116
- return lib.git if can_persist?
117
- return nil
118
- end
119
- protected :git
120
-
121
- #---
122
-
123
- def set_location(directory)
124
- super do
125
- ensure_git(true)
126
- end
127
- return myself
128
- end
129
-
130
- #---
131
-
132
- def config(name, options = {})
133
- return super do |config|
134
- git.config(config.export, name)
135
- end
136
- end
137
-
138
- #---
139
-
140
- def set_config(name, value, options = {})
141
- return super do |config, processed_value|
142
- git.config(config.export, name, processed_value)
143
- end
144
- end
145
-
146
- #---
147
-
148
- def delete_config(name, options = {})
149
- return super do |config|
150
- git.config(config.import({ :remove_section => true }).export, name)
151
- end
152
- end
153
-
154
- #---
155
-
156
- def subproject_config(options = {})
157
- return super do |config|
158
- result = {}
159
-
160
- if new?
161
- logger.debug("Project has no sub project configuration yet (has not been committed to)")
162
- else
163
- commit = lib.commit(revision)
164
- blob = commit.tree/'.gitmodules' unless commit.nil?
165
-
166
- if blob
167
- logger.debug("Houston, we have a Git blob!")
168
-
169
- lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")
170
- current = nil
171
-
172
- lines.each do |line|
173
- if line =~ /^\[submodule "(.+)"\]$/
174
- current = $1
175
- result[current] = {}
176
- result[current]['id'] = (commit.tree/current).id
177
-
178
- logger.debug("Reading: #{current}")
179
-
180
- elsif line =~ /^\t(\w+) = (.+)$/
181
- result[current][$1] = $2
182
- result[current]['id'] = (commit.tree/$2).id if $1 == 'path'
183
- end
184
- end
185
- end
186
- end
187
- result
188
- end
189
- end
190
-
191
- #-----------------------------------------------------------------------------
192
- # Basic Git operations
193
-
194
- def load_revision
195
- return super do
196
- if new?
197
- logger.debug("Project has no current revision yet (has not been committed to)")
198
- nil
199
-
200
- else
201
- current_revision = git.native(:rev_parse, { :abbrev_ref => true }, 'HEAD').strip
202
-
203
- logger.debug("Current revision: #{current_revision}")
204
- current_revision
205
- end
206
- end
207
- end
208
-
209
- #---
210
-
211
- def checkout(revision)
212
- return super do |success|
213
- if new?
214
- logger.debug("Project can not be checked out (has not been committed to)")
215
- else
216
- unless lib.bare
217
- success = safe_exec(false) do
218
- git.checkout({ :raise => true }, revision)
219
- end
220
- end
221
- end
222
- success
223
- end
224
- end
225
-
226
- #---
227
-
228
- def commit(files = '.', options = {})
229
- return super do |config, time, user, message|
230
- safe_exec(false) do
231
- git.reset({}, 'HEAD') # Clear the index so we get a clean commit
232
-
233
- files = array(files)
234
-
235
- logger.debug("Adding files to Git index")
236
-
237
- git.add({ :raise => true }, files) # Get all added and updated files
238
- git.add({ :update => true, :raise => true }, files) # Get all deleted files
239
-
240
- commit_options = {
241
- :raise => true,
242
- :m => "#{time} by <#{user}> - #{message}",
243
- :allow_empty => config.get(:allow_empty, false)
244
- }
245
- commit_options[:author] = config[:author] if config.get(:author, false)
246
-
247
- logger.debug("Composing commit options: #{commit_options.inspect}")
248
- git.commit(commit_options)
249
-
250
- new?(true)
251
- end
252
- end
253
- end
254
-
255
- #-----------------------------------------------------------------------------
256
- # Subproject operations
257
-
258
- def load_subprojects(options = {})
259
- return super do |project_path, data|
260
- File.exist?(File.join(project_path, '.git'))
261
- end
262
- end
263
-
264
- #---
265
-
266
- def add_subproject(path, url, revision, options = {})
267
- return super do |config|
268
- safe_exec(false) do
269
- branch_options = ''
270
- branch_options = [ '-b', config[:revision] ] if config.get(:revision, false)
271
-
272
- path = config[:path]
273
- url = config[:url]
274
-
275
- git.submodule({ :raise => true }, 'add', *branch_options, url, path)
276
-
277
- config.set(:files, [ '.gitmodules', path ])
278
- end
279
- end
280
- end
281
-
282
- #---
283
-
284
- def delete_subproject(path)
285
- return super do |config|
286
- safe_exec(false) do
287
- path = config[:path]
288
- submodule_key = "submodule.#{path}"
289
-
290
- logger.debug("Deleting Git configurations for #{submodule_key}")
291
- delete_config(submodule_key)
292
- delete_config(submodule_key, { :file => '.gitmodules' })
293
-
294
- logger.debug("Cleaning Git index cache for #{path}")
295
- git.rm({ :cached => true }, path)
296
-
297
- logger.debug("Removing Git submodule directories")
298
- FileUtils.rm_rf(File.join(directory, path))
299
- FileUtils.rm_rf(File.join(git.git_dir, 'modules', path))
300
-
301
- config.set(:files, [ '.gitmodules', path ])
302
- end
303
- end
304
- end
305
-
306
- #---
307
-
308
- def update_subprojects
309
- return super do
310
- safe_exec(false) do
311
- git.submodule({ :raise => true, :timeout => false }, 'update', '--init', '--recursive')
312
- end
313
- end
314
- end
315
-
316
- #-----------------------------------------------------------------------------
317
- # Remote operations
318
-
319
- def init_remotes
320
- return super do
321
- origin_url = config('remote.origin.url').strip
322
-
323
- logger.debug("Original origin remote url: #{origin_url}")
324
- origin_url
325
- end
326
- end
327
-
328
- #---
329
-
330
- def remote(name)
331
- return super do
332
- url = config("remote.#{name}.url").strip
333
- url.empty? ? nil : url
334
- end
335
- end
336
-
337
- #---
338
-
339
- def set_remote(name, url)
340
- return super do |processed_url|
341
- safe_exec(false) do
342
- git.remote({ :raise => true }, 'add', name.to_s, processed_url)
343
- end
344
- end
345
- end
346
-
347
- #---
348
-
349
- def add_remote_url(name, url, options = {})
350
- return super do |config, processed_url|
351
- safe_exec(false) do
352
- git.remote({
353
- :raise => true,
354
- :add => true,
355
- :delete => config.get(:delete, false),
356
- :push => config.get(:push, false)
357
- }, 'set-url', name.to_s, processed_url)
358
- end
359
- end
360
- end
361
-
362
- #---
363
-
364
- def delete_remote(name)
365
- return super do
366
- if config("remote.#{name}.url").empty?
367
- logger.debug("Project can not delete remote #{name} because it does not exist yet")
368
- true
369
- else
370
- safe_exec(false) do
371
- git.remote({ :raise => true }, 'rm', name.to_s)
372
- end
373
- end
374
- end
375
- end
376
-
377
- #---
378
-
379
- def syncronize(cloud, options = {})
380
- return super do |config|
381
- config.init(:remote_path, '/var/git')
382
- config.set(:add, true)
383
- end
384
- end
385
-
386
- #-----------------------------------------------------------------------------
387
- # SSH operations
388
-
389
- def pull(remote = :origin, options = {})
390
- return super do |config, processed_remote|
391
- flags = []
392
- flags << :tags if config.get(:tags, true)
393
-
394
- result = CORL.command({
395
- :command => :git,
396
- :data => { 'git-dir=' => git.git_dir },
397
- :subcommand => {
398
- :command => :pull,
399
- :flags => flags,
400
- :args => [ processed_remote, config.get(:revision, get(:revision, :master)) ]
401
- }
402
- }, config.get(:provider, :shell)).exec(config) do |op, command, data|
403
- block_given? ? yield(op, command, data) : true
404
- end
405
-
406
- if result.status == CORL.code.success
407
- new?(true)
408
- true
409
- else
410
- false
411
- end
412
- end
413
- end
414
-
415
- #---
416
-
417
- def push(remote = :edit, options = {})
418
- return super do |config, processed_remote|
419
- push_branch = config.get(:revision, '')
420
-
421
- flags = []
422
- flags << :all if push_branch.empty?
423
- flags << :tags if ! push_branch.empty? && config.get(:tags, true)
424
-
425
- result = CORL.command({
426
- :command => :git,
427
- :data => { 'git-dir=' => git.git_dir },
428
- :subcommand => {
429
- :command => :push,
430
- :flags => flags,
431
- :args => [ processed_remote, push_branch ]
432
- }
433
- }, config.get(:provider, :shell)).exec(config) do |op, command, data|
434
- block_given? ? yield(op, command, data) : true
435
- end
436
-
437
- result.status == CORL.code.success
438
- end
439
- end
440
-
441
- #-----------------------------------------------------------------------------
442
- # Utilities
443
-
444
- def translate_url(host, path, options = {})
445
- return super do |config|
446
- user = config.get(:user, 'git')
447
- auth = config.get(:auth, true)
448
-
449
- user + (auth ? '@' : '://') + host + (auth ? ':' : '/') + path
450
- end
451
- end
452
-
453
- #---
454
-
455
- def translate_edit_url(url, options = {})
456
- return super do |config|
457
- if matches = url.strip.match(/^(https?|git)\:\/\/([^\/]+)\/(.+)/)
458
- protocol, host, path = matches.captures
459
- translate_url(host, path, config.import({ :auth => true }))
460
- end
461
- end
462
- end
463
- end
464
- end
465
- end