Class: RightPublish::YumRepo

Inherits:
Repo
  • Object
show all
Defined in:
lib/right_publish/repos/yum.rb

Direct Known Subclasses

ZyppRepo

Constant Summary collapse

DEFAULT_YUM_EPEL =
1
DEFAULT_YUM_DIR =
'yum/'
DEFAULT_DESCRIPTION =
"Yum Repository"
REPO_KEY =
:yum_repo
DEFAULT_EPEL_LAYOUT =
"rightlink"
REPO_OPTIONS =
{
:dists            => :attr_optional,
:epel             => DEFAULT_YUM_EPEL,
:epel_layout      => DEFAULT_EPEL_LAYOUT,
:subdir           => DEFAULT_YUM_DIR,
:description      => DEFAULT_DESCRIPTION,
:gpg_key_id       => :attr_optional,
:gpg_password     => :attr_optional }
YUM_EXT =
'rpm'
BIN_ALL_ARCH =
'noarch'
SRC_ALL_ARCH =
'src'
SRC_ALL_PATH =
'SRPMS'
ARCHITECTURES =
[ 'x86_64' ]
PKG_TYPES =
[ ARCHITECTURES, BIN_ALL_ARCH, SRC_ALL_ARCH ]

Constants inherited from Repo

Repo::LOCK_FILE_NAME, Repo::LOCK_PERIOD, Repo::LOCK_RETRY_INTERVAL

Instance Method Summary collapse

Methods inherited from Repo

#initialize, #publish, #pull, #push

Constructor Details

This class inherits a constructor from RightPublish::Repo

Instance Method Details

#add(file_or_dir, target) ⇒ Object



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/right_publish/repos/yum.rb', line 27

def add(file_or_dir, target)
  repo_updates = {}

  get_pkg_list(file_or_dir, YUM_EXT) do |path|
    # Determine package architectures, and sort
    appropriate_repos(path, target) do |repo_path|
      repo_path = File.join(repo_config[:subdir], repo_path)
      repo_updates[repo_path] ||= []
      repo_updates[repo_path].push(path)
    end
  end
  return if repo_updates.size == 0

  full_pkg_paths = []
  repo_updates.each_pair do |repo_path, pkgs|
    pkgs.each do |pkg|
      import_pkg( pkg, repo_path )
      full_pkg_paths << File.join(repo_path, File.basename(pkg))
    end
  end
  sign_files full_pkg_paths

  # Rebuild the yum index'
  repo_updates.each_key do |repo_path|
    ( repo_path )
    ( repo_path )
  end
end

#annotate(options = {}) ⇒ Object



56
57
58
59
60
# File 'lib/right_publish/repos/yum.rb', line 56

def annotate(options={})
  options[:subdir] ||= File.join(repo_config[:subdir], '1')
  options[:filter] = ['*.rpm']
  super(options)
end

#import_pkg(pkg, repo_path) ⇒ Object



62
63
64
65
66
# File 'lib/right_publish/repos/yum.rb', line 62

def import_pkg( pkg, repo_path )
  # Remove any instances of this package at a different versionh
  yum_prune( pkg, repo_path )
  install_file( pkg, repo_path )
end

#pkg_parts(path) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/right_publish/repos/yum.rb', line 80

def pkg_parts(path)
  @infocache ||= {}
  return @infocache[path] if @infocache.has_key?(path)

  result = {:name=>nil, :version=>nil, :arch=>nil, :release=>nil}

  query = IO.popen("rpm --queryformat '%{NAME} %{VERSION} %{RELEASE} %{ARCH}' -qp #{path}")
  result[:name], result[:version], result[:release], result[:arch] = query.readline.split(' ')

  # RPM query doesn't identify package as a source package, we just
  # have to test the filename.
  result[:arch] = SRC_ALL_ARCH if path.end_with?('src.rpm')

  @infocache[path] = result
  result
end

#sign_files(pkgs) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/right_publish/repos/yum.rb', line 68

def sign_files( pkgs )
  if repo_config[:gpg_key_id]
    do_in_subdir('') do

      cmd = "rpm --define '%_gpg_name #{repo_config[:gpg_key_id]}' --addsign #{pkgs.join(' ')}"
      exited = shellout_with_password(cmd)

      raise Exception, "rpm signing failed; cannot continue publishing" unless exited
    end
  end
end