fig 0.1.51 → 0.1.52
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +93 -0
- data/LICENSE +1 -1
- data/README.md +330 -99
- data/TODO +4 -0
- data/VERSION +1 -1
- data/bin/fig +2 -4
- data/lib/fig/backtrace.rb +3 -1
- data/lib/fig/command.rb +477 -0
- data/lib/fig/environment.rb +76 -23
- data/lib/fig/figrc.rb +2 -2
- data/lib/fig/grammar.treetop +23 -31
- data/lib/fig/{os.rb → operatingsystem.rb} +11 -9
- data/lib/fig/options.rb +424 -202
- data/lib/fig/package.rb +134 -18
- data/lib/fig/packagecache.rb +36 -0
- data/lib/fig/packagedescriptor.rb +46 -0
- data/lib/fig/parser.rb +2 -2
- data/lib/fig/repository.rb +173 -124
- data/lib/fig/retriever.rb +3 -1
- data/lib/fig/statement.rb +18 -0
- data/lib/fig/{package → statement}/archive.rb +3 -4
- data/lib/fig/{package → statement}/command.rb +3 -4
- data/lib/fig/{package → statement}/configuration.rb +18 -6
- data/lib/fig/statement/include.rb +87 -0
- data/lib/fig/{package → statement}/override.rb +3 -4
- data/lib/fig/{package → statement}/path.rb +3 -4
- data/lib/fig/{package → statement}/publish.rb +3 -4
- data/lib/fig/{package → statement}/resource.rb +3 -4
- data/lib/fig/{package → statement}/retrieve.rb +3 -4
- data/lib/fig/{package → statement}/set.rb +3 -4
- metadata +118 -71
- data/lib/fig.rb +0 -288
- data/lib/fig/package/include.rb +0 -32
- data/lib/fig/package/install.rb +0 -22
- data/lib/fig/package/statement.rb +0 -13
data/lib/fig.rb
DELETED
@@ -1,288 +0,0 @@
|
|
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/package'
|
11
|
-
require 'fig/package/configuration'
|
12
|
-
require 'fig/package/publish'
|
13
|
-
require 'fig/parser'
|
14
|
-
require 'fig/repository'
|
15
|
-
require 'fig/retriever'
|
16
|
-
require 'fig/userinputerror'
|
17
|
-
require 'fig/windows'
|
18
|
-
|
19
|
-
# Main program
|
20
|
-
module Fig
|
21
|
-
DEFAULT_FIG_FILE = 'package.fig'
|
22
|
-
|
23
|
-
def parse_descriptor(descriptor)
|
24
|
-
# todo should use treetop for these:
|
25
|
-
package_name = descriptor =~ %r< ^ ( [^:/]+ ) >x ? $1 : nil
|
26
|
-
config_name = descriptor =~ %r< : ( [^:/]+ ) >x ? $1 : nil
|
27
|
-
version_name = descriptor =~ %r< / ( [^:/]+ ) >x ? $1 : nil
|
28
|
-
return package_name, config_name, version_name
|
29
|
-
end
|
30
|
-
|
31
|
-
def read_in_package_config_file(options)
|
32
|
-
if File.exist?(options[:package_config_file])
|
33
|
-
return File.read(options[:package_config_file])
|
34
|
-
else
|
35
|
-
raise UserInputError.new(%Q<File not found: "#{options[:package_config_file]}".>)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def initialize_shell_command(argv)
|
40
|
-
shell_command = nil
|
41
|
-
argv.each_with_index do |arg, i|
|
42
|
-
if arg == '--'
|
43
|
-
shell_command = argv[(i+1)..-1]
|
44
|
-
argv.slice!(i..-1)
|
45
|
-
break
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
return shell_command
|
50
|
-
end
|
51
|
-
|
52
|
-
def initialize_remote_url(options)
|
53
|
-
if options[:update] || options[:publish] || options[:update_if_missing] || options[:list_remote]
|
54
|
-
if ENV['FIG_REMOTE_URL'].nil?
|
55
|
-
raise UserInputError.new 'Please define the FIG_REMOTE_URL environment variable.'
|
56
|
-
end
|
57
|
-
return ENV['FIG_REMOTE_URL']
|
58
|
-
end
|
59
|
-
|
60
|
-
return nil
|
61
|
-
end
|
62
|
-
|
63
|
-
def load_package_config_file_contents(options)
|
64
|
-
package_config_file = options[:package_config_file]
|
65
|
-
|
66
|
-
if package_config_file == :none
|
67
|
-
return nil
|
68
|
-
elsif package_config_file == '-'
|
69
|
-
return $stdin.read
|
70
|
-
elsif package_config_file.nil?
|
71
|
-
if File.exist?(DEFAULT_FIG_FILE)
|
72
|
-
return File.read(DEFAULT_FIG_FILE)
|
73
|
-
end
|
74
|
-
else
|
75
|
-
return read_in_package_config_file(options)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def display_package_list(repository)
|
80
|
-
repository.list_packages.sort.each do |item|
|
81
|
-
puts item
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def display_remote_package_list(repository)
|
86
|
-
repository.list_remote_packages.sort.each do |item|
|
87
|
-
puts item
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def display_configs_in_local_packages_list(options, repository)
|
92
|
-
options[:list_configs].each do |descriptor|
|
93
|
-
package_name, version_name = descriptor.split('/')
|
94
|
-
repository.read_local_package(package_name, version_name).configs.each do |config|
|
95
|
-
puts config.name
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def resolve_listing(options, repository)
|
101
|
-
if options[:list]
|
102
|
-
display_package_list(repository)
|
103
|
-
return true
|
104
|
-
end
|
105
|
-
|
106
|
-
if options[:list_remote]
|
107
|
-
display_remote_package_list(repository)
|
108
|
-
return true
|
109
|
-
end
|
110
|
-
|
111
|
-
if not options[:list_configs].empty?
|
112
|
-
display_configs_in_local_packages_list(options, repository)
|
113
|
-
return true
|
114
|
-
end
|
115
|
-
|
116
|
-
return false
|
117
|
-
end
|
118
|
-
|
119
|
-
def parse_package_config_file(options, package_config_file, environment, configuration)
|
120
|
-
if package_config_file
|
121
|
-
package = Parser.new(configuration).parse_package(nil, nil, '.', package_config_file)
|
122
|
-
if options[:update] || options[:update_if_missing]
|
123
|
-
package.retrieves.each do |var, path|
|
124
|
-
environment.add_retrieve(var, path)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
unless options[:publish] || options[:list] || options[:publish_local]
|
129
|
-
environment.register_package(package)
|
130
|
-
environment.apply_config(package, options[:config], nil)
|
131
|
-
end
|
132
|
-
else
|
133
|
-
package = Package.new(nil, nil, '.', [])
|
134
|
-
end
|
135
|
-
|
136
|
-
return package, environment
|
137
|
-
end
|
138
|
-
|
139
|
-
def publish(argv, options, package, repository)
|
140
|
-
if not argv.empty?
|
141
|
-
$stderr.puts %Q<Unexpected arguments: #{argv.join(' ')}>
|
142
|
-
return 10
|
143
|
-
end
|
144
|
-
|
145
|
-
package_name, config_name, version_name = parse_descriptor(options[:publish] || options[:publish_local])
|
146
|
-
|
147
|
-
if package_name.nil? || version_name.nil?
|
148
|
-
$stderr.puts 'Please specify a package name and a version name.'
|
149
|
-
return 10
|
150
|
-
end
|
151
|
-
|
152
|
-
if not options[:non_command_package_statements].empty?
|
153
|
-
publish_statements = options[:resources] + options[:archives] + [Package::Configuration.new('default', options[:non_command_package_statements])]
|
154
|
-
publish_statements << Package::Publish.new('default','default')
|
155
|
-
elsif not package.statements.empty?
|
156
|
-
publish_statements = package.statements
|
157
|
-
else
|
158
|
-
$stderr.puts 'Nothing to publish.'
|
159
|
-
return 1
|
160
|
-
end
|
161
|
-
|
162
|
-
if options[:publish]
|
163
|
-
Logging.info "Checking status of #{package_name}/#{version_name}..."
|
164
|
-
|
165
|
-
if repository.list_remote_packages.include?("#{package_name}/#{version_name}")
|
166
|
-
Logging.info "#{package_name}/#{version_name} has already been published."
|
167
|
-
|
168
|
-
if not options[:force]
|
169
|
-
Logging.fatal 'Use the --force option if you really want to overwrite, or use --publish-local for testing.'
|
170
|
-
return 1
|
171
|
-
else
|
172
|
-
Logging.info 'Overwriting...'
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
Logging.info "Publishing #{package_name}/#{version_name}."
|
178
|
-
repository.publish_package(publish_statements, package_name, version_name, options[:publish_local])
|
179
|
-
|
180
|
-
return 0
|
181
|
-
end
|
182
|
-
|
183
|
-
def run_fig(argv)
|
184
|
-
shell_command = initialize_shell_command(argv)
|
185
|
-
|
186
|
-
options, argv, exit_value = parse_options(argv)
|
187
|
-
if not exit_value.nil?
|
188
|
-
return exit_value
|
189
|
-
end
|
190
|
-
|
191
|
-
Logging.initialize_pre_configuration(options[:log_level])
|
192
|
-
|
193
|
-
remote_url = initialize_remote_url(options)
|
194
|
-
|
195
|
-
configuration = FigRC.find(
|
196
|
-
options[:figrc], remote_url, options[:login], options[:home], options[:no_figrc]
|
197
|
-
)
|
198
|
-
|
199
|
-
Logging.initialize_post_configuration(options[:log_config] || configuration['log configuration'], options[:log_level])
|
200
|
-
|
201
|
-
os = OS.new(options[:login])
|
202
|
-
repository = Repository.new(
|
203
|
-
os,
|
204
|
-
File.expand_path(File.join(options[:home], 'repos')),
|
205
|
-
remote_url,
|
206
|
-
configuration,
|
207
|
-
nil, # remote_user
|
208
|
-
options[:update],
|
209
|
-
options[:update_if_missing]
|
210
|
-
)
|
211
|
-
|
212
|
-
retriever = Retriever.new('.')
|
213
|
-
# Check to see if this is still happening with the new layers of abstraction.
|
214
|
-
at_exit { retriever.save }
|
215
|
-
environment = Environment.new(os, repository, nil, retriever)
|
216
|
-
|
217
|
-
options[:non_command_package_statements].each do |statement|
|
218
|
-
environment.apply_config_statement(nil, statement, nil)
|
219
|
-
end
|
220
|
-
|
221
|
-
package_config_file = load_package_config_file_contents(options)
|
222
|
-
|
223
|
-
options[:cleans].each do |descriptor|
|
224
|
-
package_name, version_name = descriptor.split('/')
|
225
|
-
repository.clean(package_name, version_name)
|
226
|
-
return true
|
227
|
-
end
|
228
|
-
|
229
|
-
if resolve_listing(options, repository)
|
230
|
-
return true
|
231
|
-
end
|
232
|
-
|
233
|
-
package, environment = parse_package_config_file(options, package_config_file, environment, configuration)
|
234
|
-
|
235
|
-
if options[:publish] || options[:publish_local]
|
236
|
-
return publish(argv, options, package, repository)
|
237
|
-
elsif options[:get]
|
238
|
-
puts environment[options[:get]]
|
239
|
-
elsif shell_command
|
240
|
-
argv.shift
|
241
|
-
environment.execute_shell(shell_command) { |cmd| os.shell_exec cmd }
|
242
|
-
elsif not argv.empty?
|
243
|
-
package_name, config_name, version_name = parse_descriptor(argv.shift)
|
244
|
-
environment.include_config(package, package_name, config_name, version_name, {}, nil)
|
245
|
-
environment.execute_config(package, package_name, config_name, nil, argv) { |cmd| os.shell_exec cmd }
|
246
|
-
elsif not repository.updating?
|
247
|
-
$stderr.puts "Nothing to do.\n"
|
248
|
-
$stderr.puts USAGE
|
249
|
-
$stderr.puts %q<Run "fig --help" for a full list of commands.>
|
250
|
-
return 1
|
251
|
-
end
|
252
|
-
|
253
|
-
return 0
|
254
|
-
end
|
255
|
-
|
256
|
-
def log_error_message(error)
|
257
|
-
# If there's no message, we assume that the cause has already been logged.
|
258
|
-
if error_has_message?(error)
|
259
|
-
Logging.fatal error.to_s
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def run_with_exception_handling(argv)
|
264
|
-
begin
|
265
|
-
return_code = run_fig(argv)
|
266
|
-
return return_code
|
267
|
-
rescue URLAccessError => error
|
268
|
-
urls = exception.urls.join(', ')
|
269
|
-
$stderr.puts "Access to #{urls} in #{exception.package}/#{exception.version} not allowed."
|
270
|
-
return 1
|
271
|
-
rescue UserInputError => error
|
272
|
-
log_error_message(error)
|
273
|
-
return 1
|
274
|
-
rescue OptionParser::InvalidOption => error
|
275
|
-
$stderr.puts error.to_s
|
276
|
-
$stderr.puts USAGE
|
277
|
-
return 1
|
278
|
-
rescue RepositoryError => error
|
279
|
-
log_error_message(error)
|
280
|
-
return 1
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def error_has_message?(error)
|
285
|
-
class_name = error.class.name
|
286
|
-
return error.message != class_name
|
287
|
-
end
|
288
|
-
end
|
data/lib/fig/package/include.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'fig/logging'
|
2
|
-
require 'fig/packageerror'
|
3
|
-
require 'fig/package/statement'
|
4
|
-
|
5
|
-
module Fig; end
|
6
|
-
class Fig::Package; end
|
7
|
-
|
8
|
-
# Dual role: "include :configname" incorporates one configuration into another;
|
9
|
-
# "include package[/version]" declares a dependency upon another package.
|
10
|
-
class Fig::Package::Include
|
11
|
-
include Fig::Package::Statement
|
12
|
-
|
13
|
-
attr_reader :package_name, :config_name, :version_name, :overrides
|
14
|
-
|
15
|
-
def initialize(package_name, config_name, version_name, overrides)
|
16
|
-
@package_name = package_name
|
17
|
-
@config_name = config_name
|
18
|
-
@version_name = version_name
|
19
|
-
@overrides = overrides
|
20
|
-
end
|
21
|
-
|
22
|
-
def unparse(indent)
|
23
|
-
descriptor = ''
|
24
|
-
descriptor += @package_name if @package_name
|
25
|
-
descriptor += "/#{@version_name}" if @version_name
|
26
|
-
descriptor += ":#{@config_name}" if @config_name
|
27
|
-
@overrides.each do |override|
|
28
|
-
descriptor += override.unparse
|
29
|
-
end
|
30
|
-
return "#{indent}include #{descriptor}"
|
31
|
-
end
|
32
|
-
end
|
data/lib/fig/package/install.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'fig/logging'
|
2
|
-
require 'fig/packageerror'
|
3
|
-
require 'fig/package/statement'
|
4
|
-
|
5
|
-
module Fig; end
|
6
|
-
class Fig::Package; end
|
7
|
-
|
8
|
-
# This class appears to be unused, though it is in the grammar.
|
9
|
-
class Fig::Package::Install
|
10
|
-
include Fig::Package::Statement
|
11
|
-
|
12
|
-
def initialize(statements)
|
13
|
-
@statements = statements
|
14
|
-
end
|
15
|
-
|
16
|
-
def unparse(indent)
|
17
|
-
prefix = "\n#{indent}install"
|
18
|
-
body = @statements.map { |statement| statement.unparse(indent+' ') }.join("\n")
|
19
|
-
suffix = "#{indent}end"
|
20
|
-
return [prefix, body, suffix].join("\n")
|
21
|
-
end
|
22
|
-
end
|