Class: RuneBlog::Publishing

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ Publishing

Returns a new instance of Publishing.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/publish.rb', line 14

def initialize(view)
  log!(enter: __method__, args: [view.to_s])
  @blog = RuneBlog.blog
  dir = @blog.root/:views/view/"themes/standard/"
  gfile = dir/"global.lt3"
  return unless File.exist?(gfile)  # FIXME Hackish as hell

  live = get_live_vars(gfile)
  @user    = live.vars["publish.user"]
  @server  = live.vars["publish.server"]
  @docroot = live.vars["publish.docroot"]
  @path    = live.vars["publish.path"]
  @proto   = live.vars["publish.proto"]
end

Instance Attribute Details

#docrootObject (readonly)

Returns the value of attribute docroot.



9
10
11
# File 'lib/publish.rb', line 9

def docroot
  @docroot
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/publish.rb', line 9

def path
  @path
end

#serverObject (readonly)

Returns the value of attribute server.



9
10
11
# File 'lib/publish.rb', line 9

def server
  @server
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/publish.rb', line 9

def user
  @user
end

Instance Method Details

#publishObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/publish.rb', line 41

def publish
  log!(enter: __method__, level: 1)
  dir = @docroot/@path
  view_name = @blog.view.name
  viewpath = dir # /view_name
  # FIXME rsync doesn't work
  cmd = "rsync -r -z #{@blog.root}/views/#{@blog.view}/remote/ #@user@#@server:#{viewpath}/"
  system!(cmd)
  dump("#{@blog.view} at #{Time.now}", "#{@blog.view.dir}/last_published")
  true
end

#remote_login?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/publish.rb', line 53

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

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
70
# File 'lib/publish.rb', line 61

def remote_permissions?
  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

#to_hObject



29
30
31
32
33
# File 'lib/publish.rb', line 29

def to_h
  log!(enter: __method__, level: 3)
  {user: @user, server: @server, docroot: @docroot,
   path: @path, proto: @proto}
end

#urlObject



35
36
37
38
39
# File 'lib/publish.rb', line 35

def url
  log!(enter: __method__, level: 3)
  vname = @blog.view.name # .gsub(/_/, "\\_")
  url = "#@proto://#@server/#@path"  # /#{vname}"
end