Class: RuneBlog::Publishing
- Inherits:
-
Object
- Object
- RuneBlog::Publishing
- Defined in:
- lib/runeblog_version.rb,
lib/publish.rb
Constant Summary collapse
- BadRemoteLogin =
Exception.new("Can't login remotely")
- BadRemotePerms =
Exception.new("Bad remote permissions")
Instance Attribute Summary collapse
-
#docroot ⇒ Object
readonly
Returns the value of attribute docroot.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(view) ⇒ Publishing
constructor
A new instance of Publishing.
- #publish(files, assets = []) ⇒ Object
- #remote_login? ⇒ Boolean
- #remote_permissions? ⇒ Boolean
- #system!(str) ⇒ Object
- #to_h ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(view) ⇒ Publishing
Returns a new instance of Publishing.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/publish.rb', line 14 def initialize(view) log!(enter: __method__, args: [view.to_s]) @blog = RuneBlog.blog gfile = @blog.root/:views/view/"themes/standard/global.lt3" data = File.readlines(gfile) # Please refactor the Hal out of this grab = ->(var) { data.grep(/^#{var} /).first.chomp.split(" ", 2)[1] } @user = grab.call("publish.user") @server = grab.call("publish.server") @docroot = grab.call("publish.docroot") @path = grab.call("publish.path") @proto = grab.call("publish.proto") end |
Instance Attribute Details
#docroot ⇒ Object (readonly)
Returns the value of attribute docroot.
8 9 10 |
# File 'lib/publish.rb', line 8 def docroot @docroot end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/publish.rb', line 8 def path @path end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/publish.rb', line 8 def server @server end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/publish.rb', line 8 def user @user end |
Instance Method Details
#publish(files, assets = []) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/publish.rb', line 46 def publish(files, assets=[]) log!(enter: __method__, args: [files, assets], level: 1) dir = @docroot/@path view_name = @blog.view.name viewpath = dir # /view_name result = system!("ssh #@user@#@server -x mkdir -p #{viewpath}/assets") files.each do |file| dest = "#@user@#@server:" + dir # /view_name file.gsub!(/\/\//, "/") # weird... :-/ cmd = "scp -r #{file} #{dest} >/dev/null 2>/tmp/wtf" debug "cmd = #{cmd.inspect} - see /tmp/wtf" result = system!(cmd) || puts("\n Could not copy #{file} to #{dest}") end unless assets.empty? cmd = "scp #{assets.join(' ')} #@user@#@server:#{viewpath}/assets >/dev/null 2>/tmp/wtf2" result = system!(cmd) raise PublishError if !result end dump(files, "#{@blog.view.dir}/last_published") true end |
#remote_login? ⇒ Boolean
68 69 70 71 72 73 74 |
# File 'lib/publish.rb', line 68 def remote_login? log!(enter: __method__) cmd = "ssh -o BatchMode=yes #@user@#@server -x date >/dev/null 2>&1" result = system(cmd) return nil unless result true end |
#remote_permissions? ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/publish.rb', line 76 def log!(enter: __method__) dir = @docroot/@path temp = @path/"__only_testing" try1 = system("ssh -o BatchMode=yes -o ConnectTimeout=1 #@user@#@server -x mkdir -p #{temp} >/dev/null 2>&1") return nil unless try1 try2 = system("ssh -o BatchMode=yes -o ConnectTimeout=1 #@user@#@server -x rmdir #{temp} >/dev/null 2>&1") return nil unless try2 true end |
#system!(str) ⇒ Object
40 41 42 43 44 |
# File 'lib/publish.rb', line 40 def system!(str) log!(enter: __method__, args: [str], level: 1) rc = system(str) rc end |
#to_h ⇒ Object
28 29 30 31 32 |
# File 'lib/publish.rb', line 28 def to_h log!(enter: __method__, level: 3) {user: @user, server: @server, docroot: @docroot, path: @path, proto: @proto} end |
#url ⇒ Object
34 35 36 37 38 |
# File 'lib/publish.rb', line 34 def url log!(enter: __method__, level: 3) vname = @blog.view.name # .gsub(/_/, "\\_") url = "#@proto://#@server/#@path" # /#{vname}" end |