peony 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/Rakefile +1 -1
- data/bin/peony +7 -3
- data/lib/peony/actions.rb +178 -0
- data/lib/peony/application.rb +5 -2
- data/lib/peony/default.rb +13 -13
- data/lib/peony/line_editor/basic.rb +35 -0
- data/lib/peony/line_editor/readline.rb +88 -0
- data/lib/peony/line_editor.rb +16 -0
- data/lib/peony/rake.rb +3 -1
- data/lib/peony/shell/basic.rb +429 -0
- data/lib/peony/shell/color.rb +149 -0
- data/lib/peony/shell/html.rb +126 -0
- data/lib/peony/shell.rb +46 -0
- data/lib/peony/utils.rb +22 -100
- data/lib/peony/version.rb +1 -1
- data/lib/peony.rb +7 -5
- data/peony.gemspec +9 -9
- data/recipes/db/mongo.rake +23 -23
- data/recipes/db/mysql.rake +19 -19
- data/recipes/db/pg.rake +13 -13
- data/recipes/db/redis.rake +19 -19
- data/recipes/elasticsearch.rake +10 -10
- data/recipes/httpd.rake +15 -15
- data/recipes/nginx/www.rake +5 -5
- data/recipes/nginx.rake +10 -10
- data/recipes/php.rake +6 -6
- data/spec/peony_spec.rb +45 -0
- data/spec/settings_in_rake_spec.rb +12 -12
- data/spec/settings_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -5
- metadata +29 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86659b2347d22d0bab806ea9121a25483b23234c
|
4
|
+
data.tar.gz: e00f2bb4bcaf222ea29a555214f0ce8e9750eab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad1dc485f76cba8e7ab763a0b207dab4fa175feef772719ac3a9dd9d5e8b0b6517b2551bbab1a0bf90b3c3d9b202a7155f336907f5291391e50bbb10cd45bd02
|
7
|
+
data.tar.gz: 4174ea8aa81806539ef11b7192bfcfe218b2cc73f913acb98feedad1f0651c443ab5422d9957c56ed463e6d35433a673c039f602f20234bc81b878924105792d
|
data/README.md
CHANGED
@@ -77,13 +77,31 @@ you can just add the following code to your Rakefile
|
|
77
77
|
load f
|
78
78
|
end
|
79
79
|
|
80
|
+
|
80
81
|
|
82
|
+
## Directory Convension
|
81
83
|
|
84
|
+
### template and recipes
|
85
|
+
<pre>
|
86
|
+
|--peony_root
|
87
|
+
|--Rakefile
|
88
|
+
|--recipes
|
89
|
+
|--nginx.rake
|
90
|
+
|--pgsql.rake
|
91
|
+
|--...
|
92
|
+
|--templates
|
93
|
+
|--nginx.conf.erb
|
94
|
+
|--pgsql.conf.erb
|
95
|
+
|--...
|
96
|
+
</pre>
|
82
97
|
|
98
|
+
if you want to run peony command in any directory, you can add peony_root to your environment.
|
83
99
|
|
100
|
+
export peony_root=/u/bin
|
101
|
+
|
102
|
+
|
84
103
|
|
85
|
-
|
86
|
-
## Directory Convension
|
104
|
+
### generated directory convension
|
87
105
|
<pre>
|
88
106
|
|
89
107
|
|--u
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/peony
CHANGED
@@ -20,20 +20,24 @@ if ARGV.delete('--simulate') || ARGV.delete('-S')
|
|
20
20
|
ENV['simulate'] = '1'
|
21
21
|
end
|
22
22
|
|
23
|
+
if ARGV.delete('--dry-run') || ARGV.delete('-D')
|
24
|
+
ENV['dry-run'] = '1'
|
25
|
+
end
|
26
|
+
|
23
27
|
Rake.application.instance_eval do
|
24
28
|
standard_exception_handling do
|
25
29
|
|
26
30
|
init 'peony'
|
27
31
|
|
28
|
-
@rakefiles +=
|
29
|
-
options.rakelib +=
|
32
|
+
@rakefiles += %w{Peonyfile peonyfile}
|
33
|
+
options.rakelib += %w{recipes/**}
|
30
34
|
|
31
35
|
# Load the Peony DSL.
|
32
36
|
require 'peony/rake'
|
33
37
|
|
34
38
|
load_rakefile
|
35
39
|
|
36
|
-
Dir.glob(File.expand_path(
|
40
|
+
Dir.glob(File.expand_path('../recipes/**/*.rake', __dir__)) do|fn|
|
37
41
|
load fn
|
38
42
|
end
|
39
43
|
|
@@ -0,0 +1,178 @@
|
|
1
|
+
module Peony
|
2
|
+
module Actions
|
3
|
+
|
4
|
+
def destination_root
|
5
|
+
@destination_stack ||= [File.expand_path(Dir.pwd || '')]
|
6
|
+
@destination_stack.last
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns the given path relative to the absolute root (ie, root where
|
10
|
+
# the script started).
|
11
|
+
#
|
12
|
+
def relative_to_original_destination_root(path, remove_dot = true)
|
13
|
+
path = path.dup
|
14
|
+
if path.gsub!(@destination_stack[0], '.')
|
15
|
+
remove_dot ? (path[2..-1] || '') : path
|
16
|
+
else
|
17
|
+
path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def mkdir_p(*dirs)
|
22
|
+
dirs.each do|dir|
|
23
|
+
say "mkdir #{dir}", :yellow, true
|
24
|
+
FileUtils.mkdir_p(dir) if !FileTest.exists?(dir)
|
25
|
+
fail "#{dir} must be a directory!" unless FileTest.directory?(dir)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def sudo(cmd)
|
30
|
+
run "sudo #{cmd}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# ### report_time
|
34
|
+
# Report time elapsed in the block.
|
35
|
+
# Returns the output of the block.
|
36
|
+
#
|
37
|
+
# report_time do
|
38
|
+
# sleep 2
|
39
|
+
# # do other things
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# # Output:
|
43
|
+
# # Elapsed time: 2.00 seconds
|
44
|
+
def report_time(&blk)
|
45
|
+
time, output = measure &blk
|
46
|
+
say 'Elapsed time: %.2f seconds' % [time], :yellow
|
47
|
+
output
|
48
|
+
end
|
49
|
+
|
50
|
+
# ### measure
|
51
|
+
# Measures the time (in seconds) a block takes.
|
52
|
+
# Returns a [time, output] tuple.
|
53
|
+
def measure(&blk)
|
54
|
+
t = Time.now
|
55
|
+
output = yield
|
56
|
+
[Time.now - t, output]
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# ### invoke
|
61
|
+
# Invokes another Rake task.
|
62
|
+
#
|
63
|
+
# Invokes the task given in `task`. Returns nothing.
|
64
|
+
#
|
65
|
+
# invoke :'git:clone'
|
66
|
+
# invoke :restart
|
67
|
+
#
|
68
|
+
# Options:
|
69
|
+
# reenable (bool) - Execute the task even next time.
|
70
|
+
#
|
71
|
+
def invoke(task, config = {})
|
72
|
+
Rake.application.invoke_task task
|
73
|
+
Rake::Task[task].reenable if config[:reenable]
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Do something in the root or on a provided subfolder. If a relative path
|
78
|
+
# is given it's referenced from the current root. The full path is yielded
|
79
|
+
# to the block you provide. The path is set back to the previous path when
|
80
|
+
# the method exits.
|
81
|
+
#
|
82
|
+
# ==== Parameters
|
83
|
+
# dir<String>:: the directory to move to.
|
84
|
+
# config<Hash>:: give :verbose => true to log and use padding.
|
85
|
+
#
|
86
|
+
def inside(dir='', config={}, &block)
|
87
|
+
verbose = config.fetch(:verbose, false)
|
88
|
+
dry_run = ENV['dry-run']
|
89
|
+
|
90
|
+
say_status :inside, dir, verbose
|
91
|
+
self.padding_up if verbose
|
92
|
+
@destination_stack.push File.expand_path(dir, destination_root)
|
93
|
+
|
94
|
+
# If the directory doesnt exist and we're not pretending
|
95
|
+
if !File.exist?(destination_root) && !pretend
|
96
|
+
FileUtils.mkdir_p(destination_root)
|
97
|
+
end
|
98
|
+
|
99
|
+
if dry_run
|
100
|
+
# In dry_run mode, just yield down to the block
|
101
|
+
block.arity == 1 ? yield(destination_root) : yield
|
102
|
+
else
|
103
|
+
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
104
|
+
end
|
105
|
+
|
106
|
+
@destination_stack.pop
|
107
|
+
self.padding_down if verbose
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Goes to the root and execute the given block.
|
112
|
+
#
|
113
|
+
def in_root
|
114
|
+
inside(@destination_stack.first) { yield }
|
115
|
+
end
|
116
|
+
|
117
|
+
# Loads an external file and execute it in the instance binding.
|
118
|
+
#
|
119
|
+
# ==== Parameters
|
120
|
+
# path<String>:: The path to the file to execute. Can be a web address or
|
121
|
+
# a relative path from the source root.
|
122
|
+
#
|
123
|
+
# ==== Examples
|
124
|
+
#
|
125
|
+
# apply "http://gist.github.com/103208"
|
126
|
+
#
|
127
|
+
# apply "recipes/jquery.rb"
|
128
|
+
#
|
129
|
+
def apply(path, config={})
|
130
|
+
verbose = config.fetch(:verbose, true)
|
131
|
+
is_uri = path =~ /^https?\:\/\//
|
132
|
+
path = find_recipes(path).first unless is_uri
|
133
|
+
|
134
|
+
say_status :apply, path, verbose
|
135
|
+
self.padding_up if verbose
|
136
|
+
|
137
|
+
if is_uri
|
138
|
+
contents = open(path, 'Accept' => 'application/x-peony-template') {|io| io.read }
|
139
|
+
else
|
140
|
+
contents = open(path) {|io| io.read }
|
141
|
+
end
|
142
|
+
|
143
|
+
instance_eval(contents, path)
|
144
|
+
self.padding_down if verbose
|
145
|
+
end
|
146
|
+
|
147
|
+
# Executes a command returning the contents of the command.
|
148
|
+
#
|
149
|
+
# ==== Parameters
|
150
|
+
# command<String>:: the command to be executed.
|
151
|
+
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
|
152
|
+
# to append an executable to command executation.
|
153
|
+
#
|
154
|
+
# ==== Example
|
155
|
+
#
|
156
|
+
# inside('vendor') do
|
157
|
+
# run('ln -s ~/edge rails')
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
def run(command, config={})
|
161
|
+
destination = relative_to_original_destination_root(destination_root, false)
|
162
|
+
desc = "#{command} from #{destination.inspect}"
|
163
|
+
|
164
|
+
if config[:with]
|
165
|
+
desc = "#{File.basename(config[:with].to_s)} #{desc}"
|
166
|
+
command = "#{config[:with]} #{command}"
|
167
|
+
end
|
168
|
+
|
169
|
+
say_status :run, desc, config.fetch(:verbose, true)
|
170
|
+
|
171
|
+
unless ENV['dry-run']
|
172
|
+
config[:capture] ? `#{command}` : system("#{command}")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
data/lib/peony/application.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
1
3
|
module Rake
|
2
4
|
class Application
|
3
5
|
alias_method :origin_find_rakefile_location, :find_rakefile_location
|
6
|
+
|
4
7
|
def find_rakefile_location
|
5
8
|
ret = origin_find_rakefile_location
|
6
9
|
unless ret
|
7
|
-
if ENV[
|
8
|
-
Dir.chdir(ENV[
|
10
|
+
if ENV['peony_root']
|
11
|
+
Dir.chdir(ENV['peony_root'])
|
9
12
|
if fn = have_rakefile
|
10
13
|
ret = [fn, Dir.pwd]
|
11
14
|
end
|
data/lib/peony/default.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
set_default :base_dir,
|
2
|
-
set_default :var_dir,
|
3
|
-
set_default :etc_dir,
|
4
|
-
set_default :share_dir, ->{"#{base_dir}/share"}
|
5
|
-
set_default :run_dir,
|
6
|
-
set_default :tmp_dir,
|
7
|
-
set_default :log_dir,
|
8
|
-
set_default :www_dir,
|
9
|
-
set_default :data_dir,
|
1
|
+
set_default :base_dir, "/u"
|
2
|
+
set_default :var_dir, ->{ "#{base_dir}/var" }
|
3
|
+
set_default :etc_dir, ->{ "#{base_dir}/etc" }
|
4
|
+
set_default :share_dir, ->{ "#{base_dir}/share" }
|
5
|
+
set_default :run_dir, ->{ "#{var_dir}/run" }
|
6
|
+
set_default :tmp_dir, ->{ "#{var_dir}/tmp" }
|
7
|
+
set_default :log_dir, ->{ "#{var_dir}/log" }
|
8
|
+
set_default :www_dir, ->{ "#{var_dir}/www" }
|
9
|
+
set_default :data_dir, ->{ "#{var_dir}/data" }
|
10
10
|
|
11
|
-
set_default :user,
|
12
|
-
set_default :group,
|
11
|
+
set_default :user, 'james'
|
12
|
+
set_default :group, 'admin'
|
13
13
|
|
14
14
|
namespace :settings do
|
15
|
-
desc
|
15
|
+
desc 'List all the settings.'
|
16
16
|
task :list do
|
17
17
|
settings.each do|k, v|
|
18
|
-
|
18
|
+
say "#{k} = #{settings.send(k)}", :green, true
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Peony
|
2
|
+
module LineEditor
|
3
|
+
class Basic
|
4
|
+
attr_reader :prompt, :options
|
5
|
+
|
6
|
+
def self.available?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(prompt, options)
|
11
|
+
@prompt = prompt
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def readline
|
16
|
+
$stdout.print(prompt)
|
17
|
+
get_input
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_input
|
23
|
+
if echo?
|
24
|
+
$stdin.gets
|
25
|
+
else
|
26
|
+
$stdin.noecho(&:gets)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def echo?
|
31
|
+
options.fetch(:echo, true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
begin
|
2
|
+
require 'readline'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
module Peony
|
7
|
+
module LineEditor
|
8
|
+
class Readline < Basic
|
9
|
+
def self.available?
|
10
|
+
Object.const_defined?(:Readline)
|
11
|
+
end
|
12
|
+
|
13
|
+
def readline
|
14
|
+
if echo?
|
15
|
+
::Readline.completion_append_character = nil
|
16
|
+
# Ruby 1.8.7 does not allow Readline.completion_proc= to receive nil.
|
17
|
+
if complete = completion_proc
|
18
|
+
::Readline.completion_proc = complete
|
19
|
+
end
|
20
|
+
::Readline.readline(prompt, add_to_history?)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def add_to_history?
|
29
|
+
options.fetch(:add_to_history, true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def completion_proc
|
33
|
+
if use_path_completion?
|
34
|
+
proc { |text| PathCompletion.new(text).matches }
|
35
|
+
elsif completion_options.any?
|
36
|
+
proc do |text|
|
37
|
+
completion_options.select { |option| option.start_with?(text) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def completion_options
|
43
|
+
options.fetch(:limited_to, [])
|
44
|
+
end
|
45
|
+
|
46
|
+
def use_path_completion?
|
47
|
+
options.fetch(:path, false)
|
48
|
+
end
|
49
|
+
|
50
|
+
class PathCompletion
|
51
|
+
attr_reader :text
|
52
|
+
private :text
|
53
|
+
|
54
|
+
def initialize(text)
|
55
|
+
@text = text
|
56
|
+
end
|
57
|
+
|
58
|
+
def matches
|
59
|
+
relative_matches
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def relative_matches
|
65
|
+
absolute_matches.map { |path| path.sub(base_path, '') }
|
66
|
+
end
|
67
|
+
|
68
|
+
def absolute_matches
|
69
|
+
Dir[glob_pattern].map do |path|
|
70
|
+
if File.directory?(path)
|
71
|
+
"#{path}/"
|
72
|
+
else
|
73
|
+
path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def glob_pattern
|
79
|
+
"#{base_path}#{text}*"
|
80
|
+
end
|
81
|
+
|
82
|
+
def base_path
|
83
|
+
"#{Dir.pwd}/"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# The following classes's code was copied from Thor, available under MIT-LICENSE
|
2
|
+
# Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
|
3
|
+
require 'peony/line_editor/basic'
|
4
|
+
require 'peony/line_editor/readline'
|
5
|
+
|
6
|
+
module Peony
|
7
|
+
module LineEditor
|
8
|
+
def self.readline(prompt, options = {})
|
9
|
+
best_available.new(prompt, options).readline
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.best_available
|
13
|
+
[Peony::LineEditor::Readline, Peony::LineEditor::Basic].detect(&:available?)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/peony/rake.rb
CHANGED