bits-installer 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/ext/apt/extconf.rb CHANGED
@@ -4,8 +4,13 @@ require 'mkmf-rice'
4
4
  reqs = []
5
5
  reqs << have_library('apt-pkg')
6
6
 
7
- if not reqs.all? then
8
- File.open('Makefile', 'w').write "all:\n\t@echo \"Not building APT extension\""
7
+ unless reqs.all? then
8
+ File.open 'Makefile', 'w' do |f|
9
+ f.write "all:\n"
10
+ f.write "%:\n"
11
+ f.write "\t@echo \"$@: Not building APT extension\"\n"
12
+ end
13
+
9
14
  exit 0
10
15
  end
11
16
 
data/lib/bits/cache.rb CHANGED
@@ -56,7 +56,7 @@ module Bits::Cache
56
56
  return {} unless File.file? path
57
57
 
58
58
  File.open path do |f|
59
- return YAML.load_file f
59
+ return YAML.load f
60
60
  end
61
61
  end
62
62
  end
@@ -1,6 +1,7 @@
1
1
  require 'bits/command'
2
2
  require 'bits/logging'
3
3
  require 'bits/installer_mixin'
4
+ require 'bits/manifest'
4
5
  require 'yaml'
5
6
 
6
7
  module Bits
@@ -27,38 +28,30 @@ module Bits
27
28
 
28
29
  raise "No manifest in path: #{path}" unless File.file? path
29
30
 
30
- manifest = YAML.load File.new(path)
31
-
32
- unless manifest.kind_of? Hash
33
- raise "Manifest is not of type Hash: #{path}"
31
+ manifest = File.open(path) do |f|
32
+ Bits::Manifest.new YAML.load(f)
34
33
  end
35
34
 
36
- depends = manifest[:depends]
37
-
38
35
  criteria = {
39
36
  :compiled => ns[:compiled]
40
37
  }
41
38
 
42
39
  log.info "Running manifest: #{path}"
43
40
 
44
- unless depends.nil?
45
- begin
46
- packages = resolve_packages depends, criteria
47
- rescue Bits::MissingDependencies => e
48
- puts "Missing Dependencies:"
41
+ begin
42
+ packages = resolve_dependencies manifest, criteria
43
+ rescue Bits::MissingDependencies => e
44
+ puts "Missing Dependencies:"
49
45
 
50
- e.missing.each do |m|
51
- puts " - #{m}"
52
- end
53
-
54
- return 1
46
+ e.missing.each do |dep|
47
+ puts " - #{dep.atom}"
55
48
  end
56
49
 
57
- packages.each do |package|
58
- install_package package, force=ns[:force]
59
- end
60
- else
61
- log.info "No dependencies specified"
50
+ return 1
51
+ end
52
+
53
+ packages.each do |package|
54
+ install_package package, force=ns[:force]
62
55
  end
63
56
 
64
57
  return 0
@@ -25,9 +25,16 @@ module Bits
25
25
 
26
26
  clone repo_dir unless File.directory? repo_dir
27
27
 
28
+ log.info "Syncing bits"
29
+
28
30
  Dir.chdir(repo_dir) do
29
31
  Bits.spawn [GIT, 'pull', 'origin', 'master']
30
32
  end
33
+
34
+ providers.each do |provider|
35
+ log.info "Syncing provider: #{provider.to_s}"
36
+ provider.sync
37
+ end
31
38
  end
32
39
 
33
40
  def clone(repo_dir)
@@ -30,7 +30,7 @@ module Bits::InstallerMixin
30
30
 
31
31
  # Resolve a hash of dependencies with a criteria to packages.
32
32
  # Returns [<packages>, error]
33
- def resolve_packages(depends, criteria)
33
+ def resolve_dependencies(manifest, criteria)
34
34
  repository = ns[:repository]
35
35
 
36
36
  raise "No repository in namespace" if repository.nil?
@@ -38,29 +38,16 @@ module Bits::InstallerMixin
38
38
  packages = Array.new
39
39
  missing = Array.new
40
40
 
41
- unless depends.kind_of? Array
42
- raise ":depends should be a List"
43
- end
44
-
45
- depends.each do |spec|
46
- unless spec.kind_of? Hash
47
- raise "dependency should be of type Hash"
48
- end
49
-
50
- atom = spec[:atom]
51
-
52
- if atom.nil?
53
- raise "dependency must specify :atom"
54
- end
55
-
41
+ manifest.depends.each do |dep|
56
42
  crit = Hash.new
57
- crit = criteria[:compiled] unless criteria[:compiled].nil?
58
- crit = spec[:compiled] unless spec[:compiled].nil?
43
+
44
+ crit.update criteria
45
+ crit.update dep.parameters
59
46
 
60
47
  begin
61
- packages << repository.find_package(atom, crit)
48
+ packages << repository.find_package(dep.atom, crit)
62
49
  rescue Bits::MissingBit
63
- missing << atom
50
+ missing << dep
64
51
  end
65
52
  end
66
53
 
