fig18 0.1.39 → 0.1.40

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fig.rb CHANGED
@@ -0,0 +1,222 @@
1
+ require 'rubygems'
2
+ require 'net/ftp'
3
+ require 'log4r'
4
+
5
+ require 'fig/environment'
6
+ require 'fig/figrc'
7
+ require 'fig/logging'
8
+ require 'fig/options'
9
+ require 'fig/os'
10
+ require 'fig/parser'
11
+ require 'fig/repository'
12
+ require 'fig/retriever'
13
+ require 'fig/userinputerror'
14
+ require 'fig/windows'
15
+
16
+ module Fig
17
+ DEFAULT_FIG_FILE = 'package.fig'
18
+
19
+ def parse_descriptor(descriptor)
20
+ # todo should use treetop for these:
21
+ package_name = descriptor =~ /^([^:\/]+)/ ? $1 : nil
22
+ config_name = descriptor =~ /:([^:\/]+)/ ? $1 : nil
23
+ version_name = descriptor =~ /\/([^:\/]+)/ ? $1 : nil
24
+ return package_name, config_name, version_name
25
+ end
26
+
27
+ def run_fig(argv)
28
+ shell_command = nil
29
+ argv.each_with_index do |arg, i|
30
+ if arg == '--'
31
+ shell_command = argv[(i+1)..-1]
32
+ argv.slice!(i..-1)
33
+ break
34
+ end
35
+ end
36
+
37
+ options, argv, exit_value = parse_options(argv)
38
+ if not exit_value.nil?
39
+ return exit_value
40
+ end
41
+
42
+ Logging.initialize_pre_configuration(options[:log_level])
43
+
44
+ vars = {}
45
+ ENV.each {|key,value| vars[key]=value }
46
+
47
+ remote_url = nil
48
+ if options[:update] || options[:publish] || options[:update_if_missing] || options[:list_remote]
49
+ remote_url = ENV['FIG_REMOTE_URL']
50
+ if remote_url.nil?
51
+ $stderr.puts 'Please define the FIG_REMOTE_URL environment variable.'
52
+ return 1
53
+ end
54
+ end
55
+
56
+ configuration = FigRC.find(
57
+ options[:figrc],
58
+ remote_url,
59
+ options[:login],
60
+ options[:home],
61
+ options[:no_figrc]
62
+ )
63
+
64
+ Logging.initialize_post_configuration(options[:log_config] || configuration['log configuration'], options[:log_level])
65
+
66
+ remote_user = nil
67
+
68
+ os = OS.new(options[:login])
69
+ repos = Repository.new(
70
+ os,
71
+ File.expand_path(File.join(options[:home], 'repos')),
72
+ remote_url,
73
+ configuration,
74
+ remote_user,
75
+ options[:update],
76
+ options[:update_if_missing]
77
+ )
78
+ retriever = Retriever.new('.')
79
+ # Check to see if this is still happening with the new layers of abstraction.
80
+ at_exit { retriever.save }
81
+ env = Environment.new(os, repos, vars, retriever)
82
+
83
+ options[:modifiers].each do |modifier|
84
+ env.apply_config_statement(nil, modifier, nil)
85
+ end
86
+
87
+ input = nil
88
+ if options[:input] == :none
89
+ # ignore
90
+ elsif options[:input] == '-'
91
+ input = $stdin.read
92
+ elsif options[:input].nil?
93
+ input = os.read(DEFAULT_FIG_FILE) if os.exist?(DEFAULT_FIG_FILE)
94
+ else
95
+ if os.exist?(options[:input])
96
+ input = os.read(options[:input])
97
+ else
98
+ $stderr.puts %Q<File not found: "#{options[:input]}".>
99
+ return 1
100
+ end
101
+ end
102
+
103
+ options[:cleans].each do |descriptor|
104
+ package_name, version_name = descriptor.split('/')
105
+ repos.clean(package_name, version_name)
106
+ end
107
+ if options[:list]
108
+ repos.list_packages.sort.each do |item|
109
+ puts item
110
+ end
111
+ return 0
112
+ end
113
+
114
+ if options[:list_remote]
115
+ repos.list_remote_packages.sort.each do |item|
116
+ puts item
117
+ end
118
+ return 0
119
+ end
120
+
121
+ if not options[:list_configs].empty?
122
+ options[:list_configs].each do |descriptor|
123
+ package_name, version_name = descriptor.split('/')
124
+ repos.read_local_package(package_name, version_name).configs.each do |config|
125
+ puts config.name
126
+ end
127
+ end
128
+ return 0
129
+ end
130
+
131
+ if input
132
+ package = Parser.new.parse_package(nil, nil, '.', input)
133
+ direct_retrieves=[]
134
+ if options[:retrieve]
135
+ package.retrieves.each do |var, path|
136
+ if var =~ /^@([^\/]+)(.*)/
137
+ direct_retrieves << [$1, $2, path]
138
+ else
139
+ env.add_retrieve(var, path)
140
+ end
141
+ end
142
+ end
143
+ unless options[:publish] || options[:list] || options[:publish_local]
144
+ env.register_package(package)
145
+ env.apply_config(package, options[:config], nil)
146
+ direct_retrieves.each do |info|
147
+ env.direct_retrieve(info[0], info[1], info[2])
148
+ end
149
+ end
150
+ else
151
+ package = Package.new(nil, nil, '.', [])
152
+ end
153
+
154
+ if options[:publish] || options[:publish_local]
155
+ if !argv.empty?
156
+ $stderr.puts %Q<Unexpected arguments: #{argv.join(' ')}>
157
+ return 10
158
+ end
159
+ package_name, config_name, version_name = parse_descriptor(options[:publish] || options[:publish_local])
160
+ if package_name.nil? || version_name.nil?
161
+ $stderr.puts 'Please specify a package name and a version name.'
162
+ return 10
163
+ end
164
+ if not options[:modifiers].empty?
165
+ publish_statements = options[:resources] + options[:archives] + [Configuration.new('default', options[:modifiers])]
166
+ publish_statements << Publish.new('default','default')
167
+ elsif not package.statements.empty?
168
+ publish_statements = package.statements
169
+ else
170
+ $stderr.puts 'Nothing to publish.'
171
+ return 1
172
+ end
173
+ if options[:publish]
174
+ Logging.info "Checking status of #{package_name}/#{version_name}..."
175
+ if repos.list_remote_packages.include?("#{package_name}/#{version_name}")
176
+ Logging.info "#{package_name}/#{version_name} has already been published."
177
+ if not options[:force]
178
+ Logging.fatal 'Use the --force option if you really want to overwrite, or use --publish-local for testing.'
179
+ return 1
180
+ else
181
+ Logging.info 'Overwriting...'
182
+ end
183
+ end
184
+ end
185
+ Logging.info "Publishing #{package_name}/#{version_name}."
186
+ repos.publish_package(publish_statements, package_name, version_name, options[:publish_local])
187
+ elsif options[:echo]
188
+ puts env[options[:echo]]
189
+ elsif shell_command
190
+ argv.shift
191
+ env.execute_shell(shell_command) { |cmd| os.shell_exec cmd }
192
+ elsif argv[0]
193
+ package_name, config_name, version_name = parse_descriptor(argv.shift)
194
+ env.include_config(package, package_name, config_name, version_name, {}, nil)
195
+ env.execute_config(package, package_name, config_name, nil, argv) { |cmd| os.shell_exec cmd }
196
+ elsif input
197
+ env.execute_config(package, nil, options[:config], nil, argv) { |cmd| os.shell_exec cmd }
198
+ elsif !repos.updating?
199
+ $stderr.puts USAGE
200
+ $stderr.puts %q<Run "fig --help" for a full list of commands.>
201
+ end
202
+
203
+ return 0
204
+ end
205
+
206
+ def run_with_exception_handling(argv)
207
+ begin
208
+ return_code = run_fig(argv)
209
+ return return_code
210
+ rescue URLAccessError => exception
211
+ $stderr.puts "Access to #{exception.url} not allowed."
212
+ return 1
213
+ rescue UserInputError => exception
214
+ # If there's no message, we assume that the cause has already been logged.
215
+ if not exception.message.nil?
216
+ $stderr.puts exception.to_s
217
+ end
218
+
219
+ return 1
220
+ end
221
+ end
222
+ end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fig18
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.39
4
+ hash: 75
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 40
10
+ version: 0.1.40
6
11
  platform: ruby
