rypple 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rypple +29 -3
- data/lib/rypple/base.rb +30 -15
- data/lib/rypple/setup.rb +190 -0
- data/lib/rypple/version.rb +1 -1
- data/lib/rypple.rb +20 -1
- metadata +5 -4
data/bin/rypple
CHANGED
@@ -1,10 +1,36 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
require 'optparse'
|
3
4
|
require 'rubygems'
|
4
5
|
require 'rypple'
|
5
6
|
|
6
|
-
|
7
|
+
#Default options
|
8
|
+
options = {:input => '.',
|
9
|
+
:setup => false,}
|
7
10
|
|
8
|
-
|
9
|
-
Rypple
|
11
|
+
opts = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Rypple Version: " + Rypple::VERSION + "\nUsage: rypple [options]"
|
13
|
+
# opts.separator ""
|
14
|
+
# opts.separator "Specific options:"
|
15
|
+
|
16
|
+
opts.on("-s", "--setup",
|
17
|
+
"Runs setup routine for Rypple") do |ext|
|
18
|
+
options[:setup] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-i", "--input [dir]",
|
22
|
+
"Directory to read configuration files and sync with Rypple.") do |ext|
|
23
|
+
options[:input] = ext
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on_tail("-h", "--help", "Help:") do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end.parse!(ARGV)
|
31
|
+
|
32
|
+
if options[:setup]
|
33
|
+
Rypple.Setup()
|
34
|
+
elsif File.exists?(options[:input])
|
35
|
+
Rypple.sync(options[:input])
|
10
36
|
end
|
data/lib/rypple/base.rb
CHANGED
@@ -7,11 +7,12 @@ module Rypple
|
|
7
7
|
require 'dropbox_sdk'
|
8
8
|
require 'pathname'
|
9
9
|
|
10
|
-
ACCESS_TYPE = :app_folder
|
11
10
|
DefaultConfiguration = {
|
12
11
|
:destinationDir => './test',
|
13
12
|
:dropbox => {
|
13
|
+
:root => '/',
|
14
14
|
:sync => ['**'],
|
15
|
+
:access_type => :app_folder,
|
15
16
|
}
|
16
17
|
}
|
17
18
|
|
@@ -31,6 +32,11 @@ module Rypple
|
|
31
32
|
dropboxKeys[:key] = gets.chomp!
|
32
33
|
print "Please enter your Dropbox API secret:"
|
33
34
|
dropboxKeys[:secret] = gets.chomp!
|
35
|
+
print "Should this API access be used in sandbox mode? (Y/n):"
|
36
|
+
answer = gets.downcase.chomp
|
37
|
+
if !answer.empty? and answer == 'n'
|
38
|
+
dropboxKeys[:access_type]= :dropbox
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
session = nil
|
@@ -54,7 +60,7 @@ module Rypple
|
|
54
60
|
dropboxKeys[:session] = session.serialize()
|
55
61
|
end
|
56
62
|
|
57
|
-
client = DropboxClient.new(session,
|
63
|
+
client = DropboxClient.new(session, dropboxKeys[:access_type])
|
58
64
|
|
59
65
|
if client.nil?
|
60
66
|
return nil, nil, nil
|
@@ -84,14 +90,14 @@ module Rypple
|
|
84
90
|
return conf
|
85
91
|
end
|
86
92
|
|
87
|
-
def Rypple.
|
93
|
+
def Rypple.saveDropbox(keys, path)
|
88
94
|
dropConfig = File.join(path, DropboxKeyFile)
|
89
95
|
File.open(dropConfig, 'w') do|file|
|
90
96
|
file.puts keys.to_yaml
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
94
|
-
def Rypple.
|
100
|
+
def Rypple.saveConfig(conf, path)
|
95
101
|
ryppleConf = File.join(path, RyppleConfigFile)
|
96
102
|
File.open(ryppleConf, 'w') do |file|
|
97
103
|
file.puts conf.to_yaml
|
@@ -157,14 +163,25 @@ module Rypple
|
|
157
163
|
destDir = conf[:destinationDir]
|
158
164
|
|
159
165
|
oldFileState = dropboxKeys[:files]
|
160
|
-
files = Rypple.walkDropbox(client,
|
166
|
+
files = Rypple.walkDropbox(client, conf[:dropbox][:root], oldFileState)
|
161
167
|
|
168
|
+
rootLength = conf[:dropbox][:root].length
|
162
169
|
if !files.nil?
|
163
|
-
files.keys.each { |
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
170
|
+
files.keys.each { |xx|
|
171
|
+
fileDest = xx[rootLength, xx.length]
|
172
|
+
matched = false
|
173
|
+
conf[:dropbox][:sync].each { |ii|
|
174
|
+
if File.fnmatch?(ii, xx, File::FNM_DOTMATCH)
|
175
|
+
matched = true
|
176
|
+
break
|
177
|
+
end
|
178
|
+
}
|
179
|
+
if matched
|
180
|
+
file = client.get_file(xx)
|
181
|
+
dest = File.join(destDir, fileDest)
|
182
|
+
File.makedirs(File.dirname(dest))
|
183
|
+
File.open(dest, 'w') {|f| f.puts file}
|
184
|
+
end
|
168
185
|
}
|
169
186
|
end
|
170
187
|
|
@@ -172,17 +189,15 @@ module Rypple
|
|
172
189
|
Dir.glob(File.join(destDir, ii)).each { |oo|
|
173
190
|
if !File.directory?(oo)
|
174
191
|
upName = Pathname.new(oo).relative_path_from(Pathname.new(destDir)).to_s
|
175
|
-
upName = File.join("", upName)
|
192
|
+
upName = File.join("", conf[:dropbox][:root], upName)
|
176
193
|
if files.nil? or !files.has_key?(upName)
|
177
|
-
|
178
|
-
client.put_file(upName, up, true)
|
179
|
-
up.close()
|
194
|
+
File.open(oo) { |f| client.put_file(upName, f, true) }
|
180
195
|
end
|
181
196
|
end
|
182
197
|
}
|
183
198
|
}
|
184
199
|
|
185
|
-
dropboxKeys[:files] = Rypple.walkDropbox(client,
|
200
|
+
dropboxKeys[:files] = Rypple.walkDropbox(client, conf[:dropbox][:root], {})
|
186
201
|
Rypple.cleanup(conf, dropboxKeys, path)
|
187
202
|
|
188
203
|
return true
|
data/lib/rypple/setup.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rypple'
|
3
|
+
|
4
|
+
module Rypple
|
5
|
+
|
6
|
+
DefaultCGI = <<'eos'
|
7
|
+
#!/usr/bin/ruby
|
8
|
+
gemPath = "%%GEM_PATH"
|
9
|
+
configPath = "%%CONFIG_PATH"
|
10
|
+
inDir = "%%IN_DIR"
|
11
|
+
outDir = "%%OUT_DIR"
|
12
|
+
|
13
|
+
if !gemPath.empty?
|
14
|
+
$:.push(gemPath)
|
15
|
+
ENV['GEM_PATH'] = gemPath
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'cgi'
|
19
|
+
require 'rubygems'
|
20
|
+
require 'rypple'
|
21
|
+
require 'jekyll'
|
22
|
+
|
23
|
+
cgi = CGI.new
|
24
|
+
|
25
|
+
puts cgi.header
|
26
|
+
|
27
|
+
puts "<h1>Rippling . . .</h1>"
|
28
|
+
if Rypple.sync(configPath)
|
29
|
+
puts "<h1>Generating Static Site</h1>"
|
30
|
+
puts `%%COMMAND #{inDir} #{outDir}`
|
31
|
+
end
|
32
|
+
eos
|
33
|
+
|
34
|
+
DefaultUpdateForm = <<'eos'
|
35
|
+
<html>
|
36
|
+
<head>
|
37
|
+
<title>Rypple</title>
|
38
|
+
</head>
|
39
|
+
<body>
|
40
|
+
<h1> Throw a stone into a pond..</h1>
|
41
|
+
<form action="update.cgi" method="POST">
|
42
|
+
<input type="submit" value="Rypple">
|
43
|
+
</form>
|
44
|
+
</body>
|
45
|
+
</html>
|
46
|
+
eos
|
47
|
+
|
48
|
+
DefaultHTAccess = <<'eos'
|
49
|
+
AuthName "Rypple Updater"
|
50
|
+
AuthType Basic
|
51
|
+
AuthUserFile %%AUTH_FILE
|
52
|
+
Require valid-user
|
53
|
+
eos
|
54
|
+
|
55
|
+
# Returns false if installation fails
|
56
|
+
def Rypple.Setup()
|
57
|
+
puts "Configuring the Rypple update script for web use."
|
58
|
+
if File.exists?(ENV["HOME"])
|
59
|
+
configBase = File.join(ENV["HOME"], 'ryppleSite')
|
60
|
+
puts "Please enter directory for Rypple Site. Default:", configBase
|
61
|
+
else
|
62
|
+
puts "Please enter directory for the new Rypple site."
|
63
|
+
end
|
64
|
+
directory = gets.chomp!
|
65
|
+
|
66
|
+
if !directory.empty?
|
67
|
+
configBase = File.expand_path(configBase)
|
68
|
+
end
|
69
|
+
|
70
|
+
if !File.exists?(configBase)
|
71
|
+
begin
|
72
|
+
Dir.mkdir(configBase)
|
73
|
+
rescue SystemCallError
|
74
|
+
puts "Cannot create directory", configBase, "aborting."
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
conf = Rypple.loadConfiguration(configBase)
|
80
|
+
conf[:destinationDir] = directory
|
81
|
+
session, client, keys = Rypple.connectToDropbox(configBase)
|
82
|
+
|
83
|
+
if !conf.nil? and !keys.nil?
|
84
|
+
Rypple.cleanup(conf, keys, configBase)
|
85
|
+
end
|
86
|
+
|
87
|
+
baseCGI = DefaultCGI.dup
|
88
|
+
baseCGI.gsub!(/%%CONFIG_PATH/, configBase)
|
89
|
+
|
90
|
+
choice = false
|
91
|
+
insert = true
|
92
|
+
while !choice do
|
93
|
+
puts "Is your web host set up to use ruby gems? (y/N)"
|
94
|
+
answer = gets.chomp!.downcase!
|
95
|
+
if answer.nil? or answer.empty?
|
96
|
+
choice = true
|
97
|
+
elsif answer == "n" or answer == "y"
|
98
|
+
insert = (answer == "n")
|
99
|
+
choice = true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
if insert
|
104
|
+
gemPath = ''
|
105
|
+
if ENV.has_key?('GEM_HOME')
|
106
|
+
gemPath = ENV['GEM_HOME']
|
107
|
+
else
|
108
|
+
puts "Please enter search path for the ruby gems."
|
109
|
+
gemPath = gets.chomp!
|
110
|
+
end
|
111
|
+
|
112
|
+
baseCGI.gsub!(/%%GEM_PATH/, gemPath)
|
113
|
+
end
|
114
|
+
|
115
|
+
baseCGI.gsub!(/%%IN_DIR/, configBase)
|
116
|
+
|
117
|
+
outDir = ""
|
118
|
+
while outDir.empty? or !File.exists?(outDir) do
|
119
|
+
puts "Where should the static site generator output files?"
|
120
|
+
outDir = gets.chomp!
|
121
|
+
|
122
|
+
if !outDir.empty?
|
123
|
+
outDir = File.expand_path(outDir)
|
124
|
+
else
|
125
|
+
puts "Cannot use empty output directory, aborting."
|
126
|
+
return false
|
127
|
+
end
|
128
|
+
|
129
|
+
if !File.exists?(outDir)
|
130
|
+
begin
|
131
|
+
Dir.mkdir(outDir)
|
132
|
+
rescue SystemCallError
|
133
|
+
puts "Cannot create output directory", outDir
|
134
|
+
next
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
baseCGI.gsub!(/%%OUT_DIR/, outDir)
|
140
|
+
|
141
|
+
command = File.join("#{ENV["GEM_HOME"]}", 'bin', 'jekyll')
|
142
|
+
if File.exists?(command)
|
143
|
+
puts "Please enter any arguments to pass to jekyll"
|
144
|
+
args = gets.chomp!
|
145
|
+
baseCGI.gsub!(/%%COMMAND/, command + ' ' + args)
|
146
|
+
end
|
147
|
+
|
148
|
+
ryppleDir = File.join(configBase, 'rypple')
|
149
|
+
|
150
|
+
if !File.exists?(ryppleDir)
|
151
|
+
begin
|
152
|
+
Dir.mkdir(ryppleDir)
|
153
|
+
rescue SystemCallError
|
154
|
+
"Cannot create rypple directory."
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
File.open(File.join(ryppleDir, 'update.html'), 'w', 0644) { |f| f.puts DefaultUpdateForm }
|
159
|
+
|
160
|
+
out = File.join(ryppleDir, 'update.cgi')
|
161
|
+
File.open(out, 'w', 0755) { |f| f.puts baseCGI }
|
162
|
+
|
163
|
+
puts "Should I enable basic user authentication for the update script? (Y/n):"
|
164
|
+
|
165
|
+
answer = gets.chomp!
|
166
|
+
if answer.nil? or answer.empty? or answer.downcase! == 'y'
|
167
|
+
print "Enter user name for authentication:"
|
168
|
+
user = gets.chomp!
|
169
|
+
print "Enter password for authentication:"
|
170
|
+
chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
171
|
+
salt = chars[rand(chars.size - 1)] + chars[rand(chars.size - 1)]
|
172
|
+
pass = gets.chomp!.crypt(salt)
|
173
|
+
authFile = File.join(configBase, '.htpasswd')
|
174
|
+
File.open(authFile, 'w') { |f| f.puts "#{user}:#{pass}" }
|
175
|
+
htaccess = DefaultHTAccess.gsub(/%%AUTH_FILE/, authFile)
|
176
|
+
File.open(File.join(ryppleDir, '.htaccess'), 'w') { |f| f.puts htaccess }
|
177
|
+
end
|
178
|
+
|
179
|
+
puts "Attempting first update"
|
180
|
+
|
181
|
+
if Rypple.sync(configBase)
|
182
|
+
puts `jekyll #{configBase} #{outDir}`
|
183
|
+
else
|
184
|
+
puts "Rypple sync failed."
|
185
|
+
end
|
186
|
+
|
187
|
+
return true
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
data/lib/rypple/version.rb
CHANGED
data/lib/rypple.rb
CHANGED
@@ -1 +1,20 @@
|
|
1
|
-
|
1
|
+
#$:.unshift File.dirname(__FILE__) #For use/testing without the gem.
|
2
|
+
|
3
|
+
# Requires all ruby files in a directory.
|
4
|
+
#
|
5
|
+
# path - Relative path from here to the directory.
|
6
|
+
#
|
7
|
+
# Returns nothing
|
8
|
+
def require_all(path)
|
9
|
+
glob = File.join(File.dirname(__FILE__), path, '*.rb')
|
10
|
+
Dir[glob].each { |f| require f }
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
|
15
|
+
require 'fileutils'
|
16
|
+
require 'ftools'
|
17
|
+
require 'yaml'
|
18
|
+
require 'pathname'
|
19
|
+
|
20
|
+
require_all 'rypple'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rypple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Ziglar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: jekyll
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- bin/ryppleInstall
|
64
64
|
- lib/rypple.rb
|
65
65
|
- lib/rypple/base.rb
|
66
|
+
- lib/rypple/setup.rb
|
66
67
|
- lib/rypple/version.rb
|
67
68
|
- pkg/ripple-0.0.1.gem
|
68
69
|
- rypple.gemspec
|