enzyme 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Haydn Ewers
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = enzyme
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to enzyme
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Haydn Ewers. See LICENSE.txt for
18
+ further details.
19
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/enzyme ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
+
6
+ require 'setup'
7
+ require 'enzyme'
8
+
9
+ # Require all commands in the commands directory.
10
+ Dir["#{lib_dir}/commands/*.rb"].each {|file| require "commands/"+File.basename(file, ".rb") }
11
+
12
+ Enzyme.run()
@@ -0,0 +1,76 @@
1
+ require 'yaml'
2
+ require 'hash'
3
+ require 'enzyme'
4
+ require 'commands/help'
5
+
6
+ module Config extend self
7
+
8
+ GLOBAL_FILENAME = "#{ENV['HOME']}/.enzyme.yml"
9
+ PROJECT_FILENAME = "./.enzyme.yml"
10
+
11
+ def run()
12
+ global = ARGV.delete('--global')
13
+ ARGV.reject { |x| x.start_with?("-") }
14
+ key = ARGV.shift
15
+ value = ARGV.shift
16
+
17
+ unless value === nil
18
+ set(key, value, global)
19
+ else
20
+ val = get(key)
21
+ if val.is_a?(Array) || val.is_a?(Hash) || val.is_a?(Settings)
22
+ puts val.to_hash.to_yaml
23
+ else
24
+ puts val.to_s
25
+ end
26
+ end
27
+ end
28
+
29
+ def get(key)
30
+ s = $settings
31
+ key.split('.').each { |o| s = s[o] } if key
32
+ s
33
+ end
34
+
35
+ def set(key, value, global=false)
36
+ filename = global ? GLOBAL_FILENAME : PROJECT_FILENAME
37
+ settings = YAML.load_file(filename) || {}
38
+
39
+ # FIXME: This could be simplified... heaps.
40
+ newSettings = {}
41
+ n = newSettings
42
+ keys = key.to_s.split(".")
43
+ keys.each do |k|
44
+ k = k.to_i if k == k.to_i.to_s
45
+ n[k] = (k == keys.last) ? value : {}
46
+ n = n[k]
47
+ end
48
+
49
+ settings = settings.deep_merge(newSettings)
50
+
51
+ File.open(filename, "w") { |f| f.write(settings.to_yaml) }
52
+ end
53
+
54
+ end
55
+
56
+ Enzyme.register(Config) do
57
+ puts 'CONFIG COMMAND'
58
+ puts '--------------'
59
+ puts ''
60
+ puts '### SYNOPSIS'
61
+ puts ''
62
+ puts ' enzyme config [key [value [--global]]]'
63
+ puts ''
64
+ puts '### EXAMPLES'
65
+ puts ''
66
+ puts ' enzyme config user dave --global'
67
+ puts ''
68
+ puts ' enzyme config user'
69
+ puts ' > dave'
70
+ puts ''
71
+ puts ' enzyme config project_name my_project'
72
+ puts ''
73
+ puts ' enzyme config project_name'
74
+ puts ' > my_project'
75
+ puts ''
76
+ end
@@ -0,0 +1,97 @@
1
+ require 'enzyme'
2
+ require 'commands/config'
3
+ require 'commands/help'
4
+
5
+ module Create extend self
6
+
7
+ def run()
8
+ ARGV.reject { |x| x.start_with?("-") }
9
+ project_name = ARGV.shift
10
+ project_type = ARGV.shift
11
+
12
+ if project_name
13
+ if project_type
14
+ case project_type.to_sym
15
+ when :pms
16
+ pms(project_name)
17
+ when :koi
18
+ koi(project_name)
19
+ else
20
+ Enzyme.error("Unknown project type `#{project_type}`.")
21
+ end
22
+ else
23
+ base(project_name)
24
+ end
25
+ else
26
+ Enzyme.error("A project name must be given. For example: `enzyme create project_name`")
27
+ end
28
+ end
29
+
30
+ def base(project_name)
31
+ unless $settings.projects_directory
32
+ Enzyme.error("The `sync.projects_directory` setting is not set. Set it using `enzyme config projects_directory \"/Users/me/Projects\"`.")
33
+ return
34
+ end
35
+
36
+ system "mkdir #{$settings.projects_directory}/#{project_name}"
37
+ system "mkdir #{$settings.projects_directory}/#{project_name}/resources"
38
+ system "mkdir #{$settings.projects_directory}/#{project_name}/resources/client"
39
+ system "touch #{$settings.projects_directory}/#{project_name}/.enzyme.yml"
40
+
41
+ Dir.chdir("#{$settings.projects_directory}/#{project_name}")
42
+
43
+ Config.set('project_name', project_name)
44
+ Config.set('project_type', nil)
45
+ end
46
+
47
+ def koi(project_name)
48
+ Enzyme.error("Koi projects are not avaliable in this version of Enzyme (#{$version}).")
49
+ end
50
+
51
+ def pms(project_name)
52
+ unless $settings.projects_directory
53
+ Enzyme.error("The `sync.projects_directory` setting is not set. Set it using `enzyme config projects_directory \"/Users/me/Projects\"`.")
54
+ return
55
+ end
56
+
57
+ unless $settings.github.user
58
+ Enzyme.error("The `sync.github.user` setting is not set. Set it using `enzyme config github.user \"me\"`.")
59
+ return
60
+ end
61
+
62
+ unless $settings.github.token
63
+ Enzyme.error("The `sync.github.token` setting is not set. Set it using `enzyme config github.token \"0123456789abcdef0123456789abcdef\"`.")
64
+ return
65
+ end
66
+
67
+ base(project_name)
68
+
69
+ Config.set('project_type', 'pms')
70
+
71
+ system "curl -o '/tmp/#{project_name}.zip' -F 'login=#{$settings.github.user}' -F 'token=#{$settings.github.token}' -L 'https://github.com/katalyst/pms/zipball/v0.4.2alpha03'"
72
+ system "unzip '/tmp/#{project_name}.zip' -d '/tmp/#{project_name}.temp'"
73
+ system "rm '/tmp/#{project_name}.zip'"
74
+
75
+ extracted_dir = Dir.entries("/tmp/#{project_name}.temp")[2]
76
+
77
+ system "mv /tmp/#{project_name}.temp/#{extracted_dir}/* #{$settings.projects_directory}/#{project_name}/"
78
+ system "rm -r '/tmp/#{project_name}.temp'"
79
+ end
80
+
81
+ end
82
+
83
+ Enzyme.register(Create) do
84
+ puts 'CREATE COMMAND'
85
+ puts '--------------'
86
+ puts ''
87
+ puts '### SYNOPSIS'
88
+ puts ''
89
+ puts ' enzyme create project_name [pms]'
90
+ puts ''
91
+ puts '### EXAMPLES'
92
+ puts ''
93
+ puts ' enzyme create my_project pms'
94
+ # puts ''
95
+ # puts ' enzyme create another_project koi'
96
+ puts ''
97
+ end
@@ -0,0 +1,7 @@
1
+ module List extend self
2
+
3
+ def run(what=nil)
4
+ ARGV.reject { |x| x.start_with?("-") }
5
+ end
6
+
7
+ end
@@ -0,0 +1,66 @@
1
+ require 'enzyme'
2
+
3
+ module Sync extend self
4
+
5
+ def run()
6
+ ARGV.reject { |x| x.start_with?("-") }
7
+ project_name = ARGV.shift || $settings.project_name
8
+
9
+ unless project_name
10
+ Enzyme.error("No project name specified. Ensure you're in the project's directory or set it specifically. Run `enzyme help sync` for help.")
11
+ return
12
+ end
13
+
14
+ unless $settings.sync.share_name
15
+ Enzyme.error("The `sync.share_name` setting is not set. Set it using `enzyme config sync.share_name \"Share Name\"`.")
16
+ return
17
+ end
18
+
19
+ unless $settings.sync.host
20
+ Enzyme.error("The `sync.host` setting is not set. Set it using `enzyme config sync.host \"Host._afpovertcp._tcp.local\"`.")
21
+ return
22
+ end
23
+
24
+ unless $settings.sync.projects_directory
25
+ Enzyme.error("The `sync.projects_directory` setting is not set. Set it using `enzyme config sync.projects_directory \"My Projects Directory\"`.")
26
+ return
27
+ end
28
+
29
+ unless $settings.sync.protected_directory
30
+ Enzyme.error("The `sync.protected_directory` setting is not set. Set it using `enzyme config sync.protected_directory \"my_directory\"`.")
31
+ return
32
+ end
33
+
34
+ unless $settings.sync.shared_directory
35
+ Enzyme.error("The `sync.shared_directory` setting is not set. Set it using `enzyme config sync.shared_directory \"our_shared_directory\"`.")
36
+ return
37
+ end
38
+
39
+ # Mount the network volume. Only works on OS X.
40
+ system "mkdir \"/Volumes/#{$settings.sync.share_name}\""
41
+ system "mount -t afp \"afp://#{$settings.sync.host}/#{$settings.sync.share_name}\" \"/Volumes/#{$settings.sync.share_name}\""
42
+ system "mkdir \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}\""
43
+ # Pull.
44
+ system "rsync -aH --stats -v -u --progress --exclude '#{$settings.sync.protected_directory}/**' \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}/\" '#{$settings.projects_directory}/#{project_name}/resources/'"
45
+ # Push.
46
+ system "rsync -aH --stats -v -u --progress --include '*/' --include '#{$settings.sync.shared_directory}/**' --include '#{$settings.sync.protected_directory}/**' --exclude '*' '#{$settings.projects_directory}/#{project_name}/resources/' \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}/\""
47
+ end
48
+
49
+ end
50
+
51
+ Enzyme.register(Sync) do
52
+ puts 'SYNC COMMAND'
53
+ puts '--------------'
54
+ puts ''
55
+ puts '### SYNOPSIS'
56
+ puts ''
57
+ puts ' enzyme sync [project_name]'
58
+ puts ''
59
+ puts '### EXAMPLES'
60
+ puts ''
61
+ puts ' cd ~/Projects/my_project'
62
+ puts ' enzyme sync'
63
+ puts ''
64
+ puts ' enzyme sync another_project'
65
+ puts ''
66
+ end
@@ -0,0 +1,7 @@
1
+ module Tasks extend self
2
+
3
+ def run(user=nil)
4
+ ARGV.reject { |x| x.start_with?("-") }
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ module View extend self
2
+
3
+ def run(what=nil)
4
+ ARGV.reject { |x| x.start_with?("-") }
5
+ end
6
+
7
+ end
data/lib/enzyme.rb ADDED
@@ -0,0 +1,88 @@
1
+ module Enzyme extend self
2
+
3
+ @@commands = {}
4
+
5
+ def run
6
+ # Only shift the first argument off the ARGV if help flags haven't been passed.
7
+ command = (ARGV.delete("-h") || ARGV.delete("--help")) ? 'help' : (ARGV.shift || 'help')
8
+
9
+ # Show info, help or run the requested command if it has been registered.
10
+ begin
11
+ if command.eql?('help')
12
+ help
13
+ else
14
+ if @@commands.include?(command.to_s.downcase)
15
+ @@commands[command.to_s.downcase][:class].run()
16
+ else
17
+ error("Unable to find command `#{command}`.")
18
+ help
19
+ end
20
+ end
21
+ rescue StandardError => e
22
+ error(e)
23
+ end
24
+ end
25
+
26
+ def info
27
+ puts 'ENZYME'
28
+ puts '======'
29
+ puts ''
30
+ puts 'Katalyst\'s project collaboration tool.'
31
+ puts ''
32
+ puts 'Version: '+$version
33
+ puts ''
34
+ end
35
+
36
+ def help
37
+ ARGV.reject { |x| x.start_with?("-") }
38
+ command = ARGV.shift
39
+
40
+ info
41
+
42
+ if command
43
+ if @@commands.include?(command.to_s.downcase)
44
+ @@commands[command.to_s.downcase][:help].call
45
+ else
46
+ error("No help available for `#{name}`.")
47
+ end
48
+ else
49
+ puts 'USAGE'
50
+ puts '-----'
51
+ puts ''
52
+ puts '### Commands'
53
+ puts ''
54
+ puts ' enzyme config [key [value [--global]]]'
55
+ puts ' enzyme create project_name [type]'
56
+ # puts ' enzyme join project_name'
57
+ puts ' enzyme sync [project_name]'
58
+ puts ''
59
+ puts '### Help'
60
+ puts ''
61
+ puts ' enzyme help [command]'
62
+ puts ' enzyme [command] --help'
63
+ puts ' enzyme [command] -h'
64
+ puts ''
65
+ puts '### Debugging'
66
+ puts ''
67
+ puts 'Use `--trace` at anytime to get full stacktraces.'
68
+ puts ''
69
+ end
70
+ end
71
+
72
+ def error(error)
73
+ if $trace_errors && error.is_a?(StandardError)
74
+ raise error
75
+ else
76
+ puts 'ERROR'
77
+ puts '-----'
78
+ puts ''
79
+ puts '> '+error
80
+ puts ''
81
+ end
82
+ end
83
+
84
+ def register(command_class, &block)
85
+ @@commands[command_class.to_s.downcase] = { :class => command_class, :help => block }
86
+ end
87
+
88
+ end
data/lib/hash.rb ADDED
@@ -0,0 +1,8 @@
1
+ # From: http://www.ruby-forum.com/topic/142809
2
+ # Author: Stefan Rusterholz
3
+ class Hash
4
+ def deep_merge(second)
5
+ merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
6
+ self.merge(second, &merger)
7
+ end
8
+ end
data/lib/settings.rb ADDED
@@ -0,0 +1,44 @@
1
+ # Based on: http://mjijackson.com/2010/02/flexible-ruby-config-objects
2
+ # Authors: Michael Jackson, Haydn Ewers
3
+ class Settings
4
+
5
+ def initialize(data={})
6
+ @data = {}
7
+ update!(data)
8
+ end
9
+
10
+ def update!(data)
11
+ data.each do |key, value|
12
+ self[key] = value
13
+ end
14
+ end
15
+
16
+ def [](key)
17
+ @data[key.to_sym] || @data[key.to_i]
18
+ end
19
+
20
+ def []=(key, value)
21
+ if value.class == Hash
22
+ @data[key.to_sym] = Settings.new(value)
23
+ else
24
+ @data[key.to_sym] = value
25
+ end
26
+ end
27
+
28
+ def to_hash
29
+ @data.to_hash
30
+ end
31
+
32
+ def to_s
33
+ @data.to_s
34
+ end
35
+
36
+ def method_missing(sym, *args)
37
+ if sym.to_s =~ /(.+)=$/
38
+ self[$1] = args.first
39
+ else
40
+ self[sym]
41
+ end
42
+ end
43
+
44
+ end
data/lib/setup.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+ require 'hash'
3
+ require 'settings'
4
+
5
+ # Default settings.
6
+ config = {
7
+ :github => {
8
+ :user => `git config --global github.user`.rstrip,
9
+ :token => `git config --global github.token`.rstrip
10
+ }
11
+ }
12
+ # Global settings.
13
+ config = config.deep_merge(YAML.load_file("#{ENV['HOME']}/.enzyme.yml")) if File.exist?("#{ENV['HOME']}/.enzyme.yml")
14
+ # Project settings.
15
+ config = config.deep_merge(YAML.load_file("./.enzyme.yml")) if File.exist?("./.enzyme.yml")
16
+
17
+ # Global settings object.
18
+ $settings = Settings.new(config)
19
+
20
+ # Global flag for full stacktraces.
21
+ $trace_errors = ARGV.delete('--trace')
22
+
23
+ # Version number.
24
+ $version = "0.1.0"
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'enzyme'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestEnzyme < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enzyme
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Haydn Ewers
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-18 00:00:00 +10:30
19
+ default_executable: enzyme
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ name: shoulda
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 23
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ name: bundler
49
+ prerelease: false
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 7
58
+ segments:
59
+ - 1
60
+ - 5
61
+ - 2
62
+ version: 1.5.2
63
+ type: :development
64
+ name: jeweler
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ name: rcov
79
+ prerelease: false
80
+ version_requirements: *id004
81
+ description: Enzyme is a tool developed by Katalyst to make collaborating on projects easier.
82
+ email: haydn@katalyst.com.au
83
+ executables:
84
+ - enzyme
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - VERSION
92
+ - bin/enzyme
93
+ - lib/commands/config.rb
94
+ - lib/commands/create.rb
95
+ - lib/commands/list.rb
96
+ - lib/commands/sync.rb
97
+ - lib/commands/tasks.rb
98
+ - lib/commands/view.rb
99
+ - lib/enzyme.rb
100
+ - lib/hash.rb
101
+ - lib/settings.rb
102
+ - lib/setup.rb
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ - test/helper.rb
106
+ - test/test_enzyme.rb
107
+ has_rdoc: true
108
+ homepage: http://github.com/katalyst/enzyme
109
+ licenses:
110
+ - MIT
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.3.7
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Katalyst's project collaboration tool.
141
+ test_files:
142
+ - test/helper.rb
143
+ - test/test_enzyme.rb