class RepoMate::Checkpoint

Class containing the main logic

Public Class Methods

new() click to toggle source

Init

# File lib/repomate/checkpoint.rb, line 12
def initialize
  @link       = Link.new
  @cpdbfile   = File.join(Cfg.rootdir, "checkpoints.db")
  @cpdb       = Database.new(@cpdbfile)
  @metafile   = Metafile.new
  
  create_table
end

Public Instance Methods

create() click to toggle source

Saves a checkpoint

# File lib/repomate/checkpoint.rb, line 34
def create
  datetime        = DateTime.now
  source_category = "dists"

  Architecture.dataset(source_category).each do |entry|
    source = Architecture.new(entry[:architecture], entry[:component], entry[:suitename], source_category)
    source.files.each do |fullname|
      basename = File.basename(fullname)

      sql = "insert into checkpoints values (
              '#{datetime}',
              '#{entry[:suitename]}',
              '#{entry[:component]}',
              '#{entry[:architecture]}',
              '#{basename}')"

      @cpdb.query(sql)
    end
  end

  puts "Checkpoint (#{datetime.strftime("%F %T")}) saved"
end
create_table() click to toggle source

Create the checkpoint table

# File lib/repomate/checkpoint.rb, line 22
def create_table
  sql = "create table if not exists checkpoints (
          date varchar(25),
          suitename varchar(10),
          component varchar(10),
          architecture varchar(10),
          basename varchar(70))"

  @cpdb.query(sql)
end
delete_package(entry) click to toggle source

Deletes a package from checkpoint table

# File lib/repomate/checkpoint.rb, line 101
def delete_package(entry)
  sql = "delete from checkpoints where
          basename = '#{entry[:basename]}' and
          suitename = '#{entry[:suitename]}' and
          component = '#{entry[:component]}' and
          architecture = '#{entry[:architecture]}'"

  @cpdb.query(sql)
end
list() click to toggle source

Returns a list of checkpoints for the cli

# File lib/repomate/checkpoint.rb, line 112
def list
  order = 0
  dates = []
  list  = {}

  @cpdb.query("select date from checkpoints group by date order by date asc").each do |row|
    dates << row.first
  end

  dates.each do |date|
    order += 1
    list[order] = date
  end

  list
end
load(number) click to toggle source

Loads a checkpoint

# File lib/repomate/checkpoint.rb, line 58
def load(number)
  cplist          = list
  link_workload   = []
  unlink_workload = []
  source_category = "dists"

  Architecture.dataset(source_category).each do |entry|
    destination = Architecture.new(entry[:architecture], entry[:component], entry[:suitename], source_category)
    destination.files.each do |fullname|
      unlink_workload << {
        :destination_fullname => fullname,
        :component            => entry[:component],
        :suitename            => entry[:suitename],
        :architecture         => entry[:architecture]
      }
    end
  end

  @cpdb.query("select date, suitename, component, architecture, basename from checkpoints").each do |row|
    if row[0] == cplist[number]
        suitename    = row[1]
        component    = row[2]
        architecture = row[3]
        basename     = row[4]
        source       = Architecture.new(architecture, component, suitename, "pool")
        destination  = Architecture.new(architecture, component, suitename, "dists")

        link_workload << {
          :source_fullname      => File.join(source.directory, basename),
          :destination_fullname => File.join(destination.directory, basename),
          :component            => component,
          :suitename            => suitename,
          :architecture         => architecture
        }
    end
  end

  @link.destroy(unlink_workload)
  @link.create(link_workload)
  @metafile.create
end