fig18 0.1.41 → 0.1.42

Sign up to get free protection for your applications and to get access to all the features.
data/Changes CHANGED
@@ -1,9 +1,19 @@
1
+ v0.1.xx
2
+
3
+ - "file:" protocol works for FIG_REMOTE_HOME.
4
+
5
+ - Testing no longer requires ssh.
6
+
7
+
1
8
  v0.1.41
2
9
 
3
10
  - Release cleanup
4
11
 
12
+
5
13
  v0.1.40
6
14
 
15
+ - Works on Mac (in conjunction with libarchive-static 1.0.1).
16
+
7
17
  - Supports configuration via rc files in JSON format. These can be (in
8
18
  ascending order of priority of values):
9
19
  - in the repository under "_meta/figrc"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.41
1
+ 0.1.42
@@ -2,6 +2,10 @@ require 'stringio'
2
2
 
3
3
  require 'fig/backtrace'
4
4
  require 'fig/logging'
5
+ require 'fig/package/command'
6
+ require 'fig/package/include'
7
+ require 'fig/package/path'
8
+ require 'fig/package/set'
5
9
  require 'fig/repositoryerror'
6
10
 
7
11
  module Fig
@@ -72,13 +76,13 @@ module Fig
72
76
 
73
77
  def apply_config_statement(base_package, statement, backtrace)
74
78
  case statement
75
- when Path
79
+ when Package::Path
76
80
  append_variable(base_package, statement.name, statement.value)
77
- when Set
81
+ when Package::Set
78
82
  set_variable(base_package, statement.name, statement.value)
79
- when Include
83
+ when Package::Include
80
84
  include_config(base_package, statement.package_name, statement.config_name, statement.version_name, statement.overrides, backtrace)
81
- when Command
85
+ when Package::Command
82
86
  # ignore
83
87
  else
84
88
  fail "Unexpected statement: #{statement}"
@@ -1,4 +1,15 @@
1
1
  require 'fig/package'
2
+ require 'fig/package/archive'
3
+ require 'fig/package/command'
4
+ require 'fig/package/configuration'
5
+ require 'fig/package/include'
6
+ require 'fig/package/install'
7
+ require 'fig/package/override'
8
+ require 'fig/package/path'
9
+ require 'fig/package/publish'
10
+ require 'fig/package/resource'
11
+ require 'fig/package/retrieve'
12
+ require 'fig/package/set'
2
13
 
3
14
  module Fig
4
15
 
@@ -6,7 +17,12 @@ grammar Fig
6
17
  rule package
7
18
  ws statements:(package_statement*) {
8
19
  def to_package(package_name, version_name, directory)
9
- Package.new(package_name, version_name, directory, statements.elements.map { |statement| statement.to_package_statement })
20
+ Package.new(
21
+ package_name,
22
+ version_name,
23
+ directory,
24
+ statements.elements.map { |statement| statement.to_package_statement }
25
+ )
10
26
  end
11
27
  }
12
28
  end
@@ -18,7 +34,7 @@ grammar Fig
18
34
  rule archive
19
35
  "archive" ws url {
20
36
  def to_package_statement
21
- Archive.new(url.value.text_value)
37
+ Package::Archive.new(url.value.text_value)
22
38
  end
23
39
  }
24
40
  end
@@ -26,23 +42,31 @@ grammar Fig
26
42
  rule resource
27
43
  "resource" ws url {
28
44
  def to_package_statement
29
- Resource.new(url.value.text_value)
45
+ Package::Resource.new(url.value.text_value)
30
46
  end
31
47
  }
32
48
  end
33
49
 
34
50
  rule retrieve
