Class: Volley::Publisher::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/volley/publisher/base.rb

Direct Known Subclasses

Amazons3, Local

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/volley/publisher/base.rb', line 6

def initialize(options={})
  @options = {
      :overwrite => false,
  }.merge(options)

  @debug     = optional(:debug, false)
  @encrypted = optional(:encrypted, false)
  @local     = optional(:local, Volley.config.directory)
  @loglevel  = @debug ? :info : :debug
  @latest    = {}
  @force     = false

  load_configuration
end

Instance Attribute Details

#forceObject

Returns the value of attribute force.



4
5
6
# File 'lib/volley/publisher/base.rb', line 4

def force
  @force
end

Instance Method Details

#branches(project) ⇒ Object



53
54
55
# File 'lib/volley/publisher/base.rb', line 53

def branches(project)
  raise "not implemented"
end

#contents(project, branch, version) ⇒ Object



65
66
67
# File 'lib/volley/publisher/base.rb', line 65

def contents(project, branch, version)
  raise "not implemented"
end

#delete_project(project) ⇒ Object



69
70
71
# File 'lib/volley/publisher/base.rb', line 69

def delete_project(project)
  raise "not implemented"
end

#exists?(project, branch, version) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/volley/publisher/base.rb', line 61

def exists?(project, branch, version)
  raise "not implemented"
end

#latest(project, branch) ⇒ Object



73
74
75
# File 'lib/volley/publisher/base.rb', line 73

def latest(project, branch)
  @latest["#{project}/#{branch}"] ||= pull_file(dir(project, branch), "latest")
end

#latest_release(project) ⇒ Object



81
82
83
# File 'lib/volley/publisher/base.rb', line 81

def latest_release(project)
  pull_file(project, "latest_release")
end

#latest_version(project, branch) ⇒ Object



77
78
79
# File 'lib/volley/publisher/base.rb', line 77

def latest_version(project, branch)
  latest(project, branch).split("/").last
end

#list(&block) ⇒ Object



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
# File 'lib/volley/publisher/base.rb', line 21

def list(&block)
  hash     = {}
  unsorted = {}
  plist    = projects
  plist.each do |p|
    hash[p] = {}
    blist   = branches(p)
    blist.each do |b|
      hash[p][b] = {}
      vlist      = versions(p, b)
      vlist.each do |v|
        d             = version_data(p, b, v)
        hash[p][b][v] = d
        unsorted["#{p}@#{b}:#{v}"] = d if d[:contents] && d[:contents].count > 0
      end
    end
  end

  sorted = unsorted.sort_by { |k, v| v[:timestamp] }.reverse
  sorted.each do |k, v|
    d = Volley::Descriptor.new(k)
    next unless d
    yield d.project, d.branch, d.version, v
  end

  hash
end

#projectsObject



49
50
51
# File 'lib/volley/publisher/base.rb', line 49

def projects
  raise "not implemented"
end

#pull(project, branch, version = "latest") ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/volley/publisher/base.rb', line 122

def pull(project, branch, version="latest")
  dir  = dir(project, branch, version)
  file = remote_file(branch, version)

  log "vv #{me}#pull"
  pull_file(dir, file, "#@local/#{dir}")

  "#@local/#{dir}/#{file}"
end

#push(project, branch, version, localfiles) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/volley/publisher/base.rb', line 101

def push(project, branch, version, localfiles)
  v = version == "latest" ? latest_version(project, branch) : version
  return false if exists?(project, branch, v) && !@force

  localfiles = [*localfiles].flatten
  log "^^ #{me}#push"

  dir = dir(project, branch, version)
  localfiles.each do |localfile|
    push_file(dir, localfile, File.open(localfile))
  end

  if Volley.config.volleyfile && File.file?(Volley.config.volleyfile)
    push_file(dir, "Volleyfile", File.open(Volley.config.volleyfile))
  end

  push_file(dir(project, branch), "latest", "#{project}/#{branch}/#{version}")

  true
end

#release(old, new) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/volley/publisher/base.rb', line 132

def release(old, new)
  odesc = Descriptor.new(old)
  ndesc = Descriptor.new(new)

  Dir.mktmpdir("volley-#{$$}", "/var/tmp") do |tmpdir|
    Dir.chdir(tmpdir) do
      (op, ob, ov) = odesc.get
      (p, b, v)    = ndesc.get

      Volley::Log.debug "%% #{me}#release: #{odesc} => #{ndesc} (#{tmpdir})"

      packed       = "#{b}-#{v}.tgz"
      dest         = dir(p, b, v)

      local = pull(op, ob, ov)
      system("tar xfz #{local}")

      files = Dir["**"]
      cmd = "tar cfz #{packed} #{files.join(" ")}"
      #Volley::Log.debug "-- command: #{cmd}"
      system(cmd)

      push_file(dest, packed, File.open(packed))
      push_file(dest, "Volleyfile", File.open("Volleyfile")) if File.exists?("Volleyfile")
      push_file(dest, "from", "#{op}/#{ob}/#{ov}")
      push_file(dir(p, b), "latest", "#{p}/#{b}/#{v}")
      push_file(p, "latest_release", "#{p}/#{b}/#{v}")
    end
  end

  true
end

#released_from(project, version) ⇒ Object



85
86
87
# File 'lib/volley/publisher/base.rb', line 85

def released_from(project, version)
  pull_file(dir(project, "release", version), "from")
end

#versions(project, branch) ⇒ Object



57
58
59
# File 'lib/volley/publisher/base.rb', line 57

def versions(project, branch)
  raise "not implemented"
end

#volleyfile(project, branch, version = "latest") ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/volley/publisher/base.rb', line 89

def volleyfile(project, branch, version="latest")
  d        = dir(project, branch, version)
  contents = pull_file(d, "Volleyfile")

  dest = "#@local/Volleyfile-#{Time.now.to_i}-#{$$}"
  raise "File #{dest} already exists" if File.exists?(dest)

  log "saving Volleyfile: #{dest}"
  File.open(dest, "w") { |f| f.write(contents) }
  dest
end