spock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spock.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andres Riofrio
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Spock
2
+
3
+ Merge multiple directories into one using symlinks (copies on Windows). It's like [Spock][]'s mind meld. Kind of. Not really.
4
+
5
+ [spock]: http://en.wikipedia.org/wiki/Spock
6
+
7
+ ## Installation
8
+
9
+ gem install spock
10
+
11
+ ## Usage
12
+
13
+ See [spock/examples][] for sample configuration files. Place yours in ~/.spockrc, ~/Dropbox/.spockrc, or ~/Dropbox/Apps/Spock/spockrc. Then, run
14
+
15
+ spock
16
+
17
+ You can also a configuration file anywhere by running
18
+
19
+ spock path/to/my/spockrc
20
+
21
+ [spock/examples]: https://github.com/ariofrio/spock/tree/master/examples
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # return a nicer message from ctrl-c
4
+ trap("INT") do
5
+ puts("\n ! Command cancelled.")
6
+ exit
7
+ end
8
+
9
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
10
+
11
+ # start up the CLI
12
+ require "spock/cli"
13
+ Spock::CLI.run
@@ -0,0 +1,13 @@
1
+ # dotfile manager
2
+ #
3
+ # Place this file in ~/Dropbox/.spockrc and run spock every time you add a
4
+ # file/directory. In Windows, also run spock every time you edit a file.
5
+ #
6
+ # Now you can quickly get set up on new computers.
7
+
8
+ to_prefix '.'
9
+
10
+ from '~/GitHub/dotfiles'
11
+ from '~/Dropbox/Dotfiles'
12
+ from '~/Encrypted/Dotfiles'
13
+ to '~'
@@ -0,0 +1,84 @@
1
+ require "spock/version"
2
+
3
+ class Spock
4
+
5
+ def initialize(config_file = nil, opts = {})
6
+ if config_file.nil?
7
+ config_file = "#{ENV['HOME']}/.spockrc"
8
+ config_file = "#{ENV['HOME']}/Dropbox/.spockrc" \
9
+ if not File.exists? config_file
10
+ config_file = "#{ENV['HOME']}/Dropbox/Apps/Spock/spockrc" \
11
+ if not File.exists? config_file
12
+ throw "No spockrc in default locations" if not File.exists? config_file
13
+ end
14
+ throw "#{config_file}: No such file or directory" if not File.exists? config_file
15
+ @config_file = config_file
16
+ @opts = opts
17
+ end
18
+
19
+ def merge
20
+ config = Config.new
21
+ config.instance_eval(binread(@config_file), @config_file)
22
+
23
+ config.sources.reverse.each do |source|
24
+ if not File.directory? source
25
+ puts "Not found: source directory #{source}"
26
+ next
27
+ end
28
+ Dir.chdir(source) do
29
+ Dir['*'].each do |path|
30
+ source_file = File.join(source, path)
31
+ target_file = File.join(config.target, config.target_prefix + path)
32
+
33
+ if needs_replacement? source_file, target_file
34
+ puts "Merging #{target_file} from #{source}"
35
+ merge_file source_file, target_file
36
+ else
37
+ puts "Skipping #{target_file}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def merge_file(source_file, target_file)
45
+ if not @opts[:dry_run]
46
+ FileUtils.rm_rf target_file
47
+ if symlink_supported?
48
+ File.symlink source_file, target_file
49
+ else
50
+ FileUtils.cp_r :preserve => true
51
+ end
52
+ end
53
+ end
54
+
55
+ def needs_replacement?(source_file, target_file)
56
+ if symlink_supported?
57
+ not File.symlink? target_file or
58
+ not File.readlink(target_file) == source_file
59
+ else
60
+ not File.exists? target_file or
61
+ not File.size(target_file) == File.size(source_file) or
62
+ not binread(target_file) == binread(source_file)
63
+ end
64
+ end
65
+
66
+ def symlink_supported?
67
+ not RbConfig::CONFIG["host_os"] =~
68
+ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
69
+ end
70
+
71
+ def binread(file)
72
+ File.open(file, 'rb:ASCII-8BIT') { |f| f.read }
73
+ end
74
+
75
+ class Config
76
+ attr_reader :sources, :target, :target_prefix
77
+ def initialize; @sources = []; @target = nil; @target_prefix = ''; end
78
+
79
+ def from(str); @sources << File.expand_path(str); end
80
+ def to(str); @target = File.expand_path(str); end
81
+ def to_prefix(str); @target_prefix = str; end
82
+ end
83
+
84
+ end
@@ -0,0 +1,28 @@
1
+ require 'spock'
2
+ require 'trollop'
3
+
4
+ class Spock
5
+ module CLI
6
+ class << self
7
+ include Trollop
8
+
9
+ def run(args = ARGV)
10
+ opts = options args do
11
+ banner <<EOS
12
+ Usage: spock [CONFIG]
13
+ Merge multiple directories into one using symlinks.
14
+
15
+ If CONFIG is not given, try ~/.spockrc, ~/Dropbox/.spockrc, ~/Dropbox/Apps/Spock/spockrc, in that order.
16
+
17
+ EOS
18
+ opt :dry_run, "Don't actually merge anything; just print",
19
+ :short => '-n'
20
+ version Spock::VERSION
21
+ end
22
+
23
+ spock = Spock.new ARGV[0], opts
24
+ spock.merge
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ class Spock
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ if RUBY_VERSION == '1.8.7'
3
+ $:.unshift File.expand_path("../lib", __FILE__)
4
+ require "spock/version"
5
+ else
6
+ require File.expand_path('../lib/spock/version', __FILE__ )
7
+ end
8
+
9
+ Gem::Specification.new do |gem|
10
+ gem.authors = ["Andres Riofrio"]
11
+ gem.email = ["riofrios@gmail.com"]
12
+ gem.summary = %q{Merge multiple directories into one using symlinks}
13
+ gem.homepage = "https://github.com/ariofrio/spock"
14
+
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.name = "spock"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = Spock::VERSION
21
+
22
+ gem.add_dependency 'trollop', '~> 2.0'
23
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spock
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andres Riofrio
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-08-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: trollop
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 0
32
+ version: "2.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email:
37
+ - riofrios@gmail.com
38
+ executables:
39
+ - spock
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - bin/spock
51
+ - examples/dotfiles.spockrc
52
+ - lib/spock.rb
53
+ - lib/spock/cli.rb
54
+ - lib/spock/version.rb
55
+ - spock.gemspec
56
+ homepage: https://github.com/ariofrio/spock
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.11
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Merge multiple directories into one using symlinks
89
+ test_files: []
90
+