packo 0.0.1.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/bin/packo +78 -0
  2. data/bin/packo-base +24 -0
  3. data/bin/packo-build +24 -0
  4. data/bin/packo-db +24 -0
  5. data/bin/packo-env +24 -0
  6. data/bin/packo-files +24 -0
  7. data/bin/packo-profile +24 -0
  8. data/bin/packo-repository +24 -0
  9. data/bin/packo-select +24 -0
  10. data/lib/packo.rb +186 -0
  11. data/lib/packo/cli.rb +79 -0
  12. data/lib/packo/cli/base.rb +554 -0
  13. data/lib/packo/cli/build.rb +488 -0
  14. data/lib/packo/cli/database.rb +55 -0
  15. data/lib/packo/cli/database/definition.rb +65 -0
  16. data/lib/packo/cli/database/helpers.rb +20 -0
  17. data/lib/packo/cli/environment.rb +45 -0
  18. data/lib/packo/cli/files.rb +153 -0
  19. data/lib/packo/cli/profile.rb +31 -0
  20. data/lib/packo/cli/repository.rb +561 -0
  21. data/lib/packo/cli/repository/binary.rb +74 -0
  22. data/lib/packo/cli/repository/helpers.rb +20 -0
  23. data/lib/packo/cli/repository/repository.rb +48 -0
  24. data/lib/packo/cli/repository/source.rb +91 -0
  25. data/lib/packo/cli/repository/virtual.rb +53 -0
  26. data/lib/packo/cli/select.rb +61 -0
  27. data/lib/packo/do.rb +249 -0
  28. data/lib/packo/environment.rb +269 -0
  29. data/lib/packo/extensions.rb +70 -0
  30. data/lib/packo/flags.rb +64 -0
  31. data/lib/packo/host.rb +121 -0
  32. data/lib/packo/models.rb +171 -0
  33. data/lib/packo/models/installed_package.rb +190 -0
  34. data/lib/packo/models/installed_package/content.rb +50 -0
  35. data/lib/packo/models/installed_package/dependency.rb +39 -0
  36. data/lib/packo/models/repository.rb +209 -0
  37. data/lib/packo/models/repository/binary.rb +32 -0
  38. data/lib/packo/models/repository/binary/mirror.rb +35 -0
  39. data/lib/packo/models/repository/package.rb +73 -0
  40. data/lib/packo/models/repository/package/binary.rb +34 -0
  41. data/lib/packo/models/repository/package/binary/build.rb +36 -0
  42. data/lib/packo/models/repository/package/source.rb +36 -0
  43. data/lib/packo/models/repository/package/source/feature.rb +36 -0
  44. data/lib/packo/models/repository/package/source/flavor.rb +36 -0
  45. data/lib/packo/models/repository/package/virtual.rb +32 -0
  46. data/lib/packo/models/repository/source.rb +30 -0
  47. data/lib/packo/models/repository/virtual.rb +30 -0
  48. data/lib/packo/models/selector.rb +34 -0
  49. data/lib/packo/models/tag.rb +30 -0
  50. data/lib/packo/package.rb +239 -0
  51. data/lib/packo/package/blocker.rb +100 -0
  52. data/lib/packo/package/blockers.rb +40 -0
  53. data/lib/packo/package/dependencies.rb +40 -0
  54. data/lib/packo/package/dependency.rb +100 -0
  55. data/lib/packo/package/feature.rb +55 -0
  56. data/lib/packo/package/features.rb +105 -0
  57. data/lib/packo/package/flavor.rb +101 -0
  58. data/lib/packo/package/tags.rb +60 -0
  59. data/lib/packo/package/tags/expression.rb +130 -0
  60. data/lib/packo/package/tags/expression/group.rb +28 -0
  61. data/lib/packo/package/tags/expression/logic.rb +48 -0
  62. data/lib/packo/package/tags/expression/name.rb +28 -0
  63. data/lib/packo/profile.rb +174 -0
  64. data/lib/packo/rbuild.rb +22 -0
  65. data/lib/packo/rbuild/behaviors.rb +20 -0
  66. data/lib/packo/rbuild/behaviors/default.rb +27 -0
  67. data/lib/packo/rbuild/feature.rb +64 -0
  68. data/lib/packo/rbuild/features.rb +65 -0
  69. data/lib/packo/rbuild/flavor.rb +67 -0
  70. data/lib/packo/rbuild/module.rb +40 -0
  71. data/lib/packo/rbuild/modules.rb +27 -0
  72. data/lib/packo/rbuild/modules/building.rb +24 -0
  73. data/lib/packo/rbuild/modules/building/autotools.rb +315 -0
  74. data/lib/packo/rbuild/modules/building/cmake.rb +38 -0
  75. data/lib/packo/rbuild/modules/building/patch.rb +84 -0
  76. data/lib/packo/rbuild/modules/building/rake.rb +74 -0
  77. data/lib/packo/rbuild/modules/building/strip.rb +41 -0
  78. data/lib/packo/rbuild/modules/misc.rb +26 -0
  79. data/lib/packo/rbuild/modules/misc/fetcher.rb +177 -0
  80. data/lib/packo/rbuild/modules/misc/fetching.rb +22 -0
  81. data/lib/packo/rbuild/modules/misc/fetching/git.rb +57 -0
  82. data/lib/packo/rbuild/modules/misc/fetching/github.rb +31 -0
  83. data/lib/packo/rbuild/modules/misc/fetching/gnu.rb +59 -0
  84. data/lib/packo/rbuild/modules/misc/fetching/mercurial.rb +51 -0
  85. data/lib/packo/rbuild/modules/misc/fetching/sourceforge.rb +47 -0
  86. data/lib/packo/rbuild/modules/misc/fetching/subversion.rb +51 -0
  87. data/lib/packo/rbuild/modules/misc/fetching/wget.rb +57 -0
  88. data/lib/packo/rbuild/modules/misc/unpacker.rb +70 -0
  89. data/lib/packo/rbuild/modules/misc/unpacking.rb +23 -0
  90. data/lib/packo/rbuild/modules/misc/unpacking/lzma.rb +34 -0
  91. data/lib/packo/rbuild/modules/misc/unpacking/tar.rb +35 -0
  92. data/lib/packo/rbuild/modules/misc/unpacking/xz.rb +34 -0
  93. data/lib/packo/rbuild/modules/misc/unpacking/zip.rb +26 -0
  94. data/lib/packo/rbuild/modules/packaging.rb +20 -0
  95. data/lib/packo/rbuild/modules/packaging/pko.rb +78 -0
  96. data/lib/packo/rbuild/package.rb +281 -0
  97. data/lib/packo/rbuild/package/manifest.rb +169 -0
  98. data/lib/packo/rbuild/stages.rb +171 -0
  99. data/lib/packo/rbuild/stages/callbacks.rb +96 -0
  100. data/lib/packo/rbuild/stages/stage.rb +50 -0
  101. data/lib/packo/repository.rb +95 -0
  102. data/lib/packo/repository/binary.rb +116 -0
  103. data/lib/packo/repository/source.rb +77 -0
  104. data/lib/packo/repository/virtual.rb +66 -0
  105. data/lib/packo/system.rb +53 -0
  106. data/lib/packo/version.rb +26 -0
  107. metadata +276 -0