7
12
  authors:
8
13
  - Matthew Foemmel
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-10-07 00:00:00 -05:00
18
+ date: 2011-11-10 00:00:00 -06:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -19,31 +24,46 @@ dependencies:
19
24
  requirement: &id001 !ruby/object:Gem::Requirement
20
25
  none: false
21
26
  requirements:
22
- - - "="
27
+ - - ">="
23
28
  - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
24
34
  version: 1.0.0
25
35
  type: :runtime
26
36
  version_requirements: *id001
27
37
  - !ruby/object:Gem::Dependency
28
- name: net-ssh
38
+ name: highline
29
39
  prerelease: false
30
40
  requirement: &id002 !ruby/object:Gem::Requirement
31
41
  none: false
32
42
  requirements:
33
43
  - - ">="
34
44
  - !ruby/object:Gem::Version
35
- version: 2.0.15
45
+ hash: 11
46
+ segments:
47
+ - 1
48
+ - 6
49
+ - 2
50
+ version: 1.6.2
36
51
  type: :runtime
37
52
  version_requirements: *id002
38
53
  - !ruby/object:Gem::Dependency
39
- name: net-sftp
54
+ name: log4r
40
55
  prerelease: false
41
56
  requirement: &id003 !ruby/object:Gem::Requirement
42
57
  none: false
43
58
  requirements:
44
59
  - - ">="
45
60
  - !ruby/object:Gem::Version
46
- version: 2.0.4
61
+ hash: 25
62
+ segments:
63
+ - 1
64
+ - 1
65
+ - 5
66
+ version: 1.1.5
47
67
  type: :runtime
48
68
  version_requirements: *id003
49
69
  - !ruby/object:Gem::Dependency
@@ -54,163 +74,298 @@ dependencies:
54
74
  requirements:
55
75
  - - ">="
56
76
  - !ruby/object:Gem::Version
77
+ hash: 19
78
+ segments:
79
+ - 0
80
+ - 2
81
+ - 2
57
82
  version: 0.2.2
58
83
  type: :runtime
59
84
  version_requirements: *id004
60
85
  - !ruby/object:Gem::Dependency
61
- name: polyglot
86
+ name: net-sftp
62
87
  prerelease: false
63
88
  requirement: &id005 !ruby/object:Gem::Requirement
64
89
  none: false
65
90
  requirements:
66
91
  - - ">="
67
92
  - !ruby/object:Gem::Version
68
- version: 0.2.9
93
+ hash: 7
94
+ segments:
95
+ - 2
96
+ - 0
97
+ - 4
98
+ version: 2.0.4
69
99
  type: :runtime
70
100
  version_requirements: *id005
71
101
  - !ruby/object:Gem::Dependency
72
- name: treetop
102
+ name: net-ssh
73
103
  prerelease: false
74
104
  requirement: &id006 !ruby/object:Gem::Requirement
75
105
  none: false
76
106
  requirements:
77
107
  - - ">="
78
108
  - !ruby/object:Gem::Version
79
- version: 1.4.2
109
+ hash: 17
110
+ segments:
111
+ - 2
112
+ - 0
113
+ - 15
114
+ version: 2.0.15
80
115
  type: :runtime