@@ -0,0 +1,51 @@
1
+ module Bits
2
+ class Manifest
3
+ class Dependency
4
+ attr_reader :atom, :parameters
5
+
6
+ def initialize(atom, parameters)
7
+ @atom = atom
8
+ @parameters = parameters
9
+ end
10
+ end
11
+
12
+ attr_reader :depends
13
+
14
+ def initialize(root)
15
+ unless root.kind_of? Hash
16
+ raise "Manifest is not of type Hash: #{path}"
17
+ end
18
+
19
+ @depends = read_depends root
20
+ end
21
+
22
+ private
23
+
24
+ def read_depends(root)
25
+ depends = root[:depends]
26
+ return [] if depends.nil?
27
+
28
+ unless depends.kind_of? Array
29
+ raise "Expected Array for :depends but got #{depends.inspect}"
30
+ end
31
+
32
+ list = Array.new
33
+
34
+ depends.each do |spec|
35
+ unless spec.kind_of? Hash
36
+ raise "Expected Hash for dependency spec but got #{spec.inspect}"
37
+ end
38
+
39
+ atom = spec[:atom]
40
+
41
+ if atom.nil?
42
+ raise "Expected :atom key for dependency"
43
+ end
44
+
45
+ list << Bits::Manifest::Dependency.new(atom, spec)
46
+ end
47
+
48
+ list
49
+ end
50
+ end
51
+ end
@@ -29,7 +29,7 @@ module Bits
29
29
  end
30
30
 
31
31
  def sync
32
- log.info "Does not know how to sync homebrew yet"
32
+ log.warn "Does not know how to sync homebrew yet"
33
33
  end
34
34
 
35
35
  def query(atom)
@@ -47,9 +47,16 @@ module Bits
47
47
  end
48
48
 
49
49
  def sync
50
+ # TODO: currently fetching the candidate version is a very slow operation
51
+ # sinc the initial list of packages does not include it. This needs to
52
+ # be mitigated somehow.
53
+
54
+ log.warn "Syncing without candidate version information"
55
+
50
56
  t = Time.new
51
57
 
52
58
  sync_file = File.join ns[:bits_dir], "#{provider_id}.sync"
59
+
53
60
  last_sync = get_last_sync sync_file
54
61
 
55
62
  if last_sync.nil?
@@ -67,10 +74,19 @@ module Bits
67
74
  end
68
75
 
69
76
  def query(package_atom)
70
- candidate = get_candidate_version package_atom
71
- raise MissingPackage.new package_atom if candidate.nil?
77
+ candidate = @cache[package_atom]
78
+
79
+ candidate_version = if candidate.nil?
80
+ get_candidate_version package_atom
81
+ else
82
+ candidate['version']
83
+ end
84
+
85
+ raise MissingPackage.new package_atom if candidate_version.nil?
86
+
72
87
  current = get_installed_version package_atom
73
- Bits::Package.new package_atom, current, candidate
88
+
89
+ Bits::Package.new package_atom, current, candidate_version
74
90
  end
75
91
 
76
92
  def install(package)
@@ -121,36 +137,41 @@ module Bits
121
137
  def read_partial(last_sync)
122
138
  result = @client.call :changelog, last_sync
123
139
 
140
+ log.info "PARTIAL: Syncing #{result.size} python packages"
141
+
124
142
  releases = Hash.new
125
143
 
126
144
  result.each do |name, version, timestamp, purpose|
127
145
  next if purpose != 'new release'
128
146
 
129
147
  releases[name] = {
130
- :atom => name,
131
- :candidate => version,
148
+ 'atom' => name,
149
+ 'version' => version,
132
150
  }
133
151
  end
134
152
 
135
153
  releases
136
154
  end
137
155
 
138
- # TODO: works really slowly right now, fix it
139
156
  def read_full
140
157
  remote_packages = @client.call :list_packages
141
158
 
142
- puts remote_packages.size
159
+ log.info "FULL: Syncing #{remote_packages.size} python packages"
143
160
 
144
161
  packages = Hash.new
145
162
 
146
163
  remote_packages.each do |name|
147
- candidate = get_candidate_version name
164
+ # TODO: currently syncing candidate version is very slow. This needs
165
+ # to be mitigated.
166
+
167
+ #candidate = get_candidate_version name
168
+ candidate = "0.0.0"
148
169
 
149
170
  next if candidate.nil?
150
171
 
151
172
  packages[name] = {
152
- :atom => name,
153
- :candidate => candidate,
173
+ 'atom' => name,
174
+ 'version' => candidate,
154
175
  }
155
176
  end
156
177
 
@@ -40,7 +40,7 @@ module Bits
40
40
 
41
41
  candidates = response['candidates']
42
42
 
43
- log.info "Synced #{candidates.size} gems"
43
+ log.info "Syncing #{candidates.size} gems"
44
44
 
45
45
  cache = candidates.inject({}){|h, i| h[i['atom']] = i; h}
46
46
 
data/lib/bits/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bits
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bits-installer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -113,6 +113,7 @@ files:
113
113
  - lib/bits/commands/manifest.rb
114
114
  - lib/bits/commands/show.rb
115
115
  - lib/bits/commands/setup.rb
116
+ - lib/bits/manifest.rb
116
117
  - lib/bits/package.rb
117
118
  - lib/bits/cache.rb
118
119
  - lib/bits/user.rb