35
- "retrieve" ws var:[@a-zA-Z0-9/\._]+ "->" path:[a-zA-Z0-9_/\.\-\[\]]+ ws {
51
+ "retrieve" ws var:retrieve_variable "->" path:retrieve_path ws {
36
52
  def to_package_statement
37
- Retrieve.new(var.text_value, path.text_value)
53
+ Package::Retrieve.new(var.text_value, path.text_value)
38
54
  end
39
55
  }
40
56
  end
41
57
 
58
+ rule retrieve_variable
59
+ [@a-zA-Z0-9/._]+
60
+ end
61
+
62
+ rule retrieve_path
63
+ [a-zA-Z0-9_/.\[\]-]+
64
+ end
65
+
42
66
  rule install
43
67
  "install" ws statements:config_statement* "end" ws {
44
68
  def to_package_statement
45
- Install.new(statements.elements.map { |statement| statement.to_config_statement })
69
+ Package::Install.new(statements.elements.map { |statement| statement.to_config_statement })
46
70
  end
47
71
  }
48
72
  end
@@ -50,7 +74,7 @@ grammar Fig
50
74
  rule config
51
75
  "config" ws config_name ws statements:config_statement* "end" ws {
52
76
  def to_package_statement
53
- Configuration.new(config_name.text_value, statements.elements.map { |statement| statement.to_config_statement })
77
+ Package::Configuration.new(config_name.text_value, statements.elements.map { |statement| statement.to_config_statement })
54
78
  end
55
79
  }
56
80
  end
@@ -65,7 +89,7 @@ grammar Fig
65
89
  package = descriptor.respond_to?(:package) ? descriptor.package.text_value : nil
66
90
  config = descriptor.get_config
67
91
  version = descriptor.get_version
68
- Include.new(package, config, version, overrides.elements.map{ |e| e.to_override })
92
+ Package::Include.new(package, config, version, overrides.elements.map{ |e| e.to_override })
69
93
  end
70
94
  }
71
95
  end
@@ -73,31 +97,47 @@ grammar Fig
73
97
  rule override
74
98
  "override" ws package_name "/" version_name ws {
75
99
  def to_override
76
- return Override.new(package_name.text_value, version_name.text_value)
100
+ return Package::Override.new(package_name.text_value, version_name.text_value)
77
101
  end
78
102
  }
79
103
  end
80
104
 
81
105
  rule path
82
- ("append" / "path" / "add") ws name:[a-zA-Z0-9_]+ "=" value:[@a-zA-Z0-9/\-\\._]+ ws {
106
+ ("append" / "path" / "add") ws name:path_name "=" value:path_value ws {
83
107
  def to_config_statement
84
- Path.new(name.text_value, value.text_value)
108
+ Package::Path.new(name.text_value, value.text_value)
85
109
  end
86
110
  }
87
111
  end
88
112
 
113
+ rule path_name
114
+ [a-zA-Z0-9_]+
115
+ end
116
+
117
+ rule path_value
118
+ [@a-zA-Z0-9/\\._-]+
119
+ end
120
+
89
121
  rule set
90
- "set" ws name:[a-zA-Z0-9_]+ "=" value:[@a-zA-Z0-9/\-\\._]+ ws {
122
+ "set" ws name:set_name "=" value:set_value ws {
91
123
  def to_config_statement
92
- Set.new(name.text_value, value.text_value)
124
+ Package::Set.new(name.text_value, value.text_value)
93
125
  end
94
126
  }
95
127
  end
96
128
 
129
+ rule set_name
130
+ [a-zA-Z0-9_]+
131
+ end
132
+
133
+ rule set_value
134
+ [@a-zA-Z0-9/\\._-]+
135
+ end
136
+
97
137
  rule command
98
138
  "command" ws string {
99
139
  def to_config_statement
100
- Command.new(string.value.text_value)
140
+ Package::Command.new(string.value.text_value)
101
141
  end
102
142
  }
103
143
  end
@@ -134,11 +174,11 @@ grammar Fig
134
174
  end
135
175
 
136
176
  rule version_name
137
- [a-zA-Z0-9_\-.]+
177
+ [a-zA-Z0-9_.-]+
138
178
  end
139
179
 
140
180
  rule config_name
141
- [a-zA-Z0-9_\-.]+
181
+ [a-zA-Z0-9_.-]+
142
182
  end
143
183
 
144
184
  rule name
@@ -146,7 +186,7 @@ grammar Fig
146
186
  end
147
187
 
148
188
  rule url
149
- (value:[a-zA-Z0-9:/\-\\._\*]+ ws) / ('"' value:[a-zA-Z0-9:/\-\\._]+ '"' ws)
189
+ (value:[a-zA-Z0-9:/\\._*-]+ ws) / ('"' value:[a-zA-Z0-9:/\\._-]+ '"' ws)
150
190
  end
151
191
 
152
192
  rule ws
data/lib/fig/options.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'optparse'
2
2
  require 'fig/package'
3
+ require 'fig/package/archive'
4
+ require 'fig/package/include'
5
+ require 'fig/package/path'
6
+ require 'fig/package/resource'
7
+ require 'fig/package/set'
3
8
 
4
9
  module Fig
5
10
  def parse_descriptor(descriptor)
@@ -66,7 +71,7 @@ EOF
66
71
  'append (actually, prepend) VAL to environment var VAR, delimited by separator'
67
72
  ) do |var_val|
68
73
  var, val = var_val.split('=')
69
- options[:modifiers] << Path.new(var, val)
74
+ options[:modifiers] << Package::Path.new(var, val)
70
75
  end
71
76
 
72
77
  options[:archives] = []
@@ -74,7 +79,7 @@ EOF
74
79
  '--archive FULLPATH',
75
80
  'include FULLPATH archive in package (when using --publish)'
76
81
  ) do |path|
77
- options[:archives] << Archive.new(path)
82
+ options[:archives] << Package::Archive.new(path)
78
83
  end
79
84
 
80
85
  options[:cleans] = []
@@ -127,7 +132,7 @@ EOF
127
132
  'include PKG (with any variable prepends) in environment'
128
133
  ) do |descriptor|
129
134
  package_name, config_name, version_name = parse_descriptor(descriptor)
130
- options[:modifiers] << Include.new(package_name, config_name, version_name, {})
135
+ options[:modifiers] << Package::Include.new(package_name, config_name, version_name, {})
131
136
  end
132
137
 
133
138
  options[:list] = false
@@ -179,14 +184,14 @@ EOF
179
184
  '--resource FULLPATH',
180
185
  'include FULLPATH resource in package (when using --publish)'
181
186
  ) do |path|
182
- options[:resources] << Resource.new(path)
187
+ options[:resources] << Package::Resource.new(path)
183
188
  end
184
189
 
185
190
  opts.on(
186
191
  '-s', '--set VAR=VAL', 'set environment variable VAR to VAL'
187
192
  ) do |var_val|
188
193
  var, val = var_val.split('=')
189
- options[:modifiers] << Set.new(var, val)
194
+ options[:modifiers] << Package::Set.new(var, val)
190
195
  end
191
196
 
192
197
  options[:update] = false
data/lib/fig/os.rb CHANGED
@@ -68,12 +68,22 @@ module Fig
68
68
  NOT_MODIFIED = 3
69
69
  NOT_FOUND = 4
70
70
 
