post 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71e5d93a8fa103a0210b3230edefb0ec82dbf29e
4
+ data.tar.gz: 51c4860ebc76a4258996d7df65447d1e31b0fdd0
5
+ SHA512:
6
+ metadata.gz: 246d4aa22656ad872c6f45359ba7ffbf6c17d5d94fe369714e3b1c7e289369c2e821abe1a486d61bad3ab3c9d48a5b800a58a4231f61cbf53b01a5f64c48b8a3
7
+ data.tar.gz: 251e352bc80155e058c3e713fdf29c6235bd5c3c261f138b9e51616c68ad0633ae2a526a775601abcb824d7ee1f304b14022ca7501b5811f89a910c430e57df9
data/bin/post ADDED
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/ruby
2
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
3
+ # This file is part of Post.
4
+ # Post is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Lesser General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # Post is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Lesser General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU Lesser General Public License
15
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ STDOUT.sync = true
18
+ PWD = Dir.pwd()
19
+
20
+ require('rubygems')
21
+ require('post')
22
+ require('optparse')
23
+ require('fileutils')
24
+
25
+ LOGFILE = File.open("/var/log/post.log", "a")
26
+
27
+ def puts(x, stdout = true)
28
+ message = "#{Time.now}: #{x}"
29
+ LOGFILE.puts(message)
30
+ if (stdout)
31
+ print("#{x}")
32
+ end
33
+ end
34
+
35
+ class PostFetch < Fetch
36
+ def get_file(url, file)
37
+ url = URI.parse(url)
38
+ file_name = File.basename(file)
39
+ saved_file = File.open(file, 'w')
40
+
41
+ Net::HTTP.new(url.host, url.port).request_get(url.path) do |response|
42
+ length = response['Content-Length'].to_i
43
+ saved_file_length = 0.0
44
+ response.read_body do |fragment|
45
+ saved_file << fragment
46
+ saved_file_length += fragment.length
47
+ progress = (saved_file_length / length) * 100
48
+ print("\rFetching: #{file_name} [#{progress.round}%]")
49
+ end
50
+ end
51
+ saved_file.close()
52
+ print("\r")
53
+ puts("Fetched: #{file_name} [100%]\n")
54
+ end
55
+ end
56
+
57
+ DATA = PackageDataBase.new()
58
+
59
+ OPTIONS = {}
60
+ OPTIONS[:root] = '/'
61
+
62
+ puts('Loading: Downloading package information.', stdout = false)
63
+ DATA.update_database()
64
+
65
+ def confirmation(queue)
66
+ return false if queue.empty?
67
+ puts("Queue: #{queue.to_a.join(" ")}\n")
68
+ puts('Confirm: [y/n] ')
69
+ return true if gets.include?('y')
70
+ end
71
+
72
+ def install_local_packages(args)
73
+ install = Fetch.new()
74
+ args.each do |package|
75
+ path = File.join(File.expand_path(PWD), package)
76
+ puts path
77
+ FileUtils.cp(path, "/tmp/post/#{File.basename(path)}")
78
+ end
79
+ if confirmation(args)
80
+ args.each { |package| install.do_install(File.basename(package)) }
81
+ end
82
+ end
83
+
84
+ def install_packages(args)
85
+ queue = PackageList.new(OPTIONS[:root])
86
+ fetch = PostFetch.new(OPTIONS[:root])
87
+
88
+ begin
89
+ args.each { |package| queue.push(package) }
90
+ if confirmation(queue)
91
+ queue.each do |package|
92
+ fetch.fetch_package(package)
93
+ puts("Installing: #{package}\n")
94
+ fetch.install_package(package)
95
+ end
96
+ end
97
+ rescue MismatchedHash => error
98
+ puts(error.message)
99
+ rescue ConflictingEntry => error
100
+ puts(error.message)
101
+ end
102
+ end
103
+
104
+ def remove_packages(args)
105
+ queue = PackageList.new(OPTIONS[:root])
106
+ args.each do |package|
107
+ queue.set(package) if DATA.installed?(package)
108
+ end
109
+ erase = Erase.new(OPTIONS[:root])
110
+ if confirmation(queue)
111
+ queue.each { |package| puts("Removing: #{package}\n") }
112
+ queue.each { |package| erase.remove_package(package) }
113
+ end
114
+ end
115
+
116
+ options = ARGV.options()
117
+ options.set_summary_indent(' ')
118
+ options.banner = "Usage: post [OPTIONS] [PACKAGES]"
119
+ options.version = "Post 2.0 (2.0.3)"
120
+ options.define_head "Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>"
121
+
122
+ options.on( '--root=OPT', String, "Change the root filesystem." ) do |arg|
123
+ OPTIONS[:root] = arg
124
+ DATA.set_root(OPTIONS[:root])
125
+ DATA.update_database()
126
+ end
127
+ options.on('-i', '--fetch PACKAGES', Array,
128
+ 'Install a package.') { |args| install_packages(args) }
129
+ options.on('-l', '--install PACKAGES', Array,
130
+ 'Install a local package.') { |args| install_local_packages(args) }
131
+ options.on('-r', '--erase PACKAGES', Array,
132
+ 'Erase a package.') { |args| remove_packages(args) }
133
+ options.on('-u', '--upgrade',
134
+ 'Upgrade packages to latest versions') do
135
+ packages = DATA.get_installed_packages()
136
+ install_packages(packages)
137
+ end
138
+
139
+ options.on('-h', '--help', 'Show this help message.') { puts(options) }
140
+ options.on('-v', '--version', 'Show version information.') { puts( options.version() ) }
141
+ options.parse!
data/bin/postdb ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/ruby
2
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
3
+ # This file is part of Post.
4
+ # Post is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Lesser General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # Post is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Lesser General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU Lesser General Public License
15
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require('rubygems')
18
+ require('post')
19
+ require('optparse')
20
+
21
+ DATA = PackageDataBase.new()
22
+
23
+ options = ARGV.options()
24
+ options.set_summary_indent(' ')
25
+ options.banner = "Usage: postdb [OPTIONS] [PACKAGES]"
26
+ options.version = "Post Database 2.0 (2.0.0)"
27
+ options.define_head "Copyright (C) Thomas Chace 2011-2012 <tchacex@gmail.com>"
28
+
29
+ options.on('--depends PACKAGE', String,
30
+ 'Get dependencies.') do |arg|
31
+ puts DATA.get_sync_data(arg)['dependencies'] if DATA.available?(arg)
32
+ end
33
+ options.on('--version PACKAGE', String,
34
+ 'Get latest version.') do |arg|
35
+ puts DATA.get_sync_data(arg)['version'] if DATA.available?(arg)
36
+ end
37
+ options.on('--conflicts PACKAGE', String,
38
+ 'Get conflicts.') do |arg|
39
+ puts DATA.get_sync_data(arg)['conflicts'] if DATA.available?(arg)
40
+ end
41
+ options.on('--description PACKAGE', String,
42
+ 'Get conflicts.') do |arg|
43
+ puts DATA.get_sync_data(arg)['description'] if DATA.available?(arg)
44
+ end
45
+ options.on('--files PACKAGE', String,
46
+ 'Get installed files.') do |arg|
47
+ puts DATA.get_files(arg) if DATA.available?(arg)
48
+ end
49
+
50
+
51
+ options.on('--availablepackages',
52
+ 'Get available packages.') { puts DATA.get_available_packages }
53
+ options.on('--packages',
54
+ 'Get installed packages.') { puts DATA.get_installed_packages }
55
+
56
+ options.on('-h', '--help', 'Show this help message.') { puts(options) }
57
+ options.parse!
data/lib/erase.rb ADDED
@@ -0,0 +1,36 @@
1
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
2
+ # This file is part of Post.
3
+ # Post is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # Post is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require(File.join(File.dirname(__FILE__), "packagedata.rb"))
17
+ require('fileutils')
18
+
19
+ class Erase
20
+ include FileUtils
21
+ def initialize(root = '/')
22
+ @root = root
23
+ @database = PackageDataBase.new(@root)
24
+ end
25
+
26
+ def remove_package(package)
27
+ remove_script = @database.get_remove_script(package)
28
+
29
+ @database.get_files(package).each do |file|
30
+ file = "#{@root}/#{file.strip}"
31
+ rm(file) if FileTest.exists?(file)
32
+ end
33
+ eval(remove_script)
34
+ @database.remove_package(package)
35
+ end
36
+ end
data/lib/fetch.rb ADDED
@@ -0,0 +1,106 @@
1
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
2
+ # This file is part of Post.
3
+ # Post is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # Post is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ class MismatchedHash < Exception
17
+ end
18
+
19
+ class IncompleteError < Exception
20
+ end
21
+
22
+ require('digest')
23
+ require('net/http')
24
+
25
+ require(File.join(File.dirname(__FILE__), "packagedata.rb"))
26
+ require(File.join(File.dirname(__FILE__), "tools.rb"))
27
+
28
+ class Fetch
29
+ include FileUtils
30
+ def initialize(root = '/')
31
+ @root = root
32
+ rm_r("/tmp/post") if File.exists?("/tmp/post")
33
+ mkdir("/tmp/post")
34
+ cd("/tmp/post")
35
+ @database = PackageDataBase.new(@root)
36
+ end
37
+
38
+ def get_file(url, file)
39
+ url = URI.parse(url)
40
+ filename = File.basename(file)
41
+ saved_file = File.open(file, 'w')
42
+
43
+ Net::HTTP.new(url.host, url.port).request_get(url.path) do |response|
44
+ length = response['Content-Length'].to_i
45
+ saved_file_length = 0.0
46
+ response.read_body do |fragment|
47
+ saved_file << fragment
48
+ saved_file_length += fragment.length
49
+ progress = (saved_file_length / length) * 100
50
+ end
51
+ end
52
+ saved_file.close()
53
+ end
54
+
55
+ def fetch_package(package, output = true)
56
+ mkdir_p("/tmp/post/#{package}")
57
+
58
+ sync_data = @database.get_sync_data(package)
59
+ repo_url = @database.get_url(@database.get_repo(package))
60
+
61
+ file = "#{package}-#{sync_data['version']}-#{sync_data['architecture']}.pst"
62
+ url = ("#{repo_url}/#{file}")
63
+ begin
64
+ if url.include?('file://')
65
+ url.sub!("file://", '')
66
+ cp(url, "/tmp/post/#{package}/#{file}")
67
+ cp(url + ".sha256", "/tmp/post/#{package}/#{file}.sha256")
68
+ else
69
+ get_file(url, "/tmp/post/#{package}/#{file}")
70
+ get_file(url + ".sha256", "/tmp/post/#{package}/#{file}.sha256")
71
+ end
72
+ rescue
73
+ raise IncompleteError, "Error: '#{url}' does not exist."
74
+ end
75
+
76
+ end
77
+
78
+ def do_install(filename)
79
+
80
+ extract(filename)
81
+ rm(filename)
82
+ new_files = Dir["**/*"].reject {|file| File.directory?(file) }
83
+ new_directories = Dir["**/*"].reject {|file| File.file?(file) }
84
+ @database.install_package(".packageData", ".remove", new_files)
85
+ new_directories.each { |directory| mkdir_p("#{@root}/#{directory}") }
86
+ for file in new_files
87
+ install(file, "#{@root}/#{file}")
88
+ system("chmod +x #{@root}/#{file}") if file.include?("/bin/")
89
+ end
90
+ install_script = File.read(".install")
91
+ eval(install_script)
92
+ end
93
+
94
+ def install_package(package)
95
+ cd("/tmp/post/#{package}")
96
+ sync_data = @database.get_sync_data(package)
97
+ filename = "#{package}-#{sync_data['version']}-#{sync_data['architecture']}.pst"
98
+ file_hash = Digest::SHA256.hexdigest(open(filename, "r").read())
99
+ real_hash = File.open("#{filename}.sha256").read().strip()
100
+ unless (file_hash == real_hash)
101
+ raise MismatchedHash, "Error: #{filename} is corrupt."
102
+ end
103
+ rm("#{filename}.sha256")
104
+ do_install(filename)
105
+ end
106
+ end
@@ -0,0 +1,250 @@
1
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
2
+ # This file is part of Post.
3
+ # Post is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # Post is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require('yaml')
17
+ require('open-uri')
18
+ require('fileutils')
19
+ require('rbconfig')
20
+ require('zlib')
21
+
22
+ def runs_on_this?(arch)
23
+ platform = RbConfig::CONFIG['host_cpu']
24
+ if platform == 'x86_64'
25
+ complist = ['i386', 'i486', 'i686', 'x86_64']
26
+ elsif platform == 'i686'
27
+ complist = ['i386', 'i486', 'i686']
28
+ elsif platform == 'i486'
29
+ complist = ['i386', 'i486', 'i686']
30
+ else
31
+ complist = platform
32
+ end
33
+
34
+ if complist.include?(arch)
35
+ return true
36
+ else
37
+ return false
38
+ end
39
+ end
40
+
41
+ class PackageDataBase
42
+ include FileUtils
43
+ def initialize(root = '/')
44
+ @repos = []
45
+ set_root(root)
46
+ end
47
+
48
+ def get_root()
49
+ @root
50
+ end
51
+
52
+ def set_root(root)
53
+ @root = root
54
+ @database_location = "#{@root}/var/lib/post/"
55
+ @install_database = File.join(@database_location, "installed")
56
+ @sync_database = File.join(@database_location, "available")
57
+ unless File.exist?(@database_location)
58
+ mkdir_p(@install_database)
59
+ mkdir_p(@sync_database)
60
+ end
61
+ end
62
+
63
+ def get_data(package)
64
+ begin
65
+ package_data = File.join(@install_database, package, 'packageData')
66
+ data = normalise(YAML::load_file(package_data))
67
+ rescue
68
+ data = {}
69
+ data['version'] = "0"
70
+ end
71
+ return data
72
+ end
73
+
74
+ def normalise(data)
75
+ data['version'] = data['version'].to_s()
76
+
77
+ data['conflicts'] = [] if data['conflicts'] == nil
78
+ data['dependencies'] = [] if data['dependencies'] == nil
79
+ data['version'] = "0" if data['version'].empty?
80
+ return data
81
+ end
82
+
83
+ def get_repos()
84
+ list = Dir.entries("/etc/post/repos.d")
85
+ list.delete('.')
86
+ list.delete('..')
87
+ return list
88
+ end
89
+
90
+ def get_repo(package)
91
+
92
+ package_repo = ""
93
+ version = "0"
94
+
95
+ get_repos.each do |repo|
96
+ data = Dir["#{@sync_database}/#{repo}/*"].map { |pack| File.basename(pack) }
97
+ data.each do |member|
98
+ if member == package
99
+ package_repo = repo
100
+ package_data = File.join(@sync_database + "/" + repo, package)
101
+ data = normalise(YAML::load_file(package_data))
102
+ unless (runs_on_this?(data['architecture'].to_s))
103
+ data['version'] = "0"
104
+ end
105
+ if version >= data['version']
106
+ version = data['version']
107
+ package_repo = repo
108
+ end
109
+
110
+ end
111
+ end
112
+ end
113
+ return package_repo
114
+ end
115
+
116
+ def get_sync_data(package)
117
+ repo = File.join(@sync_database, get_repo(package))
118
+ package_data = File.join(repo, package)
119
+ data = normalise(YAML::load_file(package_data))
120
+
121
+ unless (runs_on_this?(data['architecture'].to_s))
122
+ data['version'] = "0"
123
+ end
124
+ return data
125
+ end
126
+
127
+ def get_files(package)
128
+ file = File.join(@install_database, package, 'files')
129
+ file_list = []
130
+ IO.readlines(file).each do |entry|
131
+ file_list.push(entry)
132
+ end
133
+ return file_list
134
+ end
135
+
136
+ def get_remove_script(package)
137
+ remove_script = File.join(@install_database, package, 'remove')
138
+ File.read(remove_script)
139
+ end
140
+
141
+ def install_package(package_data, remove_file, installed_files)
142
+ data = YAML::load_file(package_data)
143
+
144
+ dir_name = File.join(@install_database, data['name'])
145
+ file_name = File.join(dir_name, 'files')
146
+ package_data_name = File.join(dir_name, 'packageData')
147
+ remove_file_name = File.join(dir_name, 'remove')
148
+
149
+ mkdir_p(dir_name)
150
+ install(package_data, package_data_name)
151
+ install(remove_file, remove_file_name)
152
+
153
+ file = open(file_name, 'w')
154
+ file.puts(installed_files)
155
+ end
156
+
157
+ def remove_package(package)
158
+ dir_name = File.join(@install_database, package)
159
+ rm_r(dir_name)
160
+ end
161
+
162
+ def get_available_packages()
163
+ list = []
164
+ for repo in get_repos
165
+ list += Dir["#{@sync_database}/#{repo}/*"].map() { |package| File.basename(package) }
166
+ list.delete("repo.yaml")
167
+ end
168
+ return list
169
+ end
170
+
171
+ def get_group_repo(group)
172
+ group_repo = nil
173
+ for repo in get_repos
174
+ data = YAML::load_file("#{@sync_database}/#{repo}/repo.yaml")
175
+ unless data[group] == nil
176
+ group_repo = repo
177
+ end
178
+ end
179
+ return group_repo
180
+ end
181
+
182
+ def get_repodata(repo)
183
+ if get_repos.include?(repo)
184
+ return YAML::load_file("#{@sync_database}/#{repo}/repo.yaml")
185
+ else
186
+ return {}
187
+ end
188
+ end
189
+
190
+ def get_installed_packages()
191
+ Dir["#{@install_database}/*"].map() { |package| File.basename(package) }
192
+ end
193
+
194
+ def installed?(package)
195
+ true if get_installed_packages.include?(package)
196
+ end
197
+
198
+ def available?(package)
199
+ true if get_available_packages.include?(package)
200
+ end
201
+
202
+ def upgrade?(package)
203
+ true if (available?(package)) and (get_sync_data(package)['version'] > get_data(package)['version'])
204
+ end
205
+
206
+ def get_url(repo)
207
+ data = YAML::load_file("/etc/post/repos.d/#{repo}")
208
+ return data['url']
209
+ end
210
+
211
+ def update_database()
212
+ rm_r("/tmp/post") if (File.exists?("/tmp/post"))
213
+ rm_r(@sync_database) if (File.exists?(@sync_database))
214
+
215
+ mkdir_p("/tmp/post")
216
+ cd("/tmp/post")
217
+ mkdir_p(@sync_database)
218
+
219
+ for repo in get_repos
220
+
221
+ source_url = get_url(repo) + '/info.tar'
222
+ if source_url.include?("file://")
223
+ source_url.sub!("file://", '')
224
+ cp(source_url, 'info.tar')
225
+ else
226
+ File.open('info.tar', 'w') do |file|
227
+ file.puts(open(source_url).read)
228
+ end
229
+ end
230
+
231
+ system("tar xf info.tar")
232
+ cp_r('info', "#{@sync_database}/#{repo}")
233
+
234
+ source_url = get_url(repo) + '/repo.yaml'
235
+ if source_url.include?("file://")
236
+ source_url.sub!("file://", '')
237
+ cp(source_url, 'repo.yaml')
238
+ else
239
+ File.open('repo.yaml', 'w') do |file|
240
+ file.puts(open(source_url).read)
241
+ end
242
+ end
243
+ cp_r('repo.yaml', "#{@sync_database}/#{repo}/repo.yaml")
244
+ rm('repo.yaml')
245
+ rm('info.tar')
246
+ rm_r('info')
247
+ end
248
+ end
249
+ end
250
+
@@ -0,0 +1,82 @@
1
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
2
+ # This file is part of Post.
3
+ # Post is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # Post is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require(File.join(File.dirname(__FILE__), "packagedata.rb"))
17
+
18
+ class ConflictingEntry < Exception
19
+ end
20
+
21
+ class PackageList
22
+ include Enumerable
23
+
24
+ def initialize(root = '/')
25
+ @size = 0
26
+ @database = PackageDataBase.new(root)
27
+ end
28
+
29
+ def push(package)
30
+ group = []
31
+ repo = @database.get_group_repo(package).to_s
32
+ group = @database.get_repodata(repo)[package].to_a
33
+ if (group.to_a.empty?) and (@database.upgrade?(package))
34
+ deps = @database.get_sync_data(package)['dependencies']
35
+ deps.each { |dependency| push(dependency) }
36
+ set(package)
37
+ else
38
+ group.each { |member| push(member) }
39
+ end
40
+ end
41
+
42
+ def [](n)
43
+ instance_variable_get("@a#{n}")
44
+ end
45
+
46
+ def length
47
+ @size
48
+ end
49
+
50
+ def each
51
+ 0.upto(@size - 1) { |n| yield self[n] }
52
+ end
53
+
54
+ def empty?()
55
+ return true unless (@size > 0)
56
+ end
57
+
58
+ def include?(package)
59
+ for value in self
60
+ return true if (value == package)
61
+ end
62
+ return false
63
+ end
64
+
65
+ def set(variable)
66
+ unless (include?(variable))
67
+ conflict?(variable)
68
+ instance_variable_set("@a#{@size}".to_sym, variable)
69
+ @size += 1
70
+ end
71
+ end
72
+
73
+ def conflict?(variable)
74
+ for conflict in @database.get_sync_data(variable)['conflicts']
75
+ raise ConflictingEntry,
76
+ "Error: '#{conflict}' conflicts with '#{variable}'" if include?(conflict)
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+
data/lib/post.rb ADDED
@@ -0,0 +1,23 @@
1
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
2
+ # This file is part of Post.
3
+ # Post is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # Post is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ directory = File.dirname(__FILE__)
17
+ path = File.expand_path(directory)
18
+
19
+ require(File.join(path, 'fetch.rb'))
20
+ require(File.join(path, 'erase.rb'))
21
+ require(File.join(path, 'packagedata.rb'))
22
+ require(File.join(path, "tools.rb"))
23
+ require(File.join(path, "packagelist.rb"))
data/lib/tools.rb ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright (C) Thomas Chace 2011-2013 <tchacex@gmail.com>
2
+ # This file is part of Post.
3
+ # Post is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+
8
+ # Post is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Post. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ def extract(filename)
17
+ system("mv #{filename} #{filename}.xz")
18
+ system("unxz #{filename}.xz")
19
+ system("tar xf #{filename}")
20
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: post
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Chace
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Small, fast package manager in pure Ruby.
14
+ email: tchacex@gmail.com
15
+ executables:
16
+ - post
17
+ - postdb
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/post.rb
22
+ - lib/fetch.rb
23
+ - lib/erase.rb
24
+ - lib/packagelist.rb
25
+ - lib/packagedata.rb
26
+ - lib/tools.rb
27
+ - bin/post
28
+ - bin/postdb
29
+ homepage: http://github.com/thomashc/Post
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.0.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Package manager in pure ruby.
52
+ test_files: []