81
116
  version_requirements: *id006
82
117
  - !ruby/object:Gem::Dependency
83
- name: highline
118
+ name: polyglot
84
119
  prerelease: false
85
120
  requirement: &id007 !ruby/object:Gem::Requirement
86
121
  none: false
87
122
  requirements:
88
123
  - - ">="
89
124
  - !ruby/object:Gem::Version
90
- version: 1.6.2
125
+ hash: 5
126
+ segments:
127
+ - 0
128
+ - 2
129
+ - 9
130
+ version: 0.2.9
91
131
  type: :runtime
92
132
  version_requirements: *id007
93
133
  - !ruby/object:Gem::Dependency
94
- name: rspec
134
+ name: rdoc
95
135
  prerelease: false
96
136
  requirement: &id008 !ruby/object:Gem::Requirement
97
137
  none: false
98
138
  requirements:
99
- - - ~>
139
+ - - ">="
100
140
  - !ruby/object:Gem::Version
101
- version: "1.3"
102
- type: :development
141
+ hash: 27
142
+ segments:
143
+ - 2
144
+ - 4
145
+ - 2
146
+ version: 2.4.2
147
+ type: :runtime
103
148
  version_requirements: *id008
104
149
  - !ruby/object:Gem::Dependency
105
- name: open4
150
+ name: treetop
106
151
  prerelease: false
107
152
  requirement: &id009 !ruby/object:Gem::Requirement
108
153
  none: false
109
154
  requirements:
110
155
  - - ">="
111
156
  - !ruby/object:Gem::Version
112
- version: 1.0.1
113
- type: :development
157
+ hash: 3
158
+ segments:
159
+ - 1
160
+ - 4
161
+ - 2
162
+ version: 1.4.2
163
+ type: :runtime
114
164
  version_requirements: *id009
115
165
  - !ruby/object:Gem::Dependency
116
- name: libarchive-static-ruby186
166
+ name: open4
117
167
  prerelease: false
118
168
  requirement: &id010 !ruby/object:Gem::Requirement
119
169
  none: false
120
170
  requirements:
121
- - - "="
171
+ - - ">="
122
172
  - !ruby/object:Gem::Version
123
- version: 1.0.0
124
- type: :runtime
173
+ hash: 21
174
+ segments:
175
+ - 1
176
+ - 0
177
+ - 1
178
+ version: 1.0.1
179
+ type: :development
125
180
  version_requirements: *id010
126
181
  - !ruby/object:Gem::Dependency
127
- name: net-ssh
182
+ name: rspec
128
183
  prerelease: false
129
184
  requirement: &id011 !ruby/object:Gem::Requirement
130
185
  none: false
131
186
  requirements:
132
- - - ">="
187
+ - - ~>
133
188
  - !ruby/object:Gem::Version
134
- version: 2.0.15
135
- type: :runtime
189
+ hash: 7
190
+ segments:
191
+ - 2
192
+ version: "2"
193
+ type: :development
136
194
  version_requirements: *id011
137
195
  - !ruby/object:Gem::Dependency
138
- name: net-sftp
196
+ name: libarchive-static-ruby186
139
197
  prerelease: false
140
198
  requirement: &id012 !ruby/object:Gem::Requirement
141
199
  none: false
142
200
  requirements:
143
201
  - - ">="
144
202
  - !ruby/object:Gem::Version
145
- version: 2.0.4
203
+ hash: 23
204
+ segments:
205
+ - 1
206
+ - 0
207
+ - 0
208
+ version: 1.0.0
146
209
  type: :runtime
147
210
  version_requirements: *id012
148
211
  - !ruby/object:Gem::Dependency
149
- name: net-netrc
212
+ name: highline
150
213
  prerelease: false
151
214
  requirement: &id013 !ruby/object:Gem::Requirement
152
215
  none: false