71
+ def strip_paths_for_list(ls_output, packages, path)
72
+ if not ls_output.nil?
73
+ ls_output = ls_output.gsub(path + '/', '').gsub(path, '').split("\n")
74
+ ls_output.each do |line|
75
+ parts = line.gsub(/\\/, '/').sub(/^\.\//, '').sub(/:$/, '').chomp().split('/')
76
+ packages << parts.join('/') if parts.size == 2
77
+ end
78
+ end
79
+ end
80
+
71
81
  def download_list(url)
72
82
  begin
73
83
  uri = URI.parse(url)
74
84
  rescue
75
85
  Logging.fatal %Q<Unable to parse url: "#{url}">
76
- raise NetworkError.new
86
+ raise NetworkError.new(%Q<Unable to parse url: "#{url}">)
77
87
  end
78
88
  case uri.scheme
79
89
  when 'ftp'
@@ -88,18 +98,17 @@ module Fig
88
98
  packages = []
89
99
  Net::SSH.start(uri.host, uri.user) do |ssh|
90
100
  ls = ssh.exec!("[ -d #{uri.path} ] && find #{uri.path}")
91
- if not ls.nil?
92
- ls = ls.gsub(uri.path + '/', '').gsub(uri.path, '').split("\n")
93
- ls.each do |line|
94
- parts = line.gsub(/\\/, '/').sub(/^\.\//, '').sub(/:$/, '').chomp().split('/')
95
- packages << parts.join('/') if parts.size == 2
96
- end
97
- end
101
+ strip_paths_for_list(ls, packages, uri.path)
98
102
  end
99
103
  packages
104
+ when 'file'
105
+ packages = []
106
+ ls = %x<[ -d #{uri.path} ] && find #{uri.path}>
107
+ strip_paths_for_list(ls, packages, uri.path)
108
+ return packages
100
109
  else
101
110
  Logging.fatal "Protocol not supported: #{url}"
102
- raise NetworkError.new
111
+ raise NetworkError.new("Protocol not supported: #{url}")
103
112
  end
104
113
  end
105
114
 
@@ -170,9 +179,15 @@ module Fig
170
179
  cmd = `which fig-download`.strip + " #{timestamp} #{uri.path}"
171
180
  log_download(url, path)
172
181
  ssh_download(uri.user, uri.host, path, cmd)
182
+ when 'file'
183
+ begin
184
+ FileUtils.cp(uri.path, path)
185
+ rescue Errno::ENOENT => e
186
+ raise NotFoundError.new
187
+ end
173
188
  else
174
189
  Logging.fatal "Unknown protocol: #{url}"
175
- raise NetworkError.new
190
+ raise NetworkError.new("Unknown protocol: #{url}")
176
191
  end
177
192
  end
178
193
 
@@ -197,7 +212,7 @@ module Fig
197
212
  unpack_archive(dir, path)
198
213
  else
199
214
  Logging.fatal "Unknown archive type: #{basename}"
200
- raise NetworkError.new
215
+ raise NetworkError.new("Unknown archive type: #{basename}")
201
216
  end
202
217
  end
203
218
 
@@ -233,6 +248,12 @@ module Fig
233
248
  end
234
249
  ftp.putbinaryfile(local_file)
235
250
  end
251
+ when 'file'
252
+ FileUtils.mkdir_p(File.dirname(uri.path))
253
+ FileUtils.cp(local_file, uri.path)
254
+ else
255
+ Logging.fatal "Unknown protocol: #{uri}"
256
+ raise NetworkError.new("Unknown protocol: #{uri}")
236
257
  end
237
258
  end
238
259
 
@@ -371,7 +392,7 @@ module Fig
371
392
  else
372
393
  tempfile.delete
373
394
  Logging.fatal "Unable to download file #{path}: #{return_code}"
374
- raise NetworkError.new
395
+ raise NetworkError.new("Unable to download file #{path}: #{return_code}")
375
396
  end
376
397
  end
377
398
 
@@ -0,0 +1,24 @@
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
+ class Fig::Package::Archive
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :url
12
+
13
+ def initialize(url)
14
+ @url = url
15
+ end
16
+
17
+ def urls
18
+ return [@url]
19
+ end
20
+
21
+ def unparse(indent)
22
+ %Q<#{indent}archive "#{url}">
23
+ end
24
+ end
@@ -0,0 +1,20 @@
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
+ class Fig::Package::Command
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :command
12
+
13
+ def initialize(command)
14
+ @command = command
15
+ end
16
+
17
+ def unparse(indent)
18
+ %Q<#{indent}command "#{@command}">
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/command'
4
+ require 'fig/package/statement'
5
+
6
+ module Fig; end
7
+ class Fig::Package; end
8
+
9
+ class Fig::Package::Configuration
10
+ include Fig::Package::Statement
11
+
12
+ attr_reader :name, :statements
13
+
14
+ def initialize(name, statements)
15
+ @name = name
16
+ @statements = statements
17
+ end
18
+
19
+ def with_name(name)
20
+ Configuration.new(name, statements)
21
+ end
22
+
23
+ def commands
24
+ result = statements.select do
25
+ |statement| statement.is_a?(Fig::Package::Command)
26
+ end
27
+ result
28
+ end
29
+
30
+ def walk_statements(&block)
31
+ @statements.each do |statement|
32
+ yield statement
33
+ statement.walk_statements &block
34
+ end
35
+ end
36
+
37
+ def unparse(indent)
38
+ unparse_statements(indent, "config #{@name}", @statements, 'end')
39
+ end
40
+ end
@@ -0,0 +1,30 @@
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
+ class Fig::Package::Include
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :package_name, :config_name, :version_name, :overrides
12
+
13
+ def initialize(package_name, config_name, version_name, overrides)
14
+ @package_name = package_name
15
+ @config_name = config_name
16
+ @version_name = version_name
17
+ @overrides = overrides
18
+ end
19
+
20
+ def unparse(indent)
21
+ descriptor = ''
22
+ descriptor += @package_name if @package_name
23
+ descriptor += "/#{@version_name}" if @version_name
24
+ descriptor += ":#{@config_name}" if @config_name
25
+ @overrides.each do |override|
26
+ descriptor += override.unparse
27
+ end
28
+ return "#{indent}include #{descriptor}"
29
+ end
30
+ end
@@ -0,0 +1,21 @@
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
+ class Fig::Package::Install
9
+ include Fig::Package::Statement
10
+
11
+ def initialize(statements)
12
+ @statements = statements
13
+ end
14
+
15
+ def unparse(indent)
16
+ prefix = "\n#{indent}install"
17
+ body = @statements.map { |statement| statement.unparse(indent+' ') }.join("\n")
18
+ suffix = "#{indent}end"
19
+ return [prefix, body, suffix].join("\n")
20
+ end
21
+ end
@@ -0,0 +1,21 @@
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
+ class Fig::Package::Override
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :package_name, :version_name
12
+
13
+ def initialize(package_name, version_name)
14
+ @package_name = package_name
15
+ @version_name = version_name
16
+ end
17
+
18
+ def unparse()
19
+ return ' override ' + @package_name + '/' + @version_name
20
+ end
21
+ end
@@ -0,0 +1,21 @@
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
+ class Fig::Package::Path
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :name, :value
12
+
13
+ def initialize(name, value)
14
+ @name = name
15
+ @value = value
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}append #{name}=#{value}"
20
+ end
21
+ end
@@ -0,0 +1,21 @@
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
+ class Fig::Package::Publish
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :local_name, :remote_name
12
+
13
+ def initialize(local_name, remote_name)
14
+ @local_name = local_name
15
+ @remote_name = remote_name
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}publish #{@local_name}->#{@remote_name}"
20
+ end
21
+ end
@@ -0,0 +1,24 @@
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
+ class Fig::Package::Resource
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :url
12
+
13
+ def initialize(url)
14
+ @url = url
15
+ end
16
+
17
+ def urls
18
+ return [@url]
19
+ end
20
+
21
+ def unparse(indent)
22
+ "#{indent}resource #{url}"
23
+ end
24
+ end
@@ -0,0 +1,21 @@
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
+ class Fig::Package::Retrieve
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :var, :path
12
+
13
+ def initialize(var, path)
14
+ @var = var
15
+ @path = path
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}retrieve #{var}->#{path}"
20
+ end
21
+ end
@@ -0,0 +1,21 @@
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
+ class Fig::Package::Set
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :name, :value
12
+
13
+ def initialize(name, value)
14
+ @name = name
15
+ @value = value
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}set #{name}=#{value}"
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Fig; end
2
+ class Fig::Package; end
3
+
4
+ module Fig::Package::Statement
5
+ def walk_statements(&block)
6
+ return
7
+ end
8
+
9
+ def urls
10
+ return []
11
+ end
12
+ end