@@ -0,0 +1,209 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'packo/repository'
21
+
22
+ require 'packo/models/repository/package'
23
+
24
+ require 'packo/models/repository/binary'
25
+ require 'packo/models/repository/source'
26
+ require 'packo/models/repository/virtual'
27
+
28
+ module Packo; module Models
29
+
30
+ class Repository
31
+ include DataMapper::Resource
32
+
33
+ property :id, Serial
34
+
35
+ property :type, Enum[:binary, :source, :virtual], required: true
36
+ property :name, String, required: true
37
+
38
+ property :uri, URI, required: true
39
+ property :path, Text, required: true
40
+
41
+ has n, :packages, constraint: :destroy
42
+
43
+ after :create do |repo|
44
+ case repo.type
45
+ when :binary; Binary.create(repo: repo)
46
+ when :source; Source.create(repo: repo)
47
+ when :virtual; Virtual.create(repo: repo)
48
+ end
49
+ end
50
+
51
+ after :save do |repo|
52
+ repo.data.save if repo.data
53
+ end
54
+
55
+ after :destroy do |repo|
56
+ repo.data.destroy! if repo.data
57
+ end
58
+
59
+ def data
60
+ case type
61
+ when :binary; Binary.first_or_create(repo: self)
62
+ when :source; Source.first_or_create(repo: self)
63
+ when :virtual; Virtual.first_or_create(repo: self)
64
+ end
65
+ end
66
+
67
+ def to_hash
68
+ Hash[
69
+ type: self.type,
70
+ name: self.name,
71
+ uri: self.uri,
72
+ path: self.path
73
+ ]
74
+ end
75
+
76
+ def URI
77
+ case type
78
+ when :binary; data.mirrors.to_a.map {|m| m.uri}.join("\n")
79
+ when :source; data.address
80
+ when :virtual; data.address
81
+ end
82
+ end
83
+
84
+ def search (expression, exact=false)
85
+ if expression.start_with?('[') && expression.end_with?(']')
86
+ expression = expression[1, expression.length - 2]
87
+
88
+ if DataMapper.repository.adapter.respond_to? :select
89
+ result = _find_by_expression(expression).map {|id|
90
+ Package.get(id)
91
+ }
92
+ else
93
+ expression = Packo::Package::Tags::Expression.parse(expression)
94
+
95
+ result = packages.all.select {|pkg|
96
+ expression.evaluate(Packo::Package.wrap(pkg))
97
+ }
98
+ end
99
+ else
100
+ if matches = expression.match(/^([<>]?=?)/)
101
+ validity = ((matches[1] && !matches[1].empty?) ? matches[1] : nil)
102
+ expression = expression.sub(/^([<>]?=?)/, '')
103
+
104
+ validity = nil if validity == '='
105
+ else
106
+ validity = nil
107
+ end
108
+
109
+ package = Packo::Package.parse(expression)
110
+
111
+ conditions = { order: [:name.asc] }
112
+
113
+ if exact
114
+ conditions[:name] = package.name if package.name
115
+ conditions[:version] = package.version if package.version
116
+ conditions[:slot] = package.slot if package.slot
117
+ else
118
+ conditions[:name.like] = "%#{package.name}%" if package.name
119
+ conditions[:version.like] = package.version if package.version
120
+ conditions[:slot.like] = "%#{package.slot}%" if package.slot
121
+ end
122
+
123
+ result = packages.all(conditions)
124
+
125
+ if !package.tags.empty?
126
+ result = result.to_a.select {|pkg|
127
+ Packo::Package.wrap(pkg).tags == package.tags
128
+ }
129
+ end
130
+
131
+ if validity
132
+ result = result.select {|pkg|
133
+ case validity
134
+ when '>'; pkg.version > package.version
135
+ when '>='; pkg.version >= package.version
136
+ when '<'; pkg.version < package.version
137
+ when '<='; pkg.version <= package.version
138
+ end
139
+ }
140
+ end
141
+ end
142
+
143
+ return result
144
+ end
145
+
146
+ private
147
+
148
+ def _expression_to_sql (value)
149
+ value.downcase!
150
+ value.gsub!(/(\s+and\s+|\s*&&\s*)/i, ' && ')
151
+ value.gsub!(/(\s+or\s+|\s*\|\|\s*)/i, ' || ')
152
+ value.gsub!(/(\s+not\s+|\s*!\s*)/i, ' !')
153
+ value.gsub!(/\(\s*!/, '(!')
154
+
155
+ joins = String.new
156
+ names = []
157
+ expression = value.clone
158
+
159
+ expression.scan(/(("(([^\\"]|\\.)*)")|([^\s&!|()]+))/) {|match|
160
+ names.push((match[2] || match[4]).downcase)
161
+ }
162
+
163
+ names.compact!
164
+ names.uniq!
165
+
166
+ names.each_index {|index|
167
+ joins << %{
168
+ LEFT JOIN (
169
+ SELECT _used_tag_#{index}.package_id
170
+
171
+ FROM packo_models_package_tags AS _used_tag_#{index}
172
+
173
+ INNER JOIN packo_models_tags AS _tag_#{index}
174
+ ON _used_tag_#{index}.tag_id = _tag_#{index}.id AND _tag_#{index}.name = ?
175
+ ) AS _tag_check_#{index}
176
+ ON packo_models_repository_packages.id = _tag_check_#{index}.package_id
177
+ }
178
+
179
+ if (replace = names[index]).match(/[\s&!|]/)
180
+ replace = %{"#{replace}"}
181
+ end
182
+
183
+ expression.gsub!(/([\s()]|\G)!\s*#{Regexp.escape(replace)}([\s()]|$)/, "\\1 (_tag_check_#{index}.package_id IS NULL) \\2")
184
+ expression.gsub!(/([\s()]|\G)#{Regexp.escape(replace)}([\s()]|$)/, "\\1 (_tag_check_#{index}.package_id IS NOT NULL) \\2")
185
+ }
186
+
187
+ expression.gsub!(/([\G\s()])&&([\s()\A])/, '\1 AND \2')
188
+ expression.gsub!(/([\G\s()])\|\|([\s()\A])/, '\1 OR \2')
189
+ expression.gsub!(/([\G\s()])!([\s()\A])/, '\1 NOT \2')
190
+
191
+ return joins, names, expression
192
+ end
193
+
194
+ def _find_by_expression (expression)
195
+ joins, names, expression = _expression_to_sql(expression)
196
+
197
+ repository.adapter.select(%{
198
+ SELECT DISTINCT packo_models_repository_packages.id
199
+
200
+ FROM packo_models_repository_packages
201
+
202
+ #{joins}
203
+
204
+ WHERE packo_models_repository_packages.repo_id = ? #{"AND (#{expression})" if !expression.empty?}
205
+ }, *(names + [id])) rescue []
206
+ end
207
+ end
208
+
209
+ end; end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'packo/models/repository/binary/mirror'
21
+
22
+ module Packo; module Models; class Repository
23
+
24
+ class Binary
25
+ include DataMapper::Resource
26
+
27
+ belongs_to :repo, 'Repository', key: true
28
+
29
+ has n, :mirrors, constraint: :destroy
30
+ end
31
+
32
+ end; end; end
@@ -0,0 +1,35 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module Packo; module Models; class Repository; class Binary
21
+
22
+ class Mirror
23
+ include DataMapper::Resource
24
+
25
+ property :id, Serial
26
+
27
+ belongs_to :binary
28
+
29
+ property :id, Serial
30
+
31
+ property :binary_id, Integer, unique_index: :a
32
+ property :uri, URI, unique_index: :a
33
+ end
34
+
35
+ end; end; end; end
@@ -0,0 +1,73 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'packo/models/tag'
21
+ require 'packo/models/repository/package/binary'
22
+ require 'packo/models/repository/package/source'
23
+ require 'packo/models/repository/package/virtual'
24
+
25
+ module Packo; module Models; class Repository
26
+
27
+ class Package
28
+ include DataMapper::Resource
29
+
30
+ property :id, Serial
31
+
32
+ belongs_to :repo, 'Repository'
33
+ has n, :tags, through: Resource, constraint: :destroy
34
+
35
+ property :repository_id, Integer, unique_index: :a
36
+ property :tags_hashed, String, length: 40, required: true, unique_index: :a
37
+ property :name, String, length: 255, required: true, unique_index: :a
38
+ property :version, Version, required: true, unique_index: :a
39
+ property :slot, String, default: '', unique_index: :a
40
+ property :revision, Integer, default: 0
41
+
42
+ property :description, Text
43
+ property :homepage, Text
44
+ property :license, Text
45
+
46
+ property :maintainer, String
47
+
48
+ after :create do |package|
49
+ case package.repo.type
50
+ when :binary; Binary.create(package: package)
51
+ when :source; Source.create(package: package)
52
+ when :virtual; Virtual.create(package: package)
53
+ end
54
+ end
55
+
56
+ after :save do |package|
57
+ package.data.save if package.data
58
+ end
59
+
60
+ after :destroy do |package|
61
+ package.data.destroy! if package.data
62
+ end
63
+
64
+ def data
65
+ case repo.type
66
+ when :binary; Binary.first_or_create(package: self)
67
+ when :source; Source.first_or_create(package: self)
68
+ when :virtual; Virtual.first_or_create(package: self)
69
+ end
70
+ end
71
+ end
72
+
73
+ end; end; end
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'packo/models/repository/package/binary/build'
21
+
22
+ module Packo; module Models; class Repository; class Package
23
+
24
+ class Binary
25
+ include DataMapper::Resource
26
+
27
+ belongs_to :package, key: true
28
+
29
+ property :features, Text, default: ''
30
+
31
+ has n, :builds, constraint: :destroy
32
+ end
33
+
34
+ end; end; end; end
@@ -0,0 +1,36 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module Packo; module Models; class Repository; class Package; class Binary
21
+
22
+ class Build
23
+ include DataMapper::Resource
24
+
25
+ belongs_to :binary
26
+
27
+ property :id, Serial
28
+
29
+ property :binary_package_id, Integer, unique_index: :a
30
+ property :flavor, Text, default: '', unique_index: :a
31
+ property :features, Text, default: '', unique_index: :a
32
+
33
+ property :digest, Text, default: ''
34
+ end
35
+
36
+ end; end; end; end; end
@@ -0,0 +1,36 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of packo.
5
+ #
6
+ # packo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # packo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with packo. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'packo/models/repository/package/source/feature'
21
+ require 'packo/models/repository/package/source/flavor'
22
+
23
+ module Packo; module Models; class Repository; class Package
24
+
25
+ class Source
26
+ include DataMapper::Resource
27
+
28
+ belongs_to :package, key: true
29
+
30
+ property :path, Text, default: ''
31
+
32
+ has n, :features, constraint: :destroy
33
+ has n, :flavor, constraint: :destroy
34
+ end
35
+
36
+ end; end; end; end