Class: Gaffer::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/gaffer/base.rb', line 5

def initialize(options)
  @force = options[:force]
end

Instance Attribute Details

#build_nameObject

Returns the value of attribute build_name.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def build_name
  @build_name
end

#dependsObject

Returns the value of attribute depends.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def depends
  @depends
end

#dirObject

Returns the value of attribute dir.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def dir
  @dir
end

#gitObject

Returns the value of attribute git.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def git
  @git
end

#maintainerObject

Returns the value of attribute maintainer.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def maintainer
  @maintainer
end

#prefixObject

Returns the value of attribute prefix.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def prefix
  @prefix
end

#projectObject

Returns the value of attribute project.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def project
  @project
end

#readmeObject

Returns the value of attribute readme.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def readme
  @readme
end

#versionObject

Returns the value of attribute version.



3
4
5
# File 'lib/gaffer/base.rb', line 3

def version
  @version
end

Instance Method Details

#add(file) ⇒ Object



46
47
48
# File 'lib/gaffer/base.rb', line 46

def add(file)
  repro.include(file)
end

#build(dir) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gaffer/base.rb', line 9

def build(dir)
  @dir     = dir
  @git     = Git::open(dir)

  @project = File::basename(File::dirname(@git.repo.path))
  @maintainer = "#{@git.config["user.name"]} <#{@git.config["user.email"]}>"
  @prefix  = "opt/#{@project}"

  @readme  = File::read("#{dir}/README") rescue "no README file"
  @depends = File::read("#{dir}/DEPENDS").chomp rescue "libc6 (>= 2.10)"
  @version = File::read("#{dir}/VERSION").chomp

  raise "Bad version #{@version}" unless @version =~ /^\d+[.]\d+[.]\d+$/

  @build_name = "#{@version}-#{next_build_id}"

  puts "======> #{@version.inspect}"

  @git.add_tag(@build_name)
  ## check version - tag repo

  Gaffer::Deb::new(self, project, depends).build
#      Gaffer::Deb::new(self, "#{project}-dev", "#{project} (>= #{@version})").build
end

#git_build_idObject



34
35
36
# File 'lib/gaffer/base.rb', line 34

def git_build_id
  @git.tags.map { |a| a.name =~ /^#{@version}-(.+)/; $1.to_i }.sort.last.to_i
end

#next_build_idObject



42
43
44
# File 'lib/gaffer/base.rb', line 42

def next_build_id
  [git_build_id, repro_build_id].max + 1
end

#push_changed(dir, &blk) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/gaffer/base.rb', line 50

def push_changed(dir, &blk)
  # I can optimze later
  start = Time::now
  Dir.chdir(dir) do
    blk.call
    Dir["**/*"].select { |file| File::stat(file).mtime >= start }.each do |file|
      puts "PUSHING: #{f}"
    end
  end
end

#reproObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gaffer/base.rb', line 61

def repro
  options = {}

  options[:aws_key]    ||= ENV['AWS_ACCESS_KEY_ID']
  options[:aws_secret] ||= ENV['AWS_SECRET_ACCESS_KEY']
  options[:bucket]     ||= ENV['GAFFER_BUCKET']
  options[:email]      ||= ENV['GAFFER_EMAIL']
  options[:maintainer] ||= ENV['GAFFER_MAINTAINER']
  options[:key]        ||= ENV['GAFFER_KEY']
  options[:key]        ||= options[:email]

  options[:codename]   ||= "maverick"
  options[:components] ||= "main"
  options[:force]      ||= !!@force

  Gaffer::Repro.new(repro_dir, options)
end

#repro_build_idObject



38
39
40
# File 'lib/gaffer/base.rb', line 38

def repro_build_id
  repro.packages.map { |p| p =~ /^#{@project}_#{@version}-(\d+)_/; $1 }.reject { |x| x.nil? }.max.to_i rescue 0
end

#repro_dirObject



79
80
81
82
83
84
85
# File 'lib/gaffer/base.rb', line 79

def repro_dir
  if ENV['HOME']
    "#{ENV['HOME']}/.gaffer/repo"
  else
    "/var/lib/gaffer/repo"
  end
end

#repro_ready?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/gaffer/base.rb', line 87

def repro_ready?
  File.exists? "#{repro_dir}/ubuntu/conf/distributions"
end