winton-externals 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Winton Welsh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1 @@
1
+ # Externals
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rake'
2
+
3
+ task :default => 'externals.gemspec'
4
+
5
+ file 'externals.gemspec' => FileList['{lib,spec}/**','Rakefile'] do |f|
6
+ # read spec file and split out manifest section
7
+ spec = File.read(f.name)
8
+ parts = spec.split(" # = MANIFEST =\n")
9
+ fail 'bad spec' if parts.length != 3
10
+ # determine file list from git ls-files
11
+ files = `git ls-files`.
12
+ split("\n").
13
+ sort.
14
+ reject{ |file| file =~ /^\./ }.
15
+ reject { |file| file =~ /^doc/ }.
16
+ map{ |file| " #{file}" }.
17
+ join("\n")
18
+ # piece file back together and write...
19
+ parts[1] = " s.files = %w[\n#{files}\n ]\n"
20
+ spec = parts.join(" # = MANIFEST =\n")
21
+ File.open(f.name, 'w') { |io| io.write(spec) }
22
+ puts "Updated #{f.name}"
23
+ end
24
+
25
+ # sudo rake install
26
+ task :install do
27
+ `sudo gem uninstall externals -x`
28
+ `gem build externals.gemspec`
29
+ `sudo gem install externals*.gem`
30
+ `rm externals*.gem`
31
+ end
data/bin/externals ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'externals'
5
+
6
+ action = ARGV[0]
7
+ available_actions = %w(install freeze unfreeze)
8
+ unless available_actions.include?(action)
9
+ puts "Usage: externals (#{available_actions.join(':')})"
10
+ exit 1
11
+ end
12
+
13
+ app = Externals::App.new(FileUtils.pwd)
14
+ app.run(action)
@@ -0,0 +1,3 @@
1
+ Version 0.1.0
2
+ -------------
3
+ * Initial Creation
data/externals.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'externals'
3
+ s.version = '0.1.1'
4
+ s.date = '2008-03-11'
5
+
6
+ s.summary = "Work on git externals without affecting others"
7
+ s.description = "Work on git externals without affecting others"
8
+
9
+ s.author = 'Winton Welsh'
10
+ s.email = 'mail@wintoni.us'
11
+ s.homepage = 'http://github.com/winton/externals'
12
+
13
+ s.executables = ["externals"]
14
+ s.has_rdoc = false
15
+
16
+ # = MANIFEST =
17
+ s.files = %w[
18
+ MIT-LICENSE
19
+ README.markdown
20
+ Rakefile
21
+ bin/externals
22
+ changelog.markdown
23
+ externals.gemspec
24
+ lib/externals.rb
25
+ lib/externals/app.rb
26
+ lib/externals/repository.rb
27
+ lib/externals/yaml_config.rb
28
+ spec/spec.opts
29
+ spec/spec_helper.rb
30
+ ]
31
+ # = MANIFEST =
32
+ end
data/lib/externals.rb ADDED
@@ -0,0 +1,3 @@
1
+ require File.dirname(__FILE__) + "/externals/app.rb"
2
+ require File.dirname(__FILE__) + "/externals/repository.rb"
3
+ require File.dirname(__FILE__) + "/externals/yaml_config.rb"
@@ -0,0 +1,45 @@
1
+ module Externals
2
+ class App
3
+ def initialize(base_dir)
4
+ @base_dir = base_dir
5
+ end
6
+
7
+ def install
8
+ config.each_repo {|r| r.install }
9
+ end
10
+
11
+ def freezify
12
+ config.each_repo {|r| r.freezify }
13
+ end
14
+
15
+ def unfreezify
16
+ config.each_repo {|r| r.unfreezify }
17
+ end
18
+
19
+ def run(action)
20
+ case action
21
+ when "install"
22
+ install
23
+ when "freeze"
24
+ freezify
25
+ when "unfreeze"
26
+ unfreezify
27
+ end
28
+ end
29
+
30
+ def config
31
+ return @config if @config
32
+
33
+ config_file = ['config/externals.yml', '.externals.yml'].detect do |file|
34
+ File.file? File.expand_path(@base_dir + '/' + file)
35
+ end
36
+
37
+ if config_file.nil?
38
+ $stderr.puts "config/externals.yml is missing"
39
+ exit 1
40
+ end
41
+
42
+ @config = YamlConfig.new(@base_dir, File.read(config_file))
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,59 @@
1
+ require 'fileutils'
2
+
3
+ module Externals
4
+ class Repository
5
+
6
+ def initialize(base_dir, name, repo_url, rel_path)
7
+ @base_dir = base_dir
8
+ @name = name
9
+ @repo_url = repo_url
10
+ @rel_path = rel_path
11
+ end
12
+
13
+ def install
14
+ FileUtils.mkdir_p checkout_path unless File.exist?(checkout_path)
15
+ `cd #{checkout_path} && rm -Rf #{@name} && git clone #{@repo_url} #{@name}`
16
+ true
17
+ end
18
+
19
+ def freezify
20
+ return true if frozen?
21
+ Dir.chdir(repo_path) do
22
+ `tar czf #{temp_path}/#{@name}.git.tgz .git`
23
+ FileUtils.rm_r('.git')
24
+ end
25
+ true
26
+ end
27
+
28
+ def unfreezify
29
+ return true unless frozen?
30
+ Dir.chdir(temp_path) do
31
+ `tar xzf #{@name}.git.tgz`
32
+ FileUtils.mv(".git", repo_path)
33
+ FileUtils.rm("#{@name}.git.tgz")
34
+ end
35
+ true
36
+ end
37
+
38
+ def frozen?
39
+ File.exist?(repo_path) && !File.exist?("#{repo_path}/.git")
40
+ end
41
+
42
+ private
43
+ def checkout_path
44
+ File.expand_path(File.join(@base_dir, @rel_path))
45
+ end
46
+
47
+ def repo_path
48
+ File.expand_path(checkout_path + '/' + @name)
49
+ end
50
+
51
+ def rel_repo_path
52
+ @rel_path + '/' + @name
53
+ end
54
+
55
+ def temp_path
56
+ @base_dir + '/tmp'
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ require 'yaml'
2
+
3
+ module Externals
4
+ class YamlConfig
5
+ def initialize(base_dir, yaml_string)
6
+ @base_dir = base_dir
7
+ @config_hash = YAML.load yaml_string
8
+ end
9
+
10
+ def each_repo
11
+ repositories.each { |r| yield(r) if block_given? }
12
+ end
13
+
14
+ private
15
+ def repositories
16
+ @config_hash.map do |name, attributes|
17
+ Repository.new(@base_dir, name, attributes["repo"], attributes["path"])
18
+ end
19
+ end
20
+ end
21
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,6 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ Spec::Runner.configure do |config|
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: winton-externals
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Winton Welsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-11 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Work on git externals without affecting others
17
+ email: mail@wintoni.us
18
+ executables:
19
+ - externals
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - MIT-LICENSE
26
+ - README.markdown
27
+ - Rakefile
28
+ - bin/externals
29
+ - changelog.markdown
30
+ - externals.gemspec
31
+ - lib/externals.rb
32
+ - lib/externals/app.rb
33
+ - lib/externals/repository.rb
34
+ - lib/externals/yaml_config.rb
35
+ - spec/spec.opts
36
+ - spec/spec_helper.rb
37
+ has_rdoc: false
38
+ homepage: http://github.com/winton/externals
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Work on git externals without affecting others
63
+ test_files: []
64
+