Class: RepoMate::Checkpoint
- Inherits:
-
Object
- Object
- RepoMate::Checkpoint
- Defined in:
- lib/repomate/checkpoint.rb
Overview
Class containing the main logic
Instance Method Summary collapse
-
#create ⇒ Object
Saves a checkpoint.
-
#create_table ⇒ Object
Create the checkpoint table.
-
#delete_package(entry) ⇒ Object
Deletes a package from checkpoint table.
-
#initialize ⇒ Checkpoint
constructor
Init.
-
#list ⇒ Object
Returns a list of checkpoints for the cli.
-
#load(number) ⇒ Object
Loads a checkpoint.
Constructor Details
Instance Method Details
#create ⇒ Object
Saves a checkpoint
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 ⇒ Object
Create the checkpoint table
22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
Deletes a package from checkpoint table
101 102 103 104 105 106 107 108 109 |
# 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 ⇒ Object
Returns a list of checkpoints for the cli
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# 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) ⇒ Object
Loads a checkpoint
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# 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 |