153
216
  requirements:
154
217
  - - ">="
155
218
  - !ruby/object:Gem::Version
156
- version: 0.2.2
219
+ hash: 11
220
+ segments:
221
+ - 1
222
+ - 6
223
+ - 2
224
+ version: 1.6.2
157
225
  type: :runtime
158
226
  version_requirements: *id013
159
227
  - !ruby/object:Gem::Dependency
160
- name: polyglot
228
+ name: log4r
161
229
  prerelease: false
162
230
  requirement: &id014 !ruby/object:Gem::Requirement
163
231
  none: false
164
232
  requirements:
165
233
  - - ">="
166
234
  - !ruby/object:Gem::Version
167
- version: 0.2.9
235
+ hash: 25
236
+ segments:
237
+ - 1
238
+ - 1
239
+ - 5
240
+ version: 1.1.5
168
241
  type: :runtime
169
242
  version_requirements: *id014
170
243
  - !ruby/object:Gem::Dependency
171
- name: treetop
244
+ name: net-netrc
172
245
  prerelease: false
173
246
  requirement: &id015 !ruby/object:Gem::Requirement
174
247
  none: false
175
248
  requirements:
176
249
  - - ">="
177
250
  - !ruby/object:Gem::Version
178
- version: 1.4.2
251
+ hash: 19
252
+ segments:
253
+ - 0
254
+ - 2
255
+ - 2
256
+ version: 0.2.2
179
257
  type: :runtime
180
258
  version_requirements: *id015
181
259
  - !ruby/object:Gem::Dependency
182
- name: highline
260
+ name: net-sftp
183
261
  prerelease: false
184
262
  requirement: &id016 !ruby/object:Gem::Requirement
185
263
  none: false
186
264
  requirements:
187
265
  - - ">="
188
266
  - !ruby/object:Gem::Version
189
- version: 1.6.2
267
+ hash: 7
268
+ segments:
269
+ - 2
270
+ - 0
271
+ - 4
272
+ version: 2.0.4
190
273
  type: :runtime
191
274
  version_requirements: *id016
192
275
  - !ruby/object:Gem::Dependency
193
- name: rspec
276
+ name: net-ssh
194
277
  prerelease: false
195
278
  requirement: &id017 !ruby/object:Gem::Requirement
196
279
  none: false
197
280
  requirements:
198
- - - ~>
281
+ - - ">="
199
282
  - !ruby/object:Gem::Version
200
- version: "1.3"
201
- type: :development
283
+ hash: 17
284
+ segments:
285
+ - 2
286
+ - 0
287
+ - 15
288
+ version: 2.0.15
289
+ type: :runtime
202
290
  version_requirements: *id017
203
291
  - !ruby/object:Gem::Dependency
204
- name: open4
292
+ name: polyglot
205
293
  prerelease: false
206
294
  requirement: &id018 !ruby/object:Gem::Requirement
207
295
  none: false
208
296
  requirements:
209
297
  - - ">="
210
298
  - !ruby/object:Gem::Version
299
+ hash: 5
300
+ segments:
301
+ - 0
302
+ - 2
303
+ - 9
304
+ version: 0.2.9
305
+ type: :runtime
306
+ version_requirements: *id018
307
+ - !ruby/object:Gem::Dependency
308
+ name: rdoc
309
+ prerelease: false
310
+ requirement: &id019 !ruby/object:Gem::Requirement
311
+ none: false
312
+ requirements:
313
+ - - ">="
314
+ - !ruby/object:Gem::Version
315
+ hash: 27
316
+ segments:
317
+ - 2
318
+ - 4
319
+ - 2
320
+ version: 2.4.2
321
+ type: :runtime
322
+ version_requirements: *id019
323
+ - !ruby/object:Gem::Dependency
324
+ name: treetop
325
+ prerelease: false
326
+ requirement: &id020 !ruby/object:Gem::Requirement
327
+ none: false
328
+ requirements:
329
+ - - ">="
330
+ - !ruby/object:Gem::Version
331
+ hash: 3
332
+ segments:
333
+ - 1
334
+ - 4
335
+ - 2
336
+ version: 1.4.2
337
+ type: :runtime
338
+ version_requirements: *id020
339
+ - !ruby/object:Gem::Dependency
340
+ name: open4
341
+ prerelease: false
342
+ requirement: &id021 !ruby/object:Gem::Requirement
343
+ none: false
344
+ requirements:
345
+ - - ">="
346
+ - !ruby/object:Gem::Version
347
+ hash: 21
348
+ segments:
349
+ - 1
350
+ - 0
351
+ - 1
211
352
  version: 1.0.1
