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,171 @@
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 'dm-core'
21
+ require 'dm-constraints'
22
+ require 'dm-migrations'
23
+ require 'dm-types'
24
+ require 'dm-transactions'
25
+
26
+ require 'versionomy'
27
+
28
+ require 'packo'
29
+
30
+ module DataMapper
31
+
32
+ module Adapters
33
+ class DataObjectsAdapter < AbstractAdapter
34
+ private
35
+ def operation_statement(operation, qualify)
36
+ statements = []
37
+ bind_values = []
38
+
39
+ operation.each do |operand|
40
+ statement, values = conditions_statement(operand, qualify)
41
+ next unless statement
42
+ statements << statement
43
+ bind_values.concat(values) if values
44
+ end
45
+
46
+ statement = statements.join(" #{operation.slug.to_s.upcase} ")
47
+
48
+ if statements.size > 1
49
+ statement = "(#{statement})"
50
+ end
51
+
52
+ return (statement.empty? ? nil : statement), bind_values
53
+ end
54
+ end
55
+ end
56
+
57
+ if Packo::System.env[:DEBUG].to_i > 2
58
+ Logger.new($stdout, :debug)
59
+ end
60
+
61
+ Model.raise_on_save_failure = true
62
+
63
+ class Property
64
+ class Version < String
65
+ # Hopefully the max length of a version won't go over 255 chars
66
+ length 255
67
+
68
+ def custom?
69
+ true
70
+ end
71
+
72
+ def primitive? (value)
73
+ value.is_a?(Versionomy::Value)
74
+ end
75
+
76
+ def valid? (value, negated = false)
77
+ super || primitive?(value) || value.is_a?(::String)
78
+ end
79
+
80
+ def load (value)
81
+ Versionomy.parse(value.to_s) unless value.to_s.empty?
82
+ end
83
+
84
+ def dump (value)
85
+ value.to_s unless value.nil?
86
+ end
87
+
88
+ def typecast_to_primitive (value)
89
+ load(value)
90
+ end
91
+ end
92
+ end
93
+
94
+ begin
95
+ setup :default, Packo::System.env[:DATABASE]
96
+ rescue Exception => e
97
+ Packo::CLI.warn "Could not setup a connection with #{Packo::System.env[:DATABASE]}: #{e.message}"
98
+ end
99
+
100
+ require 'packo/models/installed_package'
101
+ require 'packo/models/repository'
102
+ require 'packo/models/selector'
103
+
104
+ finalize
105
+
106
+ begin
107
+ auto_upgrade!
108
+ rescue Exception => e
109
+ Packo::CLI.warn "Could not migrate the database: #{e.message}"
110
+ end
111
+
112
+ end
113
+
114
+ module Packo
115
+
116
+ module Models
117
+ def self.transactions
118
+ @@transactions ||= []
119
+ end
120
+
121
+ def self.transaction (&block)
122
+ transaction = DataMapper::Transaction.new(DataMapper.repository)
123
+ transaction.begin
124
+
125
+ Models.transactions << transaction
126
+
127
+ begin
128
+ transaction.within &block
129
+ rescue Exception => e
130
+ transaction.rollback unless transaction.rollback?
131
+
132
+ raise e
133
+ end
134
+
135
+ transaction.commit
136
+ end
137
+
138
+ def self.search_installed (expression, name=nil, type=nil)
139
+ Models::InstalledPackage.search(expression, true, type && name ? "#{type}/#{name}" : nil).map {|pkg|
140
+ Package.wrap(pkg)
141
+ }
142
+ end
143
+
144
+ def self.search (expression, name=nil, type=nil, exact=false)
145
+ packages = []
146
+
147
+ if name && !name.empty?
148
+ repository = Packo::Repository.parse(name)
149
+ repository.type = type if type && Packo::Repository::Types.member?(type.to_sym)
150
+ repository = Models::Repository.first(repository.to_hash)
151
+
152
+ if repository
153
+ packages << repository.search(expression, exact)
154
+ end
155
+ else
156
+ Packo::Repository::Types.each {|t|
157
+ if type.nil? || type == 'all' || type == t
158
+ Models::Repository.all(type: t).each {|repository|
159
+ packages << repository.search(expression, exact)
160
+ }
161
+ end
162
+ }
163
+ end
164
+
165
+ return packages.flatten.compact.map {|package|
166
+ Package.wrap(package)
167
+ }
168
+ end
169
+ end
170
+
171
+ end
@@ -0,0 +1,190 @@
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/installed_package/dependency'
22
+ require 'packo/models/installed_package/content'
23
+
24
+ module Packo; module Models
25
+
26
+ class InstalledPackage
27
+ include DataMapper::Resource
28
+
29
+ property :id, Serial
30
+
31
+ property :repo, String
32
+ has n, :tags, through: Resource, constraint: :destroy
33
+
34
+ property :tags_hashed, String, length: 40, required: true, unique_index: :a
35
+ property :name, String, length: 255, required: true, unique_index: :a
36
+ property :version, Version, required: true
37
+ property :slot, String, default: '', unique_index: :a
38
+ property :revision, Integer, default: 0
39
+
40
+ property :flavor, Text
41
+ property :features, Text
42
+
43
+ property :description, Text
44
+ property :homepage, Text
45
+ property :license, Text
46
+
47
+ property :maintainer, String
48
+
49
+ property :manual, Boolean, default: false
50
+ property :type, Enum[:both, :runtime, :build], default: :both
51
+
52
+ property :destination, Text
53
+
54
+ property :created_at, DateTime
55
+
56
+ has n, :dependencies, constraint: :destroy
57
+ has n, :contents, constraint: :destroy
58
+
59
+ def self.search (expression, exact=false, repository=nil)
60
+ if expression.start_with?('[') && expression.end_with?(']')
61
+ expression = expression[1, expression.length - 2]
62
+
63
+ if DataMapper.repository.adapter.respond_to? :select
64
+ result = self._find_by_expression(expression).map {|id|
65
+ InstalledPackage.get(id)
66
+ }
67
+ else
68
+ expression = Packo::Package::Tags::Expression.parse(expression)
69
+
70
+ result = packages.all.select {|pkg|
71
+ expression.evaluate(Packo::Package.wrap(pkg))
72
+ }
73
+ end
74
+ else
75
+ if matches = expression.match(/^([<>]?=?)/)
76
+ validity = ((matches[1] && !matches[1].empty?) ? matches[1] : nil)
77
+ expression = expression.sub(/^([<>]?=?)/, '')
78
+
79
+ validity = nil if validity == '='
80
+ else
81
+ validity = nil
82
+ end
83
+
84
+ package = Packo::Package.parse(expression)
85
+
86
+ conditions = { order: [:name.asc] }
87
+
88
+ if exact
89
+ conditions[:name] = package.name if package.name
90
+ conditions[:version] = package.version if package.version
91
+ conditions[:slot] = package.slot if package.slot
92
+ else
93
+ conditions[:name.like] = "%#{package.name}%" if package.name
94
+ conditions[:version.like] = package.version if package.version
95
+ conditions[:slot.like] = "%#{package.slot}%" if package.slot
96
+ end
97
+
98
+ result = InstalledPackage.all(conditions)
99
+
100
+ if !package.tags.empty?
101
+ result = result.to_a.select {|pkg|
102
+ Packo::Package.wrap(pkg).tags == package.tags
103
+ }
104
+ end
105
+
106
+ if validity
107
+ result = result.select {|pkg|
108
+ case validity
109
+ when '>'; pkg.version > package.version
110
+ when '>='; pkg.version >= package.version
111
+ when '<'; pkg.version < package.version
112
+ when '<='; pkg.version <= package.version
113
+ end
114
+ }
115
+ end
116
+ end
117
+
118
+ if repository
119
+ result.delete_if {|pkg|
120
+ pkg.repo != repository
121
+ }
122
+ end
123
+
124
+ return result
125
+ end
126
+
127
+ private
128
+
129
+ def self._expression_to_sql (value)
130
+ value.downcase!
131
+ value.gsub!(/(\s+and\s+|\s*&&\s*)/i, ' && ')
132
+ value.gsub!(/(\s+or\s+|\s*\|\|\s*)/i, ' || ')
133
+ value.gsub!(/(\s+not\s+|\s*!\s*)/i, ' !')
134
+ value.gsub!(/\(\s*!/, '(!')
135
+
136
+ joins = String.new
137
+ names = []
138
+ expression = value.clone
139
+
140
+ expression.scan(/(("(([^\\"]|\\.)*)")|([^\s&!|()]+))/) {|match|
141
+ names.push((match[2] || match[4]).downcase)
142
+ }
143
+
144
+ names.compact!
145
+ names.uniq!
146
+
147
+ names.each_index {|index|
148
+ joins << %{
149
+ LEFT JOIN (
150
+ SELECT _used_tag_#{index}.package_id
151
+
152
+ FROM packo_models_installed_package_tags AS _used_tag_#{index}
153
+
154
+ INNER JOIN packo_models_tags AS _tag_#{index}
155
+ ON _used_tag_#{index}.tag_id = _tag_#{index}.id AND _tag_#{index}.name = ?
156
+ ) AS _tag_check_#{index}
157
+ ON packo_models_installed_packages.id = _tag_check_#{index}.package_id
158
+ }
159
+
160
+ if (replace = names[index]).match(/[\s&!|]/)
161
+ replace = %{"#{replace}"}
162
+ end
163
+
164
+ expression.gsub!(/([\s()]|\G)!\s*#{Regexp.escape(replace)}([\s()]|$)/, "\\1 (_tag_check_#{index}.package_id IS NULL) \\2")
165
+ expression.gsub!(/([\s()]|\G)#{Regexp.escape(replace)}([\s()]|$)/, "\\1 (_tag_check_#{index}.package_id IS NOT NULL) \\2")
166
+ }
167
+
168
+ expression.gsub!(/([\G\s()])&&([\s()\A])/, '\1 AND \2')
169
+ expression.gsub!(/([\G\s()])\|\|([\s()\A])/, '\1 OR \2')
170
+ expression.gsub!(/([\G\s()])!([\s()\A])/, '\1 NOT \2')
171
+
172
+ return joins, names, expression
173
+ end
174
+
175
+ def self._find_by_expression (expression)
176
+ joins, names, expression = self._expression_to_sql(expression)
177
+
178
+ repository.adapter.select(%{
179
+ SELECT DISTINCT packo_models_installed_packages.id
180
+
181
+ FROM packo_models_installed_packages
182
+
183
+ #{joins}
184
+
185
+ WHERE #{expression}
186
+ }, *names) rescue []
187
+ end
188
+ end
189
+
190
+ end; end
@@ -0,0 +1,50 @@
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 InstalledPackage
21
+
22
+ class Content
23
+ include DataMapper::Resource
24
+
25
+ belongs_to :installed_package
26
+
27
+ property :id, Serial
28
+
29
+ property :type, Enum[:dir, :obj, :sym]
30
+
31
+ property :path, Text
32
+
33
+ property :meta, Object, required: false
34
+
35
+ def check!
36
+ return if self.type
37
+
38
+ if File.directory?(self.path)
39
+ self.type = :dir
40
+ elsif File.symlink?(self.path)
41
+ self.type = :sym
42
+ elsif File.file?(self.path)
43
+ self.type = :obj
44
+ end
45
+
46
+ self.save
47
+ end
48
+ end
49
+
50
+ end; end; end
@@ -0,0 +1,39 @@
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 InstalledPackage
21
+
22
+ class Dependency
23
+ include DataMapper::Resource
24
+
25
+ belongs_to :installed_package
26
+
27
+ property :id, Serial
28
+
29
+ property :tags, Text, unique_index: :a
30
+ property :name, String, unique_index: :a
31
+ property :version, String, unique_index: :a
32
+ property :slot, String, default: ''
33
+ property :revision, Integer, default: 0
34
+
35
+ property :flavor, Text, default: ''
36
+ property :features, Text, default: ''
37
+ end
38
+
39
+ end; end; end