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



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

def add(file)
  file = File.expand_path(file)
  Dir.chdir(repro_dir) do
    repro.include(file)
  end
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)
  @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_id = @git.tags.map { |a| a.name =~ /^#{@version}-(.+)/; $1.to_i }.sort.last.to_i + 1
  @build_name = "#{@version}-#{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

#push_changed(dir, &blk) ⇒ Object



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

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gaffer/base.rb', line 52

def repro
  options = {}

  options[:aws_key]    ||= ENV['AWS_ACCESS_KEY_ID']
  options[:aws_secret] ||= ENV['AWS_SECRET_ACCESS_KEY']
  options[:bucket]     ||= ENV['REP_BUCKET']
  options[:email]      ||= ENV['REP_EMAIL']
  options[:maintainer] ||= ENV['REP_MAINTAINER']
  options[:key]        ||= options[:email]

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

  dir = repro_dir

  puts "Repo: #{dir}"

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

#repro_dirObject



73
74
75
76
77
78
79
# File 'lib/gaffer/base.rb', line 73

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

#repro_ready?Boolean

Returns:

  • (Boolean)


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

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