Class: Publisher::Samba

Inherits:
Object
  • Object
show all
Defined in:
lib/depengine/publisher/samba.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#samba_mountpointsObject

Returns the value of attribute samba_mountpoints.



5
6
7
# File 'lib/depengine/publisher/samba.rb', line 5

def samba_mountpoints
  @samba_mountpoints
end

#samba_shareObject

Returns the value of attribute samba_share.



4
5
6
# File 'lib/depengine/publisher/samba.rb', line 4

def samba_share
  @samba_share
end

#workerObject

Returns the value of attribute worker.



6
7
8
# File 'lib/depengine/publisher/samba.rb', line 6

def worker
  @worker
end

Instance Method Details

#chmod(path, permissions, options = {}) ⇒ Object



56
57
58
59
# File 'lib/depengine/publisher/samba.rb', line 56

def chmod(path, permissions, options={})
  $log.writer.fatal "Not yet implemented"
  exit 1
end

#copy(source, target, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/depengine/publisher/samba.rb', line 8

def copy(source, target, options={})
  Helper.validates_presence_of samba_mountpoints, "Samba mountpoints not set"
  Helper.validates_presence_of samba_share, "Samba Share not set"

  begin
    begin
      # mount
      worker.samba_mount(samba_share,"#{samba_mountpoints}/#{samba_share}")

      to = "#{samba_mountpoints}/#{samba_share}/#{target}"
      ### create target directory
      if not File.directory?(to)
        if not FileUtils.mkdir_p(to)
          $log.writer.error "Unable to create target directory #{to}"
          exit 1
        end
      end

      # local rsync
      shell_cmd = "rsync -a --delete #{source} #{to}"
      $log.writer.debug "Execute command: #{shell_cmd}"
      output = system shell_cmd
      if not output
        $log.writer.error "#{method} #{shell_cmd} failed"
        exit 1
      end
      $log.writer.info output

      # umount
      worker.samba_umount("#{samba_mountpoints}/#{samba_share}")

    rescue Exception => e
      $log.writer.error "Can not publish files using samba"
      $log.writer.error e.message
      $log.writer.error e.backtrace.join("\n")
      worker.samba_umount("#{samba_mountpoints}/#{samba_share}")
      exit 1
    end

  rescue Exception => e
    $log.writer.error "Can not upload files to #{target}"
    $log.writer.error e.message
    $log.writer.error e.backtrace.join("\n")
    exit 1
  end

end