evoker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2010, Maciej Pasternacki <maciej@pasternacki.net>
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
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the copyright holder nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL MACIEJ PASTERNACKI BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/lib/evoker.rb ADDED
@@ -0,0 +1,143 @@
1
+ # @author Maciej Pasternacki <maciej@pasternacki.net>
2
+
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) ||
5
+ $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ require 'date'
8
+
9
+ require 'rake'
10
+ require 'rake/clean'
11
+
12
+ require 'evoker/version'
13
+
14
+ # Evoker is a tool to manage external dependencies of a project using
15
+ # Rake to run downloads.
16
+ module Evoker
17
+ # {Rake::FileList} of defined entities
18
+ # @example can be used as dependency for the default target
19
+ # task :default => Evoker::ENTITIES
20
+ ENTITIES = Rake::FileList[]
21
+
22
+ class EntityTask < Rake::FileTask
23
+ ##
24
+ # Parsed yaml config for the task
25
+ attr_reader :config
26
+
27
+ def initialize(*args, &block)
28
+ super(*args, &block)
29
+ @stampname = "#{@name}.stamp"
30
+ @actions << lambda { rm_rf @name }
31
+ CLOBBER.add([@stampname, @name])
32
+ ENTITIES.add(@name)
33
+
34
+ if File.exists? "#{@name}.yaml"
35
+ require 'yaml'
36
+ @config = YAML::load_file("#{@name}.yaml")
37
+ self.enhance [Rake.application.intern(Rake::FileTask, "#{@name}.yaml")]
38
+ end
39
+ end
40
+
41
+ # Executes task and writes its timestamp file
42
+ def execute(args=nil)
43
+ super
44
+ File.open(@stampname, 'w') { |f| f.write(DateTime::now.to_s) }
45
+ end
46
+
47
+ # Use @stampname instead of task name to determine whether to re-do the task
48
+ def needed?
49
+ ! File.exist?(name) || ! File.exist?(@stampname) || out_of_date?(timestamp)
50
+ end
51
+
52
+ # Time stamp for file task is on the stamp file, not on target.
53
+ def timestamp
54
+ if File.exist?(@stampname)
55
+ File.mtime(@stampname)
56
+ else
57
+ Rake::EARLY
58
+ end
59
+ end
60
+ end
61
+
62
+ # Base entity definition (wrapper over {EntityTask})
63
+ #
64
+ # @param [#to_s] name name of task and directory
65
+ # @param *args arguments for {EntityTask#initialize}
66
+ # @yield [Rake::Task] block executed to populate target directory
67
+ # @return [EntityTask] defined task
68
+ def entity(name, *args, &block)
69
+ Evoker::EntityTask.define_task(name, *args, &block)
70
+ end
71
+ module_function :entity
72
+
73
+ # Download a file using wget.
74
+ #
75
+ # @param [#to_s] url address to download from
76
+ # @param [Hash] opts options
77
+ # @option opts [#to_s] :output_file (basename of `url`) name of target file
78
+ # @option opts [#to_s] :wget ('wget') wget command to use
79
+ # @option opts [#to_s] :args (nil) custom command line arguments for wget
80
+ # @option opts [True, False] :no_entity (false)
81
+ # do not add task to {Evoker::ENTITIES}
82
+ def wget(url, opts={})
83
+ opts[:output_file] ||= begin
84
+ require 'uri'
85
+ URI.parse(url).path.split('/').last
86
+ end
87
+ opts[:wget] ||= 'wget'
88
+
89
+ wget_command = "#{opts[:wget]} -O #{opts[:output_file]}"
90
+ wget_command << " #{opts[:args]}" if opts[:args]
91
+ wget_command << " #{url} && touch #{opts[:output_file]}"
92
+
93
+ CLOBBER.add(opts[:output_file])
94
+ ENTITIES.add(opts[:output_file]) unless opts[:no_entity]
95
+
96
+ desc "Download #{url} as #{opts[:output_file]}"
97
+ file opts[:output_file] do
98
+ sh wget_command
99
+ touch opts[:output_file]
100
+ end
101
+ end
102
+ module_function :wget
103
+
104
+ # Check out Subversion repository
105
+ def subversion(name, opts={})
106
+ opts[:svn] ||= "svn"
107
+ entity name do |t|
108
+ cmd = "#{opts[:svn]}"
109
+ cmd << " #{opts[:svn_args]}" if opts[:svn_args]
110
+ cmd << " #{t.config[:svn_args]}" if t.config[:svn_args]
111
+ cmd << " checkout -q"
112
+ cmd << " #{opts[:checkout_args]}" if opts[:checkout_args]
113
+ cmd << " #{t.config[:checkout_args]}" if t.config[:checkout_args]
114
+ cmd << " -r #{opts[:revision]}" if opts[:revision]
115
+ cmd << " -r #{t.config[:revision]}" if t.config[:revision]
116
+ cmd << " #{opts[:url]}" if opts[:url]
117
+ cmd << " #{t.config[:url]}" if t.config[:url]
118
+ cmd << " #{t.name}"
119
+ sh cmd
120
+ end
121
+ end
122
+ module_function :subversion
123
+
124
+ # Check out Git repository
125
+ def git(name, opts={})
126
+ opts[:git] ||= "git"
127
+ entity name do |t|
128
+ cmd = "#{opts[:git]} clone"
129
+ cmd << " #{opts[:clone_args]}" if opts[:clone_args]
130
+ cmd << " #{t.config[:clone_args]}" if t.config[:clone_args]
131
+ cmd << " #{opts[:url]}" if opts[:url]
132
+ cmd << " #{t.config[:url]}" if t.config[:url]
133
+ cmd << " #{t.name}"
134
+
135
+ if rev = opts[:revision] || t.config[:revision]
136
+ cmd << " && cd #{t.name}" \
137
+ " && #{opts[:git]} checkout -b evoker-checkout #{rev}"
138
+ end
139
+ sh cmd
140
+ end
141
+ end
142
+ module_function :git
143
+ end
@@ -0,0 +1,78 @@
1
+ # Python stuff
2
+
3
+ require 'evoker'
4
+
5
+ module Evoker
6
+
7
+ # Create Python virtual environment
8
+ def virtualenv(*args)
9
+ if args.last.is_a? Hash
10
+ opts = args.pop
11
+ else
12
+ opts = {}
13
+ end
14
+
15
+ if opts[:download_virtualenv]
16
+ opts[:python] ||= 'python'
17
+ opts[:virtualenv] = "#{opts[:python]} ./virtualenv.py"
18
+ opts[:virtualenv_version] ||= '1.6'
19
+ opts[:virtualenv_url] ||= "http://github.com/pypa/virtualenv/raw/#{opts[:virtualenv_version]}/virtualenv.py"
20
+ wget_virtualenv = wget opts[:virtualenv_url],
21
+ :args => '--no-check-certificate',
22
+ :no_entity => true
23
+ CLOBBER.add(['virtualenv.pyc', 'setuptools-*.egg'])
24
+ else
25
+ opts[:virtualenv] ||= 'virtualenv'
26
+ wget_virtualenv = nil
27
+ end
28
+ opts[:args] ||= nil
29
+
30
+ virtualenv_command = "#{opts[:virtualenv]}"
31
+ virtualenv_command << " #{opts[:args]}" if opts[:args]
32
+
33
+ desc "Python virtual environment"
34
+ venv = entity(*args) do |t|
35
+ sh "#{virtualenv_command} #{t.name}"
36
+ end
37
+
38
+ task venv => wget_virtualenv if wget_virtualenv
39
+ venv
40
+ end
41
+ module_function :virtualenv
42
+
43
+ # Create a symbolic link to virtualenv's site-packages dir
44
+ def virtualenv_site_package(path, opts={})
45
+ opts[:target] ||= File.basename(path)
46
+ opts[:virtualenv] ||= :python
47
+ venv = Rake::Task[opts[:virtualenv]].name
48
+ ln_sf File.join('..', '..', '..', '..', path),
49
+ File.join(Dir["#{venv}/lib/python*/site-packages"].first,
50
+ opts[:target])
51
+ end
52
+ module_function :virtualenv_site_package
53
+
54
+ # Download Python requirements using pip
55
+ def pip_requirements(file, args={})
56
+ stampfile = "#{file}.stamp"
57
+ if args[:virtualenv]
58
+ args[:pip] = "#{args[:virtualenv]}/bin/pip"
59
+ else
60
+ args[:pip] ||= 'pip'
61
+ end
62
+ pip_cmd = "#{args[:pip]}"
63
+ pip_cmd << " #{args[:args]}" if args[:args]
64
+ pip_cmd << " install"
65
+ pip_cmd << " #{args[:install_args]}" if args[:install_args]
66
+ pip_cmd << " -r #{file}"
67
+
68
+ t = file stampfile => file do
69
+ sh pip_cmd
70
+ File.open(stampfile, 'w') { |f| f.write(DateTime::now.to_s) }
71
+ end
72
+ task t => args[:virtualenv] if args[:virtualenv]
73
+ CLOBBER.add t.name
74
+ ENTITIES.add t.name
75
+ t
76
+ end
77
+ module_function :pip_requirements
78
+ end
@@ -0,0 +1,14 @@
1
+ module Evoker
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+ STRING = [MAJOR, MINOR, TINY].join('.')
7
+
8
+ def VERSION.require_version(major, minor=0, tiny=0)
9
+ unless ([MAJOR, MINOR, TINY] <=> [major, minor, tiny]) >= 0
10
+ raise Capistrano::Error, "capistrano-offroad version #{MAJOR}.#{MINOR}.#{TINY} is below required #{major}.#{minor}.#{tiny}"
11
+ end
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evoker
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
+ - Maciej Pasternacki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-19 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: |
36
+ Evoker is an add-on to Rake to download and manage project's external
37
+ dependencied, update them as needed, cache them, etc.
38
+
39
+ email: maciej@pasternacki.net
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/evoker/python.rb
48
+ - lib/evoker/version.rb
49
+ - lib/evoker.rb
50
+ - LICENSE
51
+ has_rdoc: true
52
+ homepage: http://github.com/mpasternacki/evoker
53
+ licenses:
54
+ - BSD
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 23
75
+ segments:
76
+ - 1
77
+ - 3
78
+ - 6
79
+ version: 1.3.6
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.5.0
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Rake add-on to download and manage project's external dependencies
87
+ test_files: []
88
+