fig 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fig CHANGED
@@ -39,7 +39,7 @@ vars = {}
39
39
  ENV.each {|key,value| vars[key]=value }
40
40
 
41
41
  remote_url = nil
42
- if options[:update] || options[:publish] || options[:update_if_missing]
42
+ if options[:update] || options[:publish] || options[:update_if_missing] || options[:list_remote]
43
43
  remote_url = ENV['FIG_REMOTE_URL']
44
44
  if remote_url.nil?
45
45
  $stderr.puts "Please define the FIG_REMOTE_URL environment variable"
@@ -92,6 +92,30 @@ options[:cleans].each do |descriptor|
92
92
  repos.clean(package_name, version_name)
93
93
  end
94
94
 
95
+ if options[:list]
96
+ repos.list_packages.sort.each do |item|
97
+ puts item
98
+ end
99
+ exit 0
100
+ end
101
+
102
+ if options[:list_remote]
103
+ repos.list_remote_packages.sort.each do |item|
104
+ puts item
105
+ end
106
+ exit 0
107
+ end
108
+
109
+ if not options[:list_configs].empty?
110
+ options[:list_configs].each do |descriptor|
111
+ package_name, version_name = descriptor.split('/')
112
+ repos.read_local_package(package_name, version_name).configs.each do |config|
113
+ puts config.name
114
+ end
115
+ end
116
+ exit 0
117
+ end
118
+
95
119
  if input
96
120
  package = Parser.new.parse_package(nil, nil, ".", input)
97
121
  if options[:retrieve]
@@ -107,13 +131,6 @@ else
107
131
  package = Package.new(nil, nil, ".", [])
108
132
  end
109
133
 
110
- if options[:list]
111
- repos.list_packages.sort.each do |item|
112
- puts item
113
- end
114
- exit 0
115
- end
116
-
117
134
  def shell_exec(cmd)
118
135
  exec(ENV['SHELL'], '-c', cmd.join(' '))
119
136
  end
@@ -141,8 +158,8 @@ elsif shell_command
141
158
  elsif argv[0]
142
159
  package_name, config_name, version_name = parse_descriptor(argv.shift)
143
160
  env.include_config(package, package_name, config_name, version_name)
144
- env.execute_config(package, package_name, config_name, nil) { |cmd| shell_exec cmd }
161
+ env.execute_config(package, package_name, config_name, nil, argv) { |cmd| shell_exec cmd }
145
162
  elsif input
146
- env.execute_config(package, nil, options[:config], nil) { |cmd| shell_exec cmd }
163
+ env.execute_config(package, nil, options[:config], nil, argv) { |cmd| shell_exec cmd }
147
164
  end
148
165
 
@@ -41,14 +41,14 @@ module Fig
41
41
  end
42
42
  end
43
43
 
44
- def execute_config(base_package, package_name, config_name, version_name)
44
+ def execute_config(base_package, package_name, config_name, version_name, args)
45
45
  package = lookup_package(package_name || base_package.package_name, version_name)
46
46
  result = nil
47
47
  commands = package[config_name || "default"].commands
48
48
  with_environment do
49
49
  # todo nil check
50
50
  commands.each do |command|
51
- result = yield expand_arg(command.command).gsub("@",package.directory).split(" ")
51
+ result = yield expand_arg("#{command.command} #{args.join(' ')}").gsub("@",package.directory).split(" ")
52
52
  end
53
53
  end
54
54
  result
@@ -12,7 +12,7 @@ grammar Fig
12
12
  end
13
13
 
14
14
  rule package_statement
15
- archive / resource / retrieve / config / publish
15
+ archive / resource / retrieve / config
16
16
  end
17
17
 
18
18
  rule archive
@@ -39,23 +39,6 @@ grammar Fig
39
39
  }
40
40
  end
41
41
 
42
- rule publish
43
- "publish" ws local_name:config_name ("->" remote_name:config_name)? ws {
44
- def to_package_statement
45
- Publish.new(local_name.text_value, get_remote_name)
46
- end
47
-
48
- def get_remote_name
49
- elements.each do |element|
50
- if element.respond_to?(:remote_name)
51
- return element.remote_name.text_value
52
- end
53
- end
54
- local_name.text_value
55
- end
56
- }
57
- end
58
-
59
42
  rule install
60
43
  "install" ws statements:config_statement* "end" ws {
61
44
  def to_package_statement
data/lib/fig/options.rb CHANGED
@@ -52,6 +52,12 @@ module Fig
52
52
  options[:list] = false
53
53
  opts.on('--list', 'list packages in local repository') { options[:list] = true }
54
54
 
55
+ options[:list_remote] = false
56
+ opts.on('--list-remote', 'list packages in remote repository') { options[:list_remote] = true }
57
+
58
+ options[:list_configs] = []
59
+ opts.on('--list-configs PKG', 'list configurations in package') { |descriptor| options[:list_configs] << descriptor }
60
+
55
61
  options[:cleans] = []
56
62
  opts.on('--clean PKG', 'remove package from local repository') { |descriptor| options[:cleans] << descriptor }
57
63
 
data/lib/fig/os.rb CHANGED
@@ -29,6 +29,28 @@ module Fig
29
29
  NOT_MODIFIED = 3
30
30
  NOT_FOUND = 4
31
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}"
51
+ end
52
+ end
53
+
32
54
  def download(url, path)
33
55
  FileUtils.mkdir_p(File.dirname(path))
34
56
  uri = URI.parse(url)
@@ -115,10 +137,37 @@ module Fig
115
137
  def upload(local_file, remote_file, user)
116
138
  puts "uploading #{local_file} to #{remote_file}"
117
139
  uri = URI.parse(remote_file)
118
- if uri.scheme == "ssh"
140
+ case uri.scheme
141
+ when "ssh"
119
142
  dir = uri.path[0, uri.path.rindex('/')]
120
143
  cmd = "mkdir -p #{dir} && cat > #{uri.path}"
121
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}"
147
+ 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.
162
+ if ftp.nlst().index(dir).nil?
163
+ ftp.mkdir(dir)
164
+ ftp.chdir(dir)
165
+ else
166
+ ftp.chdir(dir)
167
+ end
168
+ end
169
+ ftp.putbinaryfile(local_file)
170
+ end
122
171
  else
123
172
  fail unless system "curl -p -T #{local_file} --create-dirs --ftp-create-dirs #{remote_file}"
124
173
  end
data/lib/fig/package.rb CHANGED
@@ -16,11 +16,16 @@ module Fig
16
16
  raise "Configuration not found: #{@package_name}/#{@version_name}:#{config_name}"
17
17
  end
18
18
 
19
+ def configs
20
+ @statements.select { |statement| statement.is_a?(Configuration) }
21
+ end
22
+
19
23
  def retrieves
20
24
  retrieves = {}
21
25
  statements.each { |statement| retrieves[statement.var] = statement.path if statement.is_a?(Retrieve) }
22
26
  retrieves
23
27
  end
28
+
24
29
  def archive_urls
25
30
  @statements.select{|s| s.is_a?(Archive)}.map{|s|s.url}
26
31
  end
@@ -10,6 +10,14 @@ module Fig
10
10
  @update = update
11
11
  @update_if_missing = update_if_missing
12
12
  @parser = Parser.new
13
+
14
+ @overrides = {}
15
+ if File.exist?('fig.properties')
16
+ File.readlines('fig.properties').each do |line|
17
+ descriptor, path = line.strip.split('=')
18
+ @overrides[descriptor] = path
19
+ end
20
+ end
13
21
  end
14
22
 
15
23
  def clean(package_name, version_name)
@@ -20,19 +28,24 @@ module Fig
20
28
 
21
29
  def list_packages
22
30
  results = []
23
- @os.list(@local_repository_dir).each do |package_name|
24
- @os.list(File.join(@local_repository_dir, package_name)).each do |version_name|
25
- results << "#{package_name}/#{version_name}"
31
+ if File.exist?(@local_repository_dir)
32
+ @os.list(@local_repository_dir).each do |package_name|
33
+ @os.list(File.join(@local_repository_dir, package_name)).each do |version_name|
34
+ results << "#{package_name}/#{version_name}"
35
+ end
26
36
  end
27
37
  end
28
38
  results
29
39
  end
30
40
 
41
+ def list_remote_packages
42
+ @os.download_list(@remote_repository_url)
43
+ end
44
+
31
45
  def publish_package(package_statements, package_name, version_name)
32
46
  temp_dir = temp_dir_for_package(package_name, version_name)
33
47
  @os.clear_directory(temp_dir)
34
48
  fig_file = File.join(temp_dir, ".fig")
35
- config_mapping = get_config_mapping(package_statements)
36
49
  content = bundle_resources(package_statements).map do |statement|
37
50
  if statement.is_a?(Publish)
38
51
  nil
@@ -52,13 +65,6 @@ module Fig
52
65
  end
53
66
  @os.upload(archive_local, archive_remote, @remote_repository_user)
54
67
  statement.class.new(archive_name).unparse('')
55
- elsif statement.is_a?(Configuration)
56
- remote_name = config_mapping[statement.name]
57
- if remote_name
58
- statement.with_name(remote_name).unparse('')
59
- else
60
- nil
61
- end
62
68
  else
63
69
  statement.unparse('')
64
70
  end
@@ -68,13 +74,6 @@ module Fig
68
74
  # update_package(package_name, version_name)
69
75
  end
70
76
 
71
- def get_config_mapping(package_statements)
72
- publish_mappings = {}
73
- package_statements.each{|s| publish_mappings[s.local_name] = s.remote_name if s.is_a?(Publish) }
74
- publish_mappings
75
- end
76
-
77
-
78
77
  def bundle_resources(package_statements)
79
78
  resources = []
80
79
  new_package_statements = package_statements.reject do |statement|
@@ -120,7 +119,14 @@ module Fig
120
119
  end
121
120
 
122
121
  def read_package_from_directory(dir, package_name, version_name)
123
- read_package_from_file(File.join(dir, ".fig"), package_name, version_name)
122
+ file = File.join(dir, ".fig")
123
+ if not File.exist?(file)
124
+ file = File.join(dir, "package.fig")
125
+ end
126
+ if not File.exist?(file)
127
+ raise "File not found: #{file}"
128
+ end
129
+ read_package_from_file(file, package_name, version_name)
124
130
  end
125
131
 
126
132
  def read_package_from_file(file_name, package_name, version_name)
@@ -134,7 +140,14 @@ module Fig
134
140
  end
135
141
 
136
142
  def local_dir_for_package(package_name, version_name)
137
- File.join(@local_repository_dir, package_name, version_name)
143
+ descriptor = "#{package_name}/#{version_name}"
144
+ dir = @overrides[descriptor]
145
+ if dir
146
+ $stderr.puts "override: #{descriptor}=#{dir}"
147
+ else
148
+ dir = File.join(@local_repository_dir, package_name, version_name)
149
+ end
150
+ dir
138
151
  end
139
152
 
140
153
  private
data/spec/fig_spec.rb CHANGED
@@ -84,7 +84,6 @@ describe "Fig" do
84
84
  FileUtils.rm_rf(FIG_HOME)
85
85
  FileUtils.rm_rf(FIG_REMOTE_DIR)
86
86
  input = <<-END
87
- publish default
88
87
  config default
89
88
  set FOO=BAR
90
89
  end
@@ -100,9 +99,8 @@ describe "Fig" do
100
99
  File.open("tmp/bin/hello", "w") { |f| f << "echo bar" }
101
100
  fail unless system "chmod +x tmp/bin/hello"
102
101
  input = <<-END
103
- publish test->default
104
102
  resource tmp/bin/hello
105
- config test
103
+ config default
106
104
  append PATH=@/tmp/bin
107
105
  end
108
106
  END
@@ -127,7 +125,6 @@ describe "Fig" do
127
125
  FileUtils.mkdir_p("tmp/lib")
128
126
  File.open("tmp/lib/hello", "w") { |f| f << "some library" }
129
127
  input = <<-END
130
- publish default
131
128
  resource tmp/lib/hello
132
129
  config default
133
130
  append FOOPATH=@/tmp/lib/hello
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.8
4
+ version: 0.1.9
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-19 00:00:00 -06:00
12
+ date: 2010-01-21 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency