repose 0.0.1.alpha1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = repose
2
+
3
+ Repose is here to make it easier to organise your project directories.
4
+
5
+ == Reposefile
6
+
7
+ directory "Rails" do
8
+ git "core", :url => "https://github.com/rails/rails.git"
9
+ git "my-fork", :url => "git@github.com:me/rails.git"
10
+ end
11
+
12
+ :include:repose.rdoc
13
+
data/Rakefile ADDED
@@ -0,0 +1,82 @@
1
+ require "rubygems"
2
+ require "rubygems/package_task"
3
+ require "rdoc/task"
4
+
5
+ require "rake/testtask"
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => ["test"]
13
+
14
+ require File.dirname(__FILE__)+"/lib/repose/version"
15
+
16
+ # This builds the actual gem. For details of what all these options
17
+ # mean, and other ones you can add, check the documentation here:
18
+ #
19
+ # http://rubygems.org/read/chapter/20
20
+ #
21
+ spec = Gem::Specification.new do |s|
22
+
23
+ # Change these as appropriate
24
+ s.name = "repose"
25
+ s.version = Repose::VERSION
26
+ s.summary = "Synchronise your repositories"
27
+ s.author = "Matthew Rudy Jacobs"
28
+ s.email = "MatthewRudyJacobs@gmail.com"
29
+ s.homepage = "https://github.com/matthewrudy/repose"
30
+
31
+ s.has_rdoc = true
32
+ s.extra_rdoc_files = %w(README.rdoc)
33
+ s.rdoc_options = %w(--main README.rdoc)
34
+
35
+ # Add any extra files to include in the gem
36
+ s.files = %w(Gemfile Rakefile README.rdoc repose.rdoc) + Dir.glob("{bin,test,lib}/**/*")
37
+ s.executables = FileList["bin/**"].map { |f| File.basename(f) }
38
+ s.require_paths = ["lib"]
39
+
40
+ # If you want to depend on other gems, add them here, along with any
41
+ # relevant versions
42
+ s.add_dependency("gli", "~> 0.1.0")
43
+
44
+ # If your tests use any gems, include them here
45
+ s.add_development_dependency("activesupport")
46
+ end
47
+
48
+ # This task actually builds the gem. We also regenerate a static
49
+ # .gemspec file, which is useful if something (i.e. GitHub) will
50
+ # be automatically building a gem for this project. If you're not
51
+ # using GitHub, edit as appropriate.
52
+ #
53
+ # To publish your gem online, install the 'gemcutter' gem; Read more
54
+ # about that here: http://gemcutter.org/pages/gem_docs
55
+ Gem::PackageTask.new(spec) do |pkg|
56
+ pkg.gem_spec = spec
57
+ end
58
+
59
+ desc "Build the gemspec file #{spec.name}.gemspec"
60
+ task :gemspec do
61
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
62
+ File.open(file, "w") {|f| f << spec.to_ruby }
63
+ end
64
+
65
+ # If you don't want to generate the .gemspec file, just remove this line. Reasons
66
+ # why you might want to generate a gemspec:
67
+ # - using bundler with a git source
68
+ # - building the gem without rake (i.e. gem build blah.gemspec)
69
+ # - maybe others?
70
+ task :package => :gemspec
71
+
72
+ # Generate documentation
73
+ RDoc::Task.new do |rd|
74
+ rd.main = "README.rdoc"
75
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
76
+ rd.rdoc_dir = "rdoc"
77
+ end
78
+
79
+ desc 'Clear out RDoc and generated packages'
80
+ task :clean => [:clobber_rdoc, :clobber_package] do
81
+ rm "#{spec.name}.gemspec"
82
+ end
data/bin/repose ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+ # 1.9 adds realpath to resolve symlinks; 1.8 doesn't
3
+ # have this method, so we add it so we get resolved symlinks
4
+ # and compatibility
5
+ unless File.respond_to? :realpath
6
+ class File #:nodoc:
7
+ def self.realpath path
8
+ return realpath(File.readlink(path)) if symlink?(path)
9
+ path
10
+ end
11
+ end
12
+ end
13
+
14
+ $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
15
+ require 'rubygems'
16
+ require 'gli'
17
+ require 'repose'
18
+
19
+ include GLI
20
+
21
+ Repose::VERSION
22
+
23
+ program_desc 'Describe your application here'
24
+
25
+ version Repose::VERSION
26
+
27
+ def read_reposefile
28
+ File.read("Reposefile")
29
+ end
30
+
31
+ def load_definition
32
+ Repose.from_file(File.open("Reposefile"))
33
+ end
34
+
35
+ desc 'Display your current config'
36
+ command :config do |c|
37
+ c.action do |global_options, options, args|
38
+ puts File.read("Reposefile")
39
+ end
40
+ end
41
+
42
+ desc 'Create a new Reposefile'
43
+ arg_name 'Describe arguments to init here'
44
+ command :init do |c|
45
+ c.action do |global_options, options, args|
46
+ if File.exist?("Reposefile")
47
+ warn "Reposefile already exists"
48
+ else
49
+ Repose::Generator.create_blank("Reposefile")
50
+ end
51
+ end
52
+ end
53
+
54
+ desc 'Describe install here'
55
+ arg_name 'Describe arguments to install here'
56
+ command :install do |c|
57
+ c.action do |global_options, options, args|
58
+ definition = load_definition
59
+ definition.install(".")
60
+ end
61
+ end
62
+
63
+ desc 'Describe update here'
64
+ arg_name 'Describe arguments to update here'
65
+ command :update do |c|
66
+ c.action do |global_options,options,args|
67
+ end
68
+ end
69
+
70
+ # pre do |global,command,options,args|
71
+ # # Pre logic here
72
+ # # Return true to proceed; false to abourt and not call the
73
+ # # chosen command
74
+ # # Use skips_pre before a command to skip this block
75
+ # # on that command only
76
+ # true
77
+ # end
78
+ #
79
+ # post do |global,command,options,args|
80
+ # # Post logic here
81
+ # # Use skips_post before a command to skip this
82
+ # # block on that command only
83
+ # end
84
+ #
85
+ # on_error do |exception|
86
+ # # Error logic here
87
+ # # return false to skip default error handling
88
+ # true
89
+ # end
90
+
91
+ exit GLI.run(ARGV)
@@ -0,0 +1,16 @@
1
+ module Repose
2
+ class Definition
3
+
4
+ def initialize(&block)
5
+ @dsl = ::Repose::DSL::BaseNode.new(&block)
6
+ end
7
+ attr_reader :dsl
8
+
9
+ def install(base_path)
10
+ dsl.each_node do |node|
11
+ node.install(base_path)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
data/lib/repose/dsl.rb ADDED
@@ -0,0 +1,144 @@
1
+ require 'fileutils'
2
+
3
+ module Repose
4
+ module DSL
5
+ class Node
6
+
7
+ def initialize(&block)
8
+ @directories = []
9
+ instance_eval(&block)
10
+ end
11
+ attr_reader :directories
12
+
13
+ # go through each directory yield it, then recurse
14
+ def each_node(&block)
15
+ directories.each do |d|
16
+ block.call(d)
17
+ d.each_node(&block)
18
+ end
19
+ end
20
+
21
+ private # DSL methods should be private
22
+
23
+ # directory "Rails" do
24
+ # git "core", :url => "https://github.com/rails/rails.git"
25
+ # git "my-fork", :git => "git@github.com:me/rails.git"
26
+ # end
27
+ def directory(path, &block)
28
+ @directories << Directory.new(path, self, &block)
29
+ end
30
+ end
31
+
32
+ class BaseNode < Node
33
+ def full_path
34
+ "."
35
+ end
36
+
37
+ def install(base_path)
38
+ #noop
39
+ end
40
+
41
+ def update(base_path)
42
+ #noop
43
+ end
44
+ end
45
+
46
+ class Directory < Node
47
+
48
+ def initialize(path, parent=nil, &block)
49
+ @path = path
50
+ @parent = parent
51
+ @repos = []
52
+ super()
53
+ end
54
+ attr_reader :path, :parent, :repos
55
+
56
+ def parent_path
57
+ parent && parent.full_path
58
+ end
59
+
60
+ def full_path(base_path=nil)
61
+ File.join([base_path, parent_path, path].compact)
62
+ end
63
+
64
+ def install(base_path)
65
+ create!(base_path)
66
+ end
67
+
68
+ def update(base_path)
69
+ create!(base_path)
70
+ end
71
+
72
+ def each_node(&block)
73
+ super(&block)
74
+ repos.each do |r|
75
+ block.call(r)
76
+ end
77
+ end
78
+
79
+ protected
80
+
81
+ def create!(base_path)
82
+ expanded_path = full_path(base_path)
83
+ if File.exist?(expanded_path)
84
+ if File.directory?(expanded_path)
85
+ puts "path exists: #{expanded_path}" if Repose.verbose
86
+ # all is good
87
+ else
88
+ raise "#{expanded_path} already exists, but is not a directory"
89
+ end
90
+ else
91
+ FileUtils.mkdir_p(expanded_path)
92
+ puts "path created: #{expanded_path}" if Repose.verbose
93
+ end
94
+ end
95
+
96
+ private # DSL methods should be private
97
+
98
+ # the git repository type
99
+ def git(name, options)
100
+ add_repository(GitRepository, name, options)
101
+ end
102
+
103
+ def add_repository(klass, name, options)
104
+ @repos << klass.new(name, options.merge(:directory => self))
105
+ end
106
+
107
+ end
108
+
109
+ class Repository
110
+
111
+ def initialize(name, options)
112
+ @name, @options = name, options
113
+ end
114
+ attr_reader :name
115
+
116
+ def url
117
+ @options[:url]
118
+ end
119
+
120
+ def directory
121
+ @options[:directory]
122
+ end
123
+
124
+ def full_path(base_path=nil)
125
+ File.join(directory.full_path(base_path), name)
126
+ end
127
+
128
+ end
129
+
130
+ class GitRepository < Repository
131
+
132
+ def install(base_path)
133
+ clone_command = "git clone #{url} #{full_path(base_path)}"
134
+ puts clone_command if Repose.verbose
135
+ system(clone_command)
136
+ end
137
+
138
+ def update(base_path)
139
+ `cd #{full_path(base_path)} && git pull origin`
140
+ end
141
+ end
142
+
143
+ end
144
+ end
@@ -0,0 +1,26 @@
1
+ # Reposefile
2
+ # ==========
3
+ # structure and share your ~/Projects folder
4
+ #
5
+ # define your structure
6
+ # then run
7
+ #
8
+ # repose install
9
+ #
10
+ # directory "Clients" do
11
+ # directory "37Signals" do
12
+ # git "BaseCamp", :url => "git@37signals.com:basecamp.git"
13
+ # git "Campfire", :url => "git@37signals.com:campfire.git"
14
+ # end
15
+ #
16
+ # directory "Google" do
17
+ # git "SearchEngine", :url => "git@google.com:core.git"
18
+ # end
19
+ # end
20
+ #
21
+ # directory "OpenSource" do
22
+ # directory "Ruby" do
23
+ # git "Rails", :url => "https://github.com/rails/rails.git"
24
+ # end
25
+ # end
26
+ #
@@ -0,0 +1,9 @@
1
+ module Repose
2
+ class Generator
3
+ def self.create_blank(path)
4
+ File.open(path, "w") do |file|
5
+ file.puts(File.read(File.dirname(__FILE__)+"/generator/Reposefile"))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Repose
2
+ VERSION="0.0.1.alpha1"
3
+ end
data/lib/repose.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'repose/definition'
2
+ require 'repose/dsl'
3
+ require 'repose/generator'
4
+ require 'repose/version'
5
+
6
+ module Repose
7
+
8
+ def self.define(&block)
9
+ ::Repose::Definition.new(&block)
10
+ end
11
+
12
+ def self.from_file(file)
13
+ eval <<-EVAL
14
+
15
+ Repose.define do
16
+ #{file.read}
17
+ end
18
+
19
+ EVAL
20
+ end
21
+
22
+ @@VERBOSE = false
23
+
24
+ def self.verbose
25
+ @@VERBOSE
26
+ end
27
+
28
+ def self.verbose=(value)
29
+ @@VERBOSE=value
30
+ end
31
+
32
+ end
data/repose.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = repose
2
+
3
+ Generate this with
4
+ repose rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+
3
+ require 'repose'
4
+
5
+ class ReposeTest < ActiveSupport::TestCase
6
+
7
+ test "define" do
8
+ definition = Repose.define do
9
+ directory "Rails" do
10
+ git "core", :url=> "https://github.com/rails/rails.git"
11
+ git "my-fork", :url => "git@github.com:me/rails.git"
12
+ end
13
+ end
14
+
15
+ dsl = definition.dsl
16
+ assert_equal 1, dsl.directories.length
17
+ rails_dir = dsl.directories.first
18
+
19
+ assert_equal "Rails", rails_dir.path
20
+ assert_equal 2, rails_dir.repos.length
21
+
22
+ core, myfork = rails_dir.repos
23
+ assert_equal "core", core.name
24
+ assert_equal "my-fork", myfork.name
25
+ end
26
+
27
+ test "define - nested directories" do
28
+ definition = Repose.define do
29
+ directory "Outer" do
30
+ directory "Inner" do
31
+ git "InnerProject", :url => "git@example.com:inner.git"
32
+ end
33
+ git "OuterProject", :url => "git@example.com:outer.git"
34
+ end
35
+ end
36
+
37
+ dsl = definition.dsl
38
+ assert_equal 1, dsl.directories.length
39
+ outer_dir = dsl.directories.first
40
+
41
+ assert_equal "Outer", outer_dir.path
42
+ assert_equal 1, outer_dir.directories.length
43
+
44
+ assert_equal 1, outer_dir.repos.length
45
+ outer_repo = outer_dir.repos.first
46
+
47
+ assert_equal "OuterProject", outer_repo.name
48
+ assert_equal "git@example.com:outer.git", outer_repo.url
49
+
50
+ inner_dir = outer_dir.directories.first
51
+ assert_equal "Inner", inner_dir.path
52
+
53
+ assert_equal 1, inner_dir.repos.length
54
+ inner_repo = inner_dir.repos.first
55
+
56
+ assert_equal "InnerProject", inner_repo.name
57
+ assert_equal "git@example.com:inner.git", inner_repo.url
58
+ end
59
+
60
+ test "full path" do
61
+ definition = Repose.define do
62
+ directory "Outer" do
63
+ directory "Inner" do
64
+ git "InnerProject", :url => "git@example.com:inner.git"
65
+ end
66
+ git "OuterProject", :url => "git@example.com:outer.git"
67
+ end
68
+ end
69
+
70
+ dsl = definition.dsl
71
+ assert_equal ".", dsl.full_path
72
+
73
+ outer = dsl.directories.first
74
+ assert_equal "./Outer", outer.full_path
75
+
76
+ outer_repo = outer.repos.first
77
+ assert_equal "./Outer/OuterProject", outer_repo.full_path
78
+
79
+ inner = outer.directories.first
80
+ assert_equal "./Outer/Inner", inner.full_path
81
+
82
+ inner_repo = inner.repos.first
83
+ assert_equal "./Outer/Inner/InnerProject", inner_repo.full_path
84
+ end
85
+
86
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+
5
+ $:.unshift File.expand_path(File.dirname(__FILE__)+"/../lib")
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repose
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Rudy Jacobs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gli
16
+ requirement: &70200385861760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70200385861760
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70200385860520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70200385860520
36
+ description:
37
+ email: MatthewRudyJacobs@gmail.com
38
+ executables:
39
+ - repose
40
+ extensions: []
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - Gemfile
45
+ - Rakefile
46
+ - README.rdoc
47
+ - repose.rdoc
48
+ - bin/repose
49
+ - test/repose_test.rb
50
+ - test/test_helper.rb
51
+ - lib/repose/definition.rb
52
+ - lib/repose/dsl.rb
53
+ - lib/repose/generator/Reposefile
54
+ - lib/repose/generator.rb
55
+ - lib/repose/version.rb
56
+ - lib/repose.rb
57
+ homepage: https://github.com/matthewrudy/repose
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --main
62
+ - README.rdoc
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>'
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.10
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Synchronise your repositories
83
+ test_files: []