212
353
  type: :development
213
- version_requirements: *id018
354
+ version_requirements: *id021
355
+ - !ruby/object:Gem::Dependency
356
+ name: rspec
357
+ prerelease: false
358
+ requirement: &id022 !ruby/object:Gem::Requirement
359
+ none: false
360
+ requirements:
361
+ - - ~>
362
+ - !ruby/object:Gem::Version
363
+ hash: 7
364
+ segments:
365
+ - 2
366
+ version: "2"
367
+ type: :development
368
+ version_requirements: *id022
214
369
  description: Fig is a utility for configuring environments and managing dependencies across a team of developers. You give it a list of packages and a shell command to run; it creates an environment that includes those packages, then executes the shell command in it (the caller's environment is not affected).
215
370
  email: git@foemmel.com
216
371
  executables:
@@ -222,18 +377,31 @@ extra_rdoc_files:
222
377
  - LICENSE
223
378
  - README.md
224
379
  files:
380
+ - Changes
381
+ - VERSION
225
382
  - bin/fig
226
383
  - bin/fig-download
227
384
  - lib/fig.rb
385
+ - lib/fig/applicationconfiguration.rb
228
386
  - lib/fig/backtrace.rb
387
+ - lib/fig/configfileerror.rb
229
388
  - lib/fig/environment.rb
389
+ - lib/fig/figrc.rb
230
390
  - lib/fig/grammar.treetop
391
+ - lib/fig/log4rconfigerror.rb
392
+ - lib/fig/logging.rb
393
+ - lib/fig/networkerror.rb
394
+ - lib/fig/notfounderror.rb
231
395
  - lib/fig/options.rb
232
396
  - lib/fig/os.rb
233
397
  - lib/fig/package.rb
398
+ - lib/fig/packageerror.rb
234
399
  - lib/fig/parser.rb
235
400
  - lib/fig/repository.rb
401
+ - lib/fig/repositoryerror.rb
236
402
  - lib/fig/retriever.rb
403
+ - lib/fig/urlaccesserror.rb
404
+ - lib/fig/userinputerror.rb
237
405
  - lib/fig/windows.rb
238
406
  - LICENSE
239
407
  - README.md
@@ -251,19 +419,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
419
  requirements:
252
420
  - - ">="
253
421
  - !ruby/object:Gem::Version
422
+ hash: 3
423
+ segments:
424
+ - 0
254
425
  version: "0"
255
426
  required_rubygems_version: !ruby/object:Gem::Requirement
256
427
  none: false
257
428
  requirements:
258
429
  - - ">="
259
430
  - !ruby/object:Gem::Version
431
+ hash: 3
432
+ segments:
433
+ - 0
260
434
  version: "0"
261
435
  requirements: []
262
436
 
263
437
  rubyforge_project:
264
- rubygems_version: 1.5.3
438
+ rubygems_version: 1.3.7
265
439
  signing_key:
266
440
  specification_version: 3
267
- summary: Fig is a utility for configuring environments and managing dependencies across a team of developers..
441
+ summary: Fig is a utility for configuring environments and managing dependencies across a team of developers.
268
442
  test_files: []
269
443