runeblog 0.0.77 → 0.0.78

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1569e4f78adc608707f4eb19abcb8fb93a02fbc
4
- data.tar.gz: ea6dddca0418de9a86335ed056187e28951ae952
3
+ metadata.gz: 803f8e5ff082b0e23819eb091c649075abb4d059
4
+ data.tar.gz: 98b845e49a328067bb7add5080498c9308c3c26b
5
5
  SHA512:
6
- metadata.gz: 8d97b86002bb3573ca90d4dad60606d0b274d27496e875e4fbefa9046a0265114c0d2434402467c7c3816dbda72955603b16d255acacdbc77a89b05f37d229c1
7
- data.tar.gz: 1459f0d97b66954d116307bd7b9695f81107a8ecf378e593f18aae3edf9ca67145e83101495dac973a77f1df7afd220541b738df822ea74a0e7e328708bf91ff
6
+ metadata.gz: 3f08ef8743d3426f0659b57e4fb7f008a00d80c43dd03b5e1acd387316025f1f23d1fd471ad82343905164ff218a3e4df60c572bcf3b9249faf0b43d2ba01469
7
+ data.tar.gz: 111cde858002851bb9c1074b92ed85ac012e89b445199a18317cc8033da2520fb5cdd7be9dba060d887a3c4ffcb0500432eda0b7d616a9e4e67ea4ec5be711f8
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.77 2018-10-04
1
+ RuneBlog v 0.0.78 2018-10-04
data/lib/deploy.rb CHANGED
@@ -4,6 +4,9 @@ require 'runeblog'
4
4
  class RuneBlog::Deployment
5
5
  attr_reader :user, :server, :root, :path
6
6
 
7
+ BadRemoteLogin = Exception.new("Can't login remotely")
8
+ BadRemotePerms = Exception.new("Bad remote permissions")
9
+
7
10
  def initialize(user, server, root, path, protocol = "http")
8
11
  @blog = RuneBlog.blog
9
12
  @user, @server, @root, @path =
@@ -17,9 +20,9 @@ class RuneBlog::Deployment
17
20
  def deploy(files)
18
21
  reset_output
19
22
  dir = "#@root/#@path"
20
- result = system("ssh -c #@user@#@server mkdir #{dir}")
23
+ result = system("ssh #@user@#@server -x mkdir #{dir}")
21
24
  list = files.join(' ')
22
- cmd = "scp -r #{list} root@#{server}:#{dir} >/dev/null 2>&1"
25
+ cmd = "scp -r #{list} #@user@##server:#{dir} >/dev/null 2>&1"
23
26
  output! "Deploying #{files.size} files...\n"
24
27
  result = system(cmd)
25
28
  raise "Problem occurred in deployment" unless result
@@ -28,6 +31,23 @@ class RuneBlog::Deployment
28
31
  output! "...finished.\n"
29
32
  @out
30
33
  end
34
+
35
+ def remote_login?
36
+ cmd = "ssh -o BatchMode=yes #@user@#@server -x date >/dev/null 2>&1"
37
+ result = system(cmd)
38
+ return nil unless result
39
+ true
40
+ end
41
+
42
+ def remote_permissions?
43
+ dir = "#@root/#@path"
44
+ temp = "#@path/__only_testing"
45
+ try1 = system("ssh -o BatchMode=yes -o ConnectTimeout=2 #@user@#@server -x mkdir -p #{temp} >/dev/null 2>&1")
46
+ return nil unless try1
47
+ try2 = system("ssh -o BatchMode=yes -o ConnectTimeout=2 #@user@#@server -x rmdir #{temp} >/dev/null 2>&1")
48
+ return nil unless try2
49
+ true
50
+ end
31
51
  end
32
52
 
33
53
 
data/lib/repl.rb CHANGED
@@ -19,8 +19,9 @@ module RuneBlog::REPL
19
19
  def cmd_browse
20
20
  reset_output
21
21
  check_empty(arg)
22
- url = @blog.deployment_url
23
- if url.nil?
22
+ url = @blog.view.deployer.url
23
+ # FIXME Bad logic here.
24
+ if url.nil?
24
25
  output! "Deploy first."
25
26
  return @out
26
27
  end
@@ -172,13 +173,14 @@ module RuneBlog::REPL
172
173
  end
173
174
 
174
175
  def cmd_kill(arg)
175
- reset_output
176
+ reset_output "\n"
176
177
  args = arg.split
177
178
  args.each do |x|
178
179
  # FIXME
179
- cmd_remove_post(x, false)
180
+ ret = cmd_remove_post(x.to_i, false)
181
+ output ret
180
182
  end
181
- nil
183
+ @out
182
184
  rescue => err
183
185
  error(err)
184
186
  puts err.backtrace
data/lib/runeblog.rb CHANGED
@@ -124,13 +124,6 @@ class RuneBlog
124
124
  end
125
125
  end
126
126
 
127
- def deployment_url
128
- return nil unless @deploy[@view]
129
- lines = @deploy[@view]
130
- user, server, sroot, spath = *@deploy[@view]
131
- url = "http://#{server}/#{spath}"
132
- end
133
-
134
127
  def view_files
135
128
  vdir = @blog.viewdir(@view)
136
129
  # meh
@@ -169,13 +162,13 @@ class RuneBlog
169
162
 
170
163
  def posts
171
164
  dir = self.view.dir
172
- posts = Dir.entries(dir).grep(/^0.*/)
165
+ posts = Dir.entries(dir).grep(/^\d{4}/)
173
166
  posts
174
167
  end
175
168
 
176
169
  def drafts
177
170
  dir = "#@root/src"
178
- drafts = Dir.entries(dir).grep(/^0.*.lt3/)
171
+ drafts = Dir.entries(dir).grep(/^\d{4}.*/)
179
172
  end
180
173
 
181
174
  def change_view(view)
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class RuneBlog
3
- VERSION = "0.0.77"
3
+ VERSION = "0.0.78"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/test/general.rb CHANGED
@@ -141,19 +141,74 @@ class TestREPL < Minitest::Test
141
141
  def test_012_create_remove_post!
142
142
  @blog.change_view("beta_view")
143
143
  assert @blog.view.to_s == "beta_view", "Expected beta_view"
144
- before = @blog.posts.size
144
+ nposts = @blog.posts.size
145
+ ndrafts = @blog.drafts.size
145
146
  meta = OpenStruct.new
146
147
  meta.title = "Uninteresting title"
147
148
  num = @blog.create_new_post(meta, true)
148
- assert @blog.posts.size == before + 1, "Don't see new post"
149
+
150
+ assert @blog.posts.size == nposts + 1, "Don't see new post"
149
151
  @blog.remove_post(num)
150
- @blog.delete_draft(num) # Hmm
151
- assert @blog.posts.size == before, "Failed to delete post"
152
+ assert @blog.posts.size == nposts, "Failed to delete post"
153
+
154
+ assert @blog.drafts.size == ndrafts + 1, "Don't see new draft"
155
+ @blog.delete_draft(num)
156
+ assert @blog.drafts.size == ndrafts, "Failed to delete draft"
157
+ @blog.change_view("alpha_view")
158
+ end
159
+
160
+ def test_013_slug_tests
161
+ hash = { "abcxyz" => "abcxyz", # 0-based
162
+ "abc'xyz" => "abcxyz",
163
+ 'abc"xyz' => "abcxyz",
164
+ '7%sol' => "7sol",
165
+ "only a test" => "only-a-test",
166
+ "abc xyz" => "abc--xyz", # change this behavior?
167
+ "ABCxyZ" => "abcxyz",
168
+ }
169
+ hash.each_pair.with_index do |keys, i|
170
+ real, fixed = *keys
171
+ result = @blog.make_slug(real)[1][5..-1] # weird? returns [99, "0099-whatever"]
172
+ assert result == fixed, "Case #{i}: expected: #{fixed.inspect}, got #{result.inspect}"
173
+ end
174
+ end
175
+
176
+ def test_014_remove_nonexistent_post!
177
+ @blog.change_view("alpha_view")
178
+ out = cmd_remove_post(99)
179
+ assert out =~ /Post 99 not found/, "Expected error about nonexistent post, got: #{out}"
180
+ end
181
+
182
+ def test_015_kill_multiple_posts!
152
183
  @blog.change_view("alpha_view")
184
+ out = cmd_list_posts(nil)
185
+ before = out.split("\n").length
186
+ out = cmd_kill("1 2 7")
187
+ out = cmd_list_posts(nil)
188
+ after = out.split("\n").length
189
+ assert after == before - 3, "list_posts saw #{before} posts, now #{after} (not #{before-3})"
190
+ system("ruby test/make_blog.rb") # This is hellish, I admit
153
191
  end
154
192
 
155
- def test_013_kill_posts!
156
- # Must think about this.
193
+ def test_016_can_deploy
194
+ dep = RuneBlog::Deployment.new("root", "rubyhacker.com", "/var/www", "whatever")
195
+ result = dep.remote_login?
196
+ assert result == true, "Valid login doesn't work"
197
+ result = dep.remote_permissions?
198
+ assert result == true, "Valid mkdir doesn't work"
157
199
  end
200
+
201
+ def test_017_cannot_deploy_wrong_user
202
+ dep = RuneBlog::Deployment.new("bad_user", "rubyhacker.com", "/var/www", "whatever")
203
+ result = dep.remote_login?
204
+ assert result.nil?, "Expected to detect login error (bad user)"
205
+ end
206
+
207
+ def test_018_cannot_deploy_bad_server
208
+ dep = RuneBlog::Deployment.new("root", "nonexistent123.com", "/var/www", "whatever")
209
+ result = dep.remote_login?
210
+ assert result.nil?, "Expected to detect login error (bad server)"
211
+ end
212
+
158
213
  end
159
214
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runeblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.77
4
+ version: 0.0.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton