fig 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,7 +71,7 @@ grammar Fig
71
71
  end
72
72
 
73
73
  rule path
74
- ("append" / "path" / "add") ws name:[a-zA-Z0-9]+ "=" value:[@a-zA-Z0-9/\-\\._]+ ws {
74
+ ("append" / "path" / "add") ws name:[a-zA-Z0-9_]+ "=" value:[@a-zA-Z0-9/\-\\._]+ ws {
75
75
  def to_config_statement
76
76
  Path.new(name.text_value, value.text_value)
77
77
  end
@@ -79,7 +79,7 @@ grammar Fig
79
79
  end
80
80
 
81
81
  rule set
82
- "set" ws name:[a-zA-Z0-9]+ "=" value:[@a-zA-Z0-9/\-\\._]+ ws {
82
+ "set" ws name:[a-zA-Z0-9_]+ "=" value:[@a-zA-Z0-9/\-\\._]+ ws {
83
83
  def to_config_statement
84
84
  Set.new(name.text_value, value.text_value)
85
85
  end
@@ -122,7 +122,7 @@ grammar Fig
122
122
  end
123
123
 
124
124
  rule config_name
125
- [a-zA-Z0-9_\-]+
125
+ [a-zA-Z0-9_\-.]+
126
126
  end
127
127
 
128
128
  rule name
data/lib/fig/os.rb CHANGED
@@ -4,192 +4,199 @@ require 'net/http'
4
4
  require 'tempfile'
5
5
 
6
6
  module Fig
7
- class OS
8
- def list(dir)
9
- Dir.entries(dir) - ['.','..']
10
- end
11
-
12
- def exist?(path)
13
- File.exist?(path)
14
- end
15
-
16
- def mtime(path)
17
- File.mtime(path)
18
- end
19
-
20
- def read(path)
21
- File.read(path)
22
- end
23
-
24
- def write(path, content)
25
- File.open(path, "w") { |f| f << content }
26
- end
7
+ class NotFoundException < Exception
8
+ end
27
9
 
28
- SUCCESS = 0
29
- NOT_MODIFIED = 3
30
- NOT_FOUND = 4
31
-
32
- def download_list(url)
33
- uri = URI.parse(url)
34
- case uri.scheme
35
- when "ftp"
36
- ftp = Net::FTP.new(uri.host)
37
- ftp.login
38
- dirs = []
39
- ftp.list("-1 " + uri.path) do |line|
40
- dirs << line
41
- end
42
- packages = []
43
- dirs.each do |dir|
44
- ftp.list("-1 #{uri.path}/#{dir}") do |line|
45
- packages << "#{dir}/#{line}"
46
- end
47
- end
48
- packages
49
- else
50
- raise "Protocol not supported: #{url}"
10
+ class OS
11
+ def list(dir)
12
+ Dir.entries(dir) - ['.','..']
51
13
  end
14
+
15
+ def exist?(path)
16
+ File.exist?(path)
17
+ end
18
+
19
+ def mtime(path)
20
+ File.mtime(path)
21
+ end
22
+
23
+ def read(path)
24
+ File.read(path)
25
+ end
26
+
27
+ def write(path, content)
28
+ File.open(path, "w") { |f| f << content }
29
+ end
30
+
31
+ SUCCESS = 0
32
+ NOT_MODIFIED = 3
33
+ NOT_FOUND = 4
34
+
35
+ def download_list(url)
36
+ uri = URI.parse(url)
37
+ case uri.scheme
38
+ when "ftp"
39
+ ftp = Net::FTP.new(uri.host)
40
+ ftp.login
41
+ dirs = []
42
+ ftp.list("-1 " + uri.path) do |line|
43
+ dirs << line
44
+ end
45
+ packages = []
46
+ dirs.each do |dir|
47
+ ftp.list("-1 #{uri.path}/#{dir}") do |line|
48
+ packages << "#{dir}/#{line}"
49
+ end
50
+ end
51
+ packages
52
+ else
53
+ raise "Protocol not supported: #{url}"
54
+ end
55
+ end
56
+
57
+ def download(url, path)
58
+ FileUtils.mkdir_p(File.dirname(path))
59
+ uri = URI.parse(url)
60
+ case uri.scheme
61
+ when "ftp"
62
+ ftp = Net::FTP.new(uri.host)
63
+ ftp.login
64
+ begin
65
+ if File.exist?(path) && ftp.mtime(uri.path) <= File.mtime(path)
66
+ return false
67
+ else
68
+ puts "downloading #{url}"
69
+ ftp.getbinaryfile(uri.path, path, 256*1024)
70
+ return true
71
+ end
72
+ rescue Net::FTPPermError
73
+ raise NotFoundException.new
74
+ end
75
+ when "http"
76
+ http = Net::HTTP.new(uri.host)
77
+ puts "downloading #{url}"
78
+ File.open(path, "w") do |file|
79
+ http.get(uri.path) do |block|
80
+ file.write(block)
81
+ end
82
+ end
83
+ when "ssh"
84
+ # TODO need better way to do conditional download
85
+ # timestamp = `ssh #{uri.user + '@' if uri.user}#{uri.host} "ruby -e 'puts File.mtime(\\"#{uri.path}\\").to_i'"`.to_i
86
+ out = nil
87
+ timestamp = File.exist?(path) ? File.mtime(path).to_i : 0
88
+ tempfile = Tempfile.new("tmp")
89
+ IO.popen("ssh #{uri.user + '@' if uri.user}#{uri.host} \"fig-download #{timestamp} #{uri.path}\"") do |io|
90
+ first = true
91
+ while bytes = io.read(4096)
92
+ if first
93
+ $stderr.puts "downloading #{url}"
94
+ first = false
95
+ end
96
+ tempfile << bytes
97
+ end
98
+ end
99
+ tempfile.close
100
+ case $?.exitstatus
101
+ when NOT_MODIFIED
102
+ tempfile.delete
103
+ return false
104
+ when NOT_FOUND
105
+ tempfile.delete
106
+ raise "File not found: #{uri}"
107
+ when SUCCESS
108
+ FileUtils.mv(tempfile.path, path)
109
+ return true
110
+ else
111
+ tempfile.delete
112
+ $stderr.puts "Unable to download file: #{$?.exitstatus}"
113
+ exit 1
114
+ end
115
+ else
116
+ raise "Unknown protocol: #{url}"
117
+ end
52
118
  end
53
-
54
- def download(url, path)
55
- FileUtils.mkdir_p(File.dirname(path))
56
- uri = URI.parse(url)
57
- case uri.scheme
58
- when "ftp"
59
- ftp = Net::FTP.new(uri.host)
60
- ftp.login
61
- if File.exist?(path) && ftp.mtime(uri.path) <= File.mtime(path)
62
- return false
63
- else
64
- puts "downloading #{url}"
65
- ftp.getbinaryfile(uri.path, path, 256*1024)
66
- return true
67
- end
68
- when "http"
69
- http = Net::HTTP.new(uri.host)
70
- puts "downloading #{url}"
71
- File.open(path, "w") do |file|
72
- http.get(uri.path) do |block|
73
- file.write(block)
74
- end
75
- end
76
- when "ssh"
77
- # TODO need better way to do conditional download
78
- # timestamp = `ssh #{uri.user + '@' if uri.user}#{uri.host} "ruby -e 'puts File.mtime(\\"#{uri.path}\\").to_i'"`.to_i
79
- out = nil
80
- timestamp = File.exist?(path) ? File.mtime(path).to_i : 0
81
- tempfile = Tempfile.new("tmp")
82
- IO.popen("ssh #{uri.user + '@' if uri.user}#{uri.host} \"fig-download #{timestamp} #{uri.path}\"") do |io|
83
- first = true
84
- while bytes = io.read(4096)
85
- if first
86
- $stderr.puts "downloading #{url}"
87
- first = false
88
- end
89
- tempfile << bytes
90
- end
91
- end
92
- tempfile.close
93
- case $?.exitstatus
94
- when NOT_MODIFIED
95
- tempfile.delete
96
- return false
97
- when NOT_FOUND
98
- tempfile.delete
99
- raise "File not found: #{uri}"
100
- when SUCCESS
101
- FileUtils.mv(tempfile.path, path)
102
- return true
103
- else
104
- tempfile.delete
105
- $stderr.puts "Unable to download file: #{$?.exitstatus}"
106
- exit 1
107
- end
108
- else
109
- raise "Unknown protocol: #{url}"
110
- end
111
- end
112
-
113
- def download_resource(url, dir)
114
- FileUtils.mkdir_p(dir)
115
- download(url, File.join(dir, URI.parse(url).path.split('/').last))
116
- end
117
-
118
- def download_archive(url, dir)
119
- FileUtils.mkdir_p(dir)
120
- basename = URI.parse(url).path.split('/').last
121
- path = File.join(dir, basename)
122
- download(url, path)
123
- case basename
124
- when /\.tar\.gz$/
125
- fail unless system "tar -C #{dir} -zxf #{path}"
119
+
120
+ def download_resource(url, dir)
121
+ FileUtils.mkdir_p(dir)
122
+ download(url, File.join(dir, URI.parse(url).path.split('/').last))
123
+ end
124
+
125
+ def download_archive(url, dir)
126
+ FileUtils.mkdir_p(dir)
127
+ basename = URI.parse(url).path.split('/').last
128
+ path = File.join(dir, basename)
129
+ download(url, path)
130
+ case basename
131
+ when /\.tar\.gz$/
132
+ fail unless system "tar -C #{dir} -zxf #{path}"
126
133
  when /\.tgz$/
127
- fail unless system "tar -C #{dir} -zxf #{path}"
128
- when /\.tar\.bz2$/
129
- fail unless system "tar -C #{dir} -jxf #{path}"
130
- when /\.zip$/
131
- fail unless system "unzip -q -d #{dir} #{path}"
132
- else
133
- raise "Unknown archive type: #{basename}"
134
- end
135
- end
136
-
137
- def upload(local_file, remote_file, user)
138
- puts "uploading #{local_file} to #{remote_file}"
139
- uri = URI.parse(remote_file)
140
- case uri.scheme
141
- when "ssh"
142
- dir = uri.path[0, uri.path.rindex('/')]
134
+ fail unless system "tar -C #{dir} -zxf #{path}"
135
+ when /\.tar\.bz2$/
136
+ fail unless system "tar -C #{dir} -jxf #{path}"
137
+ when /\.zip$/
138
+ fail unless system "unzip -q -d #{dir} #{path}"
139
+ else
140
+ raise "Unknown archive type: #{basename}"
141
+ end
142
+ end
143
+
144
+ def upload(local_file, remote_file, user)
145
+ puts "uploading #{local_file} to #{remote_file}"
146
+ uri = URI.parse(remote_file)
147
+ case uri.scheme
148
+ when "ssh"
149
+ dir = uri.path[0, uri.path.rindex('/')]
143
150
  cmd = "mkdir -p #{dir} && cat > #{uri.path}"
144
- fail unless system "cat #{local_file} | ssh #{uri.user + '@' if uri.user}#{uri.host} '#{cmd}'"
145
- when "ftp"
146
- # fail unless system "curl -T #{local_file} --create-dirs --ftp-create-dirs #{remote_file}"
151
+ fail unless system "cat #{local_file} | ssh #{uri.user + '@' if uri.user}#{uri.host} '#{cmd}'"
152
+ when "ftp"
153
+ # fail unless system "curl -T #{local_file} --create-dirs --ftp-create-dirs #{remote_file}"
147
154
  require 'net/ftp'
148
- ftp_uri = URI.parse(ENV["FIG_REMOTE_URL"])
149
- ftp_root_path = ftp_uri.path
150
- ftp_root_dirs = ftp_uri.path.split("/")
151
- remote_publish_path = uri.path[0, uri.path.rindex("/")]
152
- remote_publish_dirs = remote_publish_path.split("/")
153
- # Use array subtraction to deduce which project/version folder to upload to,
154
- # i.e. [1,2,3] - [2,3,4] = [1]
155
- remote_project_dirs = remote_publish_dirs - ftp_root_dirs
156
- Net::FTP.open(uri.host) do |ftp|
157
- ftp.login
158
- # Assume that the FIG_REMOTE_URL path exists.
159
- ftp.chdir(ftp_root_path)
160
- remote_project_dirs.each do |dir|
161
- # Can't automatically create parent directories, so do it manually.
155
+ ftp_uri = URI.parse(ENV["FIG_REMOTE_URL"])
156
+ ftp_root_path = ftp_uri.path
157
+ ftp_root_dirs = ftp_uri.path.split("/")
158
+ remote_publish_path = uri.path[0, uri.path.rindex("/")]
159
+ remote_publish_dirs = remote_publish_path.split("/")
160
+ # Use array subtraction to deduce which project/version folder to upload to,
161
+ # i.e. [1,2,3] - [2,3,4] = [1]
162
+ remote_project_dirs = remote_publish_dirs - ftp_root_dirs
163
+ Net::FTP.open(uri.host) do |ftp|
164
+ ftp.login
165
+ # Assume that the FIG_REMOTE_URL path exists.
166
+ ftp.chdir(ftp_root_path)
167
+ remote_project_dirs.each do |dir|
168
+ # Can't automatically create parent directories, so do it manually.
162
169
  if ftp.nlst().index(dir).nil?
163
170
  ftp.mkdir(dir)
164
171
  ftp.chdir(dir)
165
172
  else
166
173
  ftp.chdir(dir)
167
174
  end
168
- end
169
- ftp.putbinaryfile(local_file)
170
- end
171
- else
172
- fail unless system "curl -p -T #{local_file} --create-dirs --ftp-create-dirs #{remote_file}"
173
- end
174
- end
175
-
176
- def clear_directory(dir)
177
- FileUtils.rm_rf(dir)
178
- FileUtils.mkdir_p(dir)
179
- end
180
-
181
- def exec(dir,command)
182
- Dir.chdir(dir) { raise "Command failed" unless system command }
183
- end
184
-
185
- def copy(source, target)
186
- FileUtils.mkdir_p(File.dirname(target))
187
- FileUtils.copy_file(source, target)
188
- target
189
- end
175
+ end
176
+ ftp.putbinaryfile(local_file)
177
+ end
178
+ else
179
+ fail unless system "curl -p -T #{local_file} --create-dirs --ftp-create-dirs #{remote_file}"
180
+ end
181
+ end
182
+
183
+ def clear_directory(dir)
184
+ FileUtils.rm_rf(dir)
185
+ FileUtils.mkdir_p(dir)
186
+ end
190
187
 
191
- def log_info(msg)
192
- puts msg
188
+ def exec(dir,command)
189
+ Dir.chdir(dir) { raise "Command failed" unless system command }
193
190
  end
194
- end
191
+
192
+ def copy(source, target)
193
+ FileUtils.mkdir_p(File.dirname(target))
194
+ FileUtils.copy_file(source, target)
195
+ target
196
+ end
197
+
198
+ def log_info(msg)
199
+ puts msg
200
+ end
201
+ end
195
202
  end
@@ -88,6 +88,7 @@ module Fig
88
88
  file = "resources.tar.gz"
89
89
  file unless system "tar -zcf #{file} #{resources.join(' ')}"
90
90
  new_package_statements.unshift(Archive.new(file))
91
+ at_exit { File.delete(file) }
91
92
  end
92
93
  new_package_statements
93
94
  end
@@ -102,8 +103,13 @@ module Fig
102
103
  def update_package(package_name, version_name)
103
104
  remote_fig_file = remote_fig_file_for_package(package_name, version_name)
104
105
  local_fig_file = local_fig_file_for_package(package_name, version_name)
105
- if @os.download(remote_fig_file, local_fig_file)
106
- install_package(package_name, version_name)
106
+ begin
107
+ if @os.download(remote_fig_file, local_fig_file)
108
+ install_package(package_name, version_name)
109
+ end
110
+ rescue NotFoundException
111
+ $stderr.puts "Package not found in remote repository: #{package_name}/#{version_name}"
112
+ exit 1
107
113
  end
108
114
  end
109
115
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Foemmel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-22 00:00:00 -06:00
12
+ date: 2010-01-27 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency