fig 0.1.24-universal-darwin9.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2009, Matthew Foemmel
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ * The names of the contributors may not be used to endorse or promote
15
+ products derived from this software without specific prior written
16
+ permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
22
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,215 @@
1
+ Description
2
+ ===========
3
+
4
+ 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).
5
+
6
+ An "environment" in fig is just a set of environment variables. A "package" is a collection of files, plus some metadata describing what environment variables should be modified when the package is included.
7
+
8
+ Developers can use package files to specify the list of dependencies to use for different tasks. This file will typically be versioned along with the rest of the source files. This ensures that all developers on a team are using the same environemnts.
9
+
10
+ Packages exist in two places: a "local" repository in the user's home directory, and a "remote" repository on a server somewhere that is shared by a team. Fig will automatically download packages from the remote repository and install them in the local repository, when needed.
11
+
12
+ Fig is similar to a lot of other package/dependnency managment tools. In particular, it steals a lot of ideas from Apache Ivy and Debian APT. However, unlike Ivy, fig is meant to be lightweight (no XML, no JVM startup time), language agnostic (Java doesn't get preferential treatment), and work with executables as well as libraries. And unlike APT, fig is meant to be cross platform (Windows support is coming) and project-oriented.
13
+
14
+ Installation
15
+ ============
16
+
17
+ Fig can be installed via rubygems. The gems are hosted at [Gemcutter](http://gemcutter.org), so you'll need to set that up first:
18
+
19
+ $ gem install gemcutter
20
+ $ gem tumble
21
+
22
+ Fig also depends on a third-party library named, [libarchive](http://libarchive.rubyforge.org/). Libarchive is easily available
23
+ via most package management systems on Linux, FreeBSD, and OS X. Libarchive versions greater than 2.6.0 are preferred. If you are on Windows, the gem will install the libarchive binaries for you.
24
+
25
+ [Linux - Debian / Ubuntu]
26
+ apt-get libarchive-dev
27
+
28
+ [Linux - Red Hat / CentOS]
29
+ yum install libarchive-devel
30
+
31
+ [OS X - MacPorts]
32
+ port install libarchive
33
+
34
+ Then you can install fig:
35
+
36
+ $ gem install fig
37
+
38
+ Usage
39
+ =====
40
+
41
+ Fig recognizes the following options (not all are implemented yet):
42
+
43
+ ### Flags ###
44
+
45
+ -d, --debug Print debug info
46
+ --force Download/install packages from remote repository, even if up-to-date
47
+ -u, --update Download/install packages from remote repository, if out-of-date
48
+ -n, --no Automatically answer "n" for any prompt (batch mode)
49
+ -y, --yes Automatically answer "y" for any prompt (batch mode)
50
+
51
+
52
+ ### Environment Modifiers ###
53
+
54
+ The following otpions modify the environment generated by fig:
55
+
56
+ -i, --include DESCRIPTOR Include package in environment (recursive)
57
+ -p, --append VAR=VALUE Append value to environment variable using platform-specific separator
58
+ -s, --set VAR=VALUE Set environment variable
59
+
60
+ ### Environment Commands ###
61
+
62
+ The following commands will be run in the environment created by fig:
63
+
64
+ -b, --bash Print bash commands so user's environment can be updated (usually used with 'eval')
65
+ -g, --get VARIABLE Get value of environment variable
66
+ -x, --execute DESCRIPTOR Execute command associated with specified configuration
67
+
68
+ -- COMMAND [ARGS...] Execute arbitrary shell command
69
+
70
+ ### Other Commands ###
71
+
72
+ Fig also supports the following options, which don't require a fig environment. Any modifiers will be ignored:
73
+
74
+ -?, -h, --help Display this help text
75
+ --publish Upload package to the remote repository (also installs in local repository)
76
+ --publish-local Install package in local repository only
77
+ --list List the packages installed in local repository
78
+
79
+ Examples
80
+ ========
81
+
82
+ Fig lets you configure environments three different ways:
83
+
84
+ * From the command line
85
+ * From a "package.fig" file in the current directory
86
+ * From packages included indirectly via one of the previous two methods
87
+
88
+ ### Command Line ###
89
+
90
+ So to get started, let's trying defining an environment variable via the command line and executing a command in the newenvironment. We'll set the "GREETING" variable to "Hello", then run a command that uses that variable:
91
+
92
+ $ fig -s GREETING=Hello -- echo "\$GREETING, World"
93
+ Hello, World
94
+
95
+ Note that you need to put a slash before the dollar sign, otherwise the shell will evaluate the environment variable before it ever gets to fig.
96
+
97
+ Also note that when running fig, the original environment isn't affected:
98
+
99
+ $ echo $GREETING
100
+ <nothing>
101
+
102
+ Fig also lets you append environment variables, using the system-specified path separator (e.g. colon on unix, semicolon on windows). This is useful for adding directories to the PATH, LD_LIBRARY_PATH, CLASSPATH, etc. For example, let's create a "bin" directory, add a shell script to it, then include it in the PATH:
103
+
104
+ $ mkdir bin
105
+ $ echo "echo \$GREETING, World" > bin/hello
106
+ $ chmod +x bin/hello
107
+ $ fig -s GREETING=Hello -p PATH=bin -- hello
108
+ Hello, World
109
+
110
+ ### Fig Files ###
111
+
112
+ You can also specify environment modifiers in files. Fig looks for a file called "package.fig" in the current directory, and automatically processes it. So we can implement the previous example by creating a "package.fig" file that looks like:
113
+
114
+ config default
115
+ set GREETING=Hello
116
+ append PATH=@/bin
117
+ end
118
+
119
+ The '@' symbol represents the directory that the "package.fig" file is in (this example would still work if we just used "bin", but later on when we publish our project to the shared repository we'll definitely need the '@'). Then we can just run:
120
+
121
+ $ fig -- hello
122
+ Hello, World
123
+
124
+ A single fig file can have multiple configurations:
125
+
126
+ config default
127
+ set GREETING=Hello
128
+ append PATH=@/bin
129
+ end
130
+
131
+ config french
132
+ set GREETING=Bonjour
133
+ append PATH=@/bin
134
+ end
135
+
136
+ Configurations other than "default" can be specified using the "-c" option:
137
+
138
+ $ fig -c french -- hello
139
+ Bonjour, World
140
+
141
+ ### Packages ###
142
+
143
+ Now let's say we want to share our little script with the rest of the team by bundling it into a package. The first thing we need to do is specify the location of the remote repository by defining the FIG_REMOTE_URL environment variable. If you just want to play around with fig, you can have it point to localhost:
144
+
145
+ $ export FIG_REMOTE_URL=ssh://localhost`pwd`/remote
146
+
147
+ Before we publish our package, we'll need to tell fig which files we want to include. We do this by using the "resource" statement in our "package.fig" file:
148
+
149
+ resource bin/hello
150
+
151
+ config default...
152
+
153
+ Now we can share the package with the rest of the team by using the "--publish" option:
154
+
155
+ $ fig --publish hello/1.0.0
156
+
157
+ The "hello/1.0.0" string represents the name of the package and the version number. Once the package has been published, we can include it in other environments by using the "-i" or "--include" option (I'm going to move the "package.fig" file out of the way first, so that fig doesn't automatically process it.):
158
+
159
+ $ mv package.fig package.bak
160
+ $ fig -u -i hello/1.0.0 -- hello
161
+ ...downloading files...
162
+ Hello, World
163
+
164
+ The "-u" (or "--update") option tells fig to check the remote repository for packages if they aren't already installed locally (fig will never make any network connections unless this option is specified). Once the packages are downloaded, we can run the same command without the "-u" option:
165
+
166
+ $ fig -i hello/1.0.0 -- hello
167
+ Hello, World
168
+
169
+ Also, when including a package, you can specify a particular configuration by appending it to the package name using a colon:
170
+
171
+ $ fig -i hello/1.0.0:french -- hello
172
+ Bonjour, World
173
+
174
+ ### Retrieves ###
175
+
176
+ By default, the resources associated with a package live in the fig home directory, which defaults to "~/.fighome". This doesn't always play nicely with IDE's however, so fig gives you a way to copy resources from the repository to the current directory. To do this you add "retrieve" statements to your "package.fig" file.
177
+
178
+ For example, let's create a package that contains a library for the "foo" programming language. First we'll define a "package.fig" file:
179
+
180
+ config default
181
+ append FOOPATH=lib/hello.foo
182
+ end
183
+
184
+ Then:
185
+
186
+ $ mkdir lib
187
+ $ echo "print 'hello'" > lib/hello.foo
188
+ $ fig --publish hello-lib/3.2.1
189
+
190
+ Now we'll move to a different directory (or delete the current "package.fig" file) and create a new "package.fig" file:
191
+
192
+ retrieve FOOPATH->lib/[package]
193
+ config default
194
+ include hello-lib/3.2.1
195
+ end
196
+
197
+ When we do an update, all resources in the FOOPATH will be copied into the lib directory, into a subdirectory that matches the package name:
198
+
199
+ $ fig -u
200
+ ...downloading...
201
+ ...retrieving...
202
+ $ cat lib/hello-lib/hello.foo
203
+ print 'hello'
204
+
205
+ Community
206
+ =========
207
+
208
+ \#fig on irc.freenode.net
209
+
210
+ [Fig Mailing List](http://groups.google.com/group/fig-user)
211
+
212
+ Copyright
213
+ =========
214
+
215
+ Copyright (c) 2009 Matthew Foemmel. See LICENSE for details.
data/bin/fig ADDED
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
+
5
+ require 'rubygems'
6
+ require 'net/ftp'
7
+
8
+ require 'fig/options'
9
+ require 'fig/environment'
10
+ require 'fig/repository'
11
+ require 'fig/os'
12
+ require 'fig/parser'
13
+ require 'fig/windows'
14
+
15
+ include Fig
16
+
17
+ def parse_descriptor(descriptor)
18
+ # todo should use treetop for these:
19
+ package_name = descriptor =~ /^([^:\/]+)/ ? $1 : nil
20
+ config_name = descriptor =~ /:([^:\/]+)/ ? $1 : nil
21
+ version_name = descriptor =~ /\/([^:\/]+)/ ? $1 : nil
22
+ return package_name, config_name, version_name
23
+ end
24
+
25
+ shell_command = nil
26
+ ARGV.each_with_index do |arg, i|
27
+ if arg == "-"
28
+ # $stderr.puts "Use of single dash (-) is deprecated. Use double dash (--) instead"
29
+ # exit 1
30
+ elsif arg == "--"
31
+ shell_command = ARGV[(i+1)..-1]
32
+ ARGV.slice!(i..-1)
33
+ break
34
+ end
35
+ end
36
+
37
+ options, argv = parse_options(ARGV)
38
+
39
+ vars = {}
40
+ ENV.each {|key,value| vars[key]=value }
41
+
42
+ remote_url = nil
43
+ if options[:update] || options[:publish] || options[:update_if_missing] || options[:list_remote]
44
+ remote_url = ENV['FIG_REMOTE_URL']
45
+ if remote_url.nil?
46
+ $stderr.puts "Please define the FIG_REMOTE_URL environment variable"
47
+ exit 1
48
+ end
49
+ end
50
+
51
+ remote_user = nil
52
+ if options[:publish]
53
+ # remote_user = ENV['FIG_REMOTE_USER']
54
+ # if remote_user.nil?
55
+ # $stderr.puts "Please define the FIG_REMOTE_USER environment variable"
56
+ # exit 1
57
+ # end
58
+ end
59
+
60
+ os = OS.new
61
+ repos = Repository.new(os, File.expand_path(File.join(options[:home], 'repos')), remote_url, remote_user, options[:update], options[:update_if_missing])
62
+ env = Environment.new(os, repos, vars)
63
+
64
+ options[:modifiers].each do |modifier|
65
+ env.apply_config_statement(nil, modifier)
66
+ end
67
+
68
+ if File.exist?(".fig")
69
+ $stderr.puts "The '.fig' file is deprecated. Please rename to 'package.fig'"
70
+ exit 1
71
+ end
72
+
73
+ DEFAULT_FIG_FILE = 'package.fig'
74
+
75
+ input = nil
76
+ if options[:input] == :none
77
+ # ignore
78
+ elsif options[:input] == '-'
79
+ input = $stdin.read
80
+ elsif options[:input].nil?
81
+ input = os.read(DEFAULT_FIG_FILE) if os.exist?(DEFAULT_FIG_FILE)
82
+ else
83
+ if os.exist?(options[:input])
84
+ input = os.read(options[:input])
85
+ else
86
+ $stderr.puts "File not found: #{options[:input]}"
87
+ exit 1
88
+ end
89
+ end
90
+
91
+ options[:cleans].each do |descriptor|
92
+ package_name, version_name = descriptor.split('/')
93
+ repos.clean(package_name, version_name)
94
+ end
95
+
96
+ if options[:list]
97
+ repos.list_packages.sort.each do |item|
98
+ puts item
99
+ end
100
+ exit 0
101
+ end
102
+
103
+ if options[:list_remote]
104
+ repos.list_remote_packages.sort.each do |item|
105
+ puts item
106
+ end
107
+ exit 0
108
+ end
109
+
110
+ if not options[:list_configs].empty?
111
+ options[:list_configs].each do |descriptor|
112
+ package_name, version_name = descriptor.split('/')
113
+ repos.read_local_package(package_name, version_name).configs.each do |config|
114
+ puts config.name
115
+ end
116
+ end
117
+ exit 0
118
+ end
119
+
120
+ if input
121
+ package = Parser.new.parse_package(nil, nil, ".", input)
122
+ direct_retrieves=[]
123
+ if options[:retrieve]
124
+ package.retrieves.each do |var, path|
125
+ if var =~ /^@([^\/]+)(.*)/
126
+ direct_retrieves << [$1, $2, path]
127
+ else
128
+ env.add_retrieve(var, path)
129
+ end
130
+ end
131
+ end
132
+ unless options[:publish] || options[:list] || options[:publish_local]
133
+ env.register_package(package)
134
+ env.apply_config(package, options[:config])
135
+ direct_retrieves.each do |info|
136
+ env.direct_retrieve(info[0], info[1], info[2])
137
+ end
138
+ end
139
+ else
140
+ package = Package.new(nil, nil, ".", [])
141
+ end
142
+
143
+ if options[:publish] || options[:publish_local]
144
+ if !argv.empty?
145
+ puts "Unexpected arguments: #{argv.join(' ')}"
146
+ exit 10
147
+ end
148
+ package_name, config_name, version_name = parse_descriptor(options[:publish] || options[:publish_local])
149
+ if package_name.nil? || version_name.nil?
150
+ puts "Please specify a package name and a version name"
151
+ exit 10
152
+ end
153
+ if not options[:modifiers].empty?
154
+ publish_statements = options[:resources] + options[:archives] + [Configuration.new("default", options[:modifiers])]
155
+ publish_statements << Publish.new("default","default")
156
+ elsif not package.statements.empty?
157
+ publish_statements = package.statements
158
+ else
159
+ puts "Nothing to publish"
160
+ exit 1
161
+ end
162
+ if options[:publish]
163
+ puts "Checking status of #{package_name}/#{version_name}..."
164
+ if repos.list_remote_packages.include?("#{package_name}/#{version_name}")
165
+ puts "#{package_name}/#{version_name} has already been published"
166
+ if not options[:force]
167
+ puts "Use the --force option if you really want to overwrite, or us --publish-local for testing"
168
+ exit 1
169
+ else
170
+ puts "Overwriting..."
171
+ end
172
+ end
173
+ end
174
+ puts "Publishing #{package_name}/#{version_name}"
175
+ repos.publish_package(publish_statements, package_name, version_name, options[:publish_local])
176
+ elsif options[:echo]
177
+ puts env[options[:echo]]
178
+ elsif shell_command
179
+ argv.shift
180
+ env.execute_shell(shell_command) { |cmd| os.shell_exec cmd }
181
+ elsif argv[0]
182
+ package_name, config_name, version_name = parse_descriptor(argv.shift)
183
+ env.include_config(package, package_name, config_name, version_name)
184
+ env.execute_config(package, package_name, config_name, nil, argv) { |cmd| os.shell_exec cmd }
185
+ elsif input
186
+ env.execute_config(package, nil, options[:config], nil, argv) { |cmd| os.shell_exec cmd }
187
+ end
data/bin/fig-download ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # todo copied from os.rb
4
+ NOT_MODIFIED = 3
5
+ NOT_FOUND = 4
6
+ SUCCESS = 0
7
+
8
+ timestamp = ARGV[0].to_i
9
+ path = ARGV[1]
10
+
11
+ exit NOT_FOUND unless File.exist?(path)
12
+ exit NOT_MODIFIED if File.mtime(path).to_i <= timestamp
13
+
14
+ File.open(path) do |file|
15
+ while bytes = file.read(4096) do
16
+ $stdout.write(bytes)
17
+ end
18
+ end
19
+
20
+ exit SUCCESS