gemirro 0.13.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gemirro might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 777922859275d6f968d483067b6c468d6796436c
4
- data.tar.gz: c28f06747d86a8040b0003a0a92693fe3b37cd08
3
+ metadata.gz: 82b43d4fb674a2d477ca6e36892ce24cb75dc27e
4
+ data.tar.gz: 6722f23ee14197f2eed5fdb3089b0bfaddb3321b
5
5
  SHA512:
6
- metadata.gz: 2282a5753a197ade52486dd5921e5983d603076c9e3f4cd27a88329f2f2f98e0032ad4a485833a1b7da16d4a1ceb1436094972e000e87b49c113642a8635c21e
7
- data.tar.gz: acd234a81d16c6aff952f253855e8217ff42c6d2b52dd4be5c529672e35434e9d58ec841c0e1164c2a826892770626e82a9fc27bf99d42695f34820fc4222536
6
+ metadata.gz: 72c637dddc14a1a6f6f9649df99fd6e04dbbcfce0926b99c44ef084a8bda8d148507616ac80497df4e7ed609c37b3a7112fa310d1d64319995699ea88c6df388
7
+ data.tar.gz: 0318c861a49c17318dec009db0284022459e839a6fdd2b74f26c5be1b4a784540b0d120ef09085bf95d932fe1e485f1434ad9734255e44194cc86c978894fbce
data/README.md CHANGED
@@ -57,6 +57,26 @@ $ gemirro server --stop
57
57
 
58
58
  If you want to use a custom configuration file not located in the current directory, use the `-c` or `--config` option.
59
59
 
60
+ ### Available commands
61
+
62
+ ```
63
+ Usage: gemirro [COMMAND] [OPTIONS]
64
+
65
+ Options:
66
+
67
+ -v, --version Shows the current version
68
+ -h, --help Display this help message.
69
+
70
+ Available commands:
71
+
72
+ index Retrieve specs list from source.
73
+ init Sets up a new mirror
74
+ list List available gems.
75
+ server Manage web server
76
+ update Updates the list of Gems
77
+
78
+ See `<command> --help` for more information on a specific command.
79
+ ```
60
80
 
61
81
  ## Apache configuration
62
82
 
@@ -5,11 +5,13 @@ Gemirro::CLI.options.command 'index' do
5
5
  separator "\nOptions:\n"
6
6
 
7
7
  on :c=, :config=, 'Path to the configuration file'
8
+ on :l=, :log_level=, 'Set logger level'
8
9
  on :u, :update, 'Update only'
9
10
 
10
11
  run do |opts, _args|
11
12
  Gemirro::CLI.load_configuration(opts[:c])
12
13
  config = Gemirro.configuration
14
+ config.logger_level = opts[:l] if opts[:l]
13
15
 
14
16
  unless File.directory?(config.destination)
15
17
  config.logger.error("The directory #{config.destination} does not exist")
@@ -3,6 +3,7 @@ Gemirro::CLI.options.command 'init' do
3
3
  banner 'Usage: gemirro init [DIRECTORY] [OPTIONS]'
4
4
  description 'Sets up a new mirror'
5
5
  separator "\nOptions:\n"
6
+
6
7
  on :force, 'Force overwrite'
7
8
 
8
9
  run do |opts, args|
@@ -5,10 +5,12 @@ Gemirro::CLI.options.command 'list' do
5
5
  separator "\nOptions:\n"
6
6
 
7
7
  on :c=, :config=, 'Path to the configuration file'
8
+ on :l=, :log_level=, 'Set logger level'
8
9
 
9
10
  run do |opts, _args|
10
11
  Gemirro::CLI.load_configuration(opts[:c])
11
12
  config = Gemirro.configuration
13
+ config.logger_level = opts[:l] if opts[:l]
12
14
 
13
15
  unless File.directory?(config.destination)
14
16
  config.logger.error("The directory #{config.destination} does not exist")
@@ -10,6 +10,8 @@ Gemirro::CLI.options.command 'server' do
10
10
  on :restart, 'Restart web server'
11
11
  on :status, 'Status of web server'
12
12
  on :c=, :config=, 'Path to the configuration file'
13
+ on :l=, :log_level=, 'Set logger level'
14
+
13
15
  @pid_file = nil
14
16
 
15
17
  run do |opts, _args|
@@ -23,6 +25,7 @@ Gemirro::CLI.options.command 'server' do
23
25
  def load_configuration(opts)
24
26
  Gemirro::CLI.load_configuration(opts[:c])
25
27
  config = Gemirro.configuration
28
+ config.logger_level = opts[:l] if opts[:l]
26
29
  unless File.directory?(config.destination)
27
30
  config.logger.error("The directory #{config.destination} does not exist")
28
31
  abort
@@ -5,9 +5,11 @@ Gemirro::CLI.options.command 'update' do
5
5
  separator "\nOptions:\n"
6
6
 
7
7
  on :c=, :config=, 'Path to the configuration file'
8
+ on :l=, :log_level=, 'Set logger level'
8
9
 
9
10
  run do |opts, _args|
10
11
  Gemirro::CLI.load_configuration(opts[:c])
12
+ config.logger_level = opts[:l] if opts[:l]
11
13
 
12
14
  source = Gemirro.configuration.source
13
15
  versions = Gemirro::VersionsFetcher.new(source).fetch
@@ -24,6 +24,15 @@ module Gemirro
24
24
  attr_reader :mirror_gems_directory, :mirror_gemspecs_directory
25
25
  attr_accessor :source, :ignored_gems, :logger
26
26
 
27
+ LOGGER_LEVEL = {
28
+ 'debug' => Logger::DEBUG,
29
+ 'warning' => Logger::WARN,
30
+ 'info' => Logger::INFO,
31
+ 'unknown' => Logger::UNKNOWN,
32
+ 'error' => Logger::ERROR,
33
+ 'fatal' => Logger::FATAL
34
+ }
35
+
27
36
  ##
28
37
  # Returns the logger
29
38
  #
@@ -33,6 +42,18 @@ module Gemirro
33
42
  @logger ||= Logger.new(STDOUT)
34
43
  end
35
44
 
45
+ ##
46
+ # Set log level
47
+ #
48
+ # @param [string]
49
+ #
50
+ # @return [Logger]
51
+ #
52
+ def logger_level=(level)
53
+ logger.level = LOGGER_LEVEL[level] if LOGGER_LEVEL.key?(level)
54
+ logger
55
+ end
56
+
36
57
  ##
37
58
  # Returns the template path to init directory
38
59
  #
@@ -203,8 +203,13 @@ module Gemirro
203
203
  next
204
204
  end
205
205
 
206
- abbreviate spec
207
- sanitize spec
206
+ if ::Gem::VERSION >= '2.5.0'
207
+ spec.abbreviate
208
+ spec.sanitize
209
+ else
210
+ abbreviate spec
211
+ sanitize spec
212
+ end
208
213
 
209
214
  spec
210
215
  rescue SignalException
@@ -6,45 +6,36 @@ module Gemirro
6
6
  ##
7
7
  # Launch Sinatra server to easily download gems.
8
8
  #
9
- # @!attribute [r] versions_fetcher
10
- # @return [VersionsFetcher]
11
- # @!attribute [r] gems_fetcher
12
- # @return [Gemirro::GemsFetcher]
13
- #
14
9
  class Server < Sinatra::Base
15
10
  # rubocop:disable Metrics/LineLength
16
11
  URI_REGEXP = /^(.*)-(\d+(?:\.\d+){1,4}.*?)(?:-x86-(?:(?:mswin|mingw)(?:32|64)).*?)?\.(gem(?:spec\.rz)?)$/
17
12
  GEMSPEC_TYPE = 'gemspec.rz'
18
13
  GEM_TYPE = 'gem'
19
- # rubocop:enable Metrics/LineLength
20
-
21
- attr_accessor :versions_fetcher, :gems_fetcher
22
- attr_reader(:stored_gems,
23
- :cache)
24
14
 
25
- # rubocop:disable Metrics/LineLength
26
- access_logger = Logger.new(Gemirro.configuration.server.access_log).tap do |logger|
15
+ access_logger = Logger.new(Utils.configuration.server.access_log).tap do |logger|
27
16
  ::Logger.class_eval { alias_method :write, :'<<' }
28
17
  logger.level = ::Logger::INFO
29
18
  end
30
19
  # rubocop:enable Metrics/LineLength
31
20
 
32
- error_logger = File.new(Gemirro.configuration.server.error_log, 'a+')
21
+ error_logger = File.new(Utils.configuration.server.error_log, 'a+')
33
22
  error_logger.sync = true
34
23
 
35
24
  before do
36
25
  env['rack.errors'] = error_logger
37
- Gemirro.configuration.logger = access_logger
26
+ Utils.configuration.logger = access_logger
38
27
  end
39
28
 
40
29
  ##
41
30
  # Configure server
42
31
  #
43
32
  configure do
44
- config = Gemirro.configuration
33
+ config = Utils.configuration
45
34
  config.server.host = 'localhost' if config.server.host.nil?
46
35
  config.server.port = '2000' if config.server.port.nil?
47
36
 
37
+ set :static, true
38
+
48
39
  set :views, Gemirro::Configuration.views_directory
49
40
  set :port, config.server.port
50
41
  set :bind, config.server.host
@@ -74,10 +65,10 @@ module Gemirro
74
65
  #
75
66
  get('/gem/:gemname') do
76
67
  gems = Utils.gems_collection
77
- @gem = gems.find_by_name(params[:gemname])
78
- return not_found if @gem.nil?
68
+ gem = gems.find_by_name(params[:gemname])
69
+ return not_found if gem.nil?
79
70
 
80
- erb(:gem)
71
+ erb(:gem, {}, gem: gem)
81
72
  end
82
73
 
83
74
  ##
@@ -87,8 +78,7 @@ module Gemirro
87
78
  # @return [nil]
88
79
  #
89
80
  get('/') do
90
- @gems = Utils.gems_collection
91
- erb(:index)
81
+ erb(:index, {}, gems: Utils.gems_collection)
92
82
  end
93
83
 
94
84
  ##
@@ -144,21 +134,21 @@ module Gemirro
144
134
  return unless gem_name && gem_version
145
135
 
146
136
  begin
147
- gem = stored_gem(gem_name, gem_version)
137
+ gem = Utils.stored_gem(gem_name, gem_version)
148
138
  gem.gemspec = true if gem_type == GEMSPEC_TYPE
149
139
 
150
140
  # rubocop:disable Metrics/LineLength
151
- return if gems_fetcher.gem_exists?(gem.filename(gem_version)) && gem_type == GEM_TYPE
152
- return if gems_fetcher.gemspec_exists?(gem.gemspec_filename(gem_version)) && gem_type == GEMSPEC_TYPE
141
+ return if Utils.gems_fetcher.gem_exists?(gem.filename(gem_version)) && gem_type == GEM_TYPE
142
+ return if Utils.gems_fetcher.gemspec_exists?(gem.gemspec_filename(gem_version)) && gem_type == GEMSPEC_TYPE
153
143
  # rubocop:enable Metrics/LineLength
154
144
 
155
145
  Utils.logger
156
146
  .info("Try to download #{gem_name} with version #{gem_version}")
157
- gems_fetcher.source.gems.clear
158
- gems_fetcher.source.gems.push(gem)
159
- gems_fetcher.fetch
147
+ Utils.gems_fetcher.source.gems.clear
148
+ Utils.gems_fetcher.source.gems.push(gem)
149
+ Utils.gems_fetcher.fetch
160
150
 
161
- update_indexes if configuration.update_on_fetch
151
+ update_indexes if Utils.configuration.update_on_fetch
162
152
  rescue StandardError => e
163
153
  Utils.logger.error(e)
164
154
  end
@@ -170,7 +160,7 @@ module Gemirro
170
160
  # @return [Indexer]
171
161
  #
172
162
  def update_indexes
173
- indexer = Gemirro::Indexer.new(configuration.destination)
163
+ indexer = Gemirro::Indexer.new(Utils.configuration.destination)
174
164
  indexer.only_origin = true
175
165
  indexer.ui = ::Gem::SilentUI.new
176
166
 
@@ -183,29 +173,6 @@ module Gemirro
183
173
  Utils.logger.info(e.message)
184
174
  end
185
175
 
186
- ##
187
- # @see Gemirro.configuration
188
- #
189
- def configuration
190
- Gemirro.configuration
191
- end
192
-
193
- ##
194
- # @see Gemirro::VersionsFetcher.fetch
195
- #
196
- def versions_fetcher
197
- @versions_fetcher ||= Gemirro::VersionsFetcher
198
- .new(configuration.source).fetch
199
- end
200
-
201
- ##
202
- # @return [Gemirro::GemsFetcher]
203
- #
204
- def gems_fetcher
205
- @gems_fetcher ||= Gemirro::GemsFetcher.new(
206
- configuration.source, versions_fetcher)
207
- end
208
-
209
176
  ##
210
177
  # Return all gems pass to query
211
178
  #
@@ -272,23 +239,6 @@ module Gemirro
272
239
  end
273
240
  end
274
241
 
275
- ##
276
- # Try to cache gem classes
277
- #
278
- # @param [String] gem_name Gem name
279
- # @return [Gem]
280
- #
281
- def stored_gem(gem_name, gem_version, platform = 'ruby')
282
- @stored_gems ||= {}
283
- # rubocop:disable Metrics/LineLength
284
- @stored_gems[gem_name] = {} unless @stored_gems.key?(gem_name)
285
- @stored_gems[gem_name][gem_version] = {} unless @stored_gems[gem_name].key?(gem_version)
286
- @stored_gems[gem_name][gem_version][platform] ||= Gem.new(gem_name, gem_version, platform) unless @stored_gems[gem_name][gem_version].key?(platform)
287
- # rubocop:enable Metrics/LineLength
288
-
289
- @stored_gems[gem_name][gem_version][platform]
290
- end
291
-
292
242
  helpers do
293
243
  ##
294
244
  # Return gem specification from gemname and version
@@ -298,7 +248,7 @@ module Gemirro
298
248
  # @return [::Gem::Specification]
299
249
  #
300
250
  def spec_for(gemname, version, platform = 'ruby')
301
- gem = stored_gem(gemname, version.to_s, platform)
251
+ gem = Utils.stored_gem(gemname, version.to_s, platform)
302
252
  gemspec_path = File.join('quick',
303
253
  Gemirro::Configuration.marshal_identifier,
304
254
  gem.gemspec_filename)
data/lib/gemirro/utils.rb CHANGED
@@ -7,10 +7,18 @@ module Gemirro
7
7
  #
8
8
  # @!attribute [r] client
9
9
  # @return [HTTPClient]
10
+ # @!attribute [r] versions_fetcher
11
+ # @return [VersionsFetcher]
12
+ # @!attribute [r] gems_fetcher
13
+ # @return [Gemirro::GemsFetcher]
10
14
  #
11
15
  class Utils
12
- attr_reader :cache
13
-
16
+ attr_reader(:cache,
17
+ :versions_fetcher,
18
+ :gems_fetcher,
19
+ :gems_orig_collection,
20
+ :gems_source_collection,
21
+ :stored_gems)
14
22
  ##
15
23
  # Cache class to store marshal and data into files
16
24
  #
@@ -28,6 +36,9 @@ module Gemirro
28
36
  # @return [Gemirro::GemVersionCollection]
29
37
  #
30
38
  def self.gems_collection(orig = true)
39
+ return @gems_orig_collection if orig && !@gems_orig_collection.nil?
40
+ return @gems_source_collection if !orig && !@gems_source_collection.nil?
41
+
31
42
  gems = []
32
43
  specs_files_paths(orig).pmap do |specs_file_path|
33
44
  next unless File.exist?(specs_file_path)
@@ -38,6 +49,9 @@ module Gemirro
38
49
  end
39
50
 
40
51
  collection = GemVersionCollection.new(gems)
52
+ @gems_source_collection = collection unless orig
53
+ @gems_orig_collection = collection if orig
54
+
41
55
  collection
42
56
  end
43
57
 
@@ -81,5 +95,38 @@ module Gemirro
81
95
  def self.configuration
82
96
  Gemirro.configuration
83
97
  end
98
+
99
+ ##
100
+ # @see Gemirro::VersionsFetcher.fetch
101
+ #
102
+ def self.versions_fetcher
103
+ @versions_fetcher ||= Gemirro::VersionsFetcher
104
+ .new(configuration.source).fetch
105
+ end
106
+
107
+ ##
108
+ # @return [Gemirro::GemsFetcher]
109
+ #
110
+ def self.gems_fetcher
111
+ @gems_fetcher ||= Gemirro::GemsFetcher.new(
112
+ configuration.source, versions_fetcher)
113
+ end
114
+
115
+ ##
116
+ # Try to cache gem classes
117
+ #
118
+ # @param [String] gem_name Gem name
119
+ # @return [Gem]
120
+ #
121
+ def self.stored_gem(gem_name, gem_version, platform = 'ruby')
122
+ @stored_gems ||= {}
123
+ # rubocop:disable Metrics/LineLength
124
+ @stored_gems[gem_name] = {} unless @stored_gems.key?(gem_name)
125
+ @stored_gems[gem_name][gem_version] = {} unless @stored_gems[gem_name].key?(gem_version)
126
+ @stored_gems[gem_name][gem_version][platform] ||= Gem.new(gem_name, gem_version, platform) unless @stored_gems[gem_name][gem_version].key?(platform)
127
+ # rubocop:enable Metrics/LineLength
128
+
129
+ @stored_gems[gem_name][gem_version][platform]
130
+ end
84
131
  end
85
132
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Gemirro Version
3
3
  module Gemirro
4
- VERSION = '0.13.2'
4
+ VERSION = '0.13.3'
5
5
  end
@@ -64,7 +64,19 @@ module Gemirro
64
64
  gem = Gem.new('gemirro')
65
65
  version = ::Gem::Version.new('0.0.1')
66
66
  allow(@source).to receive(:fetch_gem)
67
- .once.with('gemirro', version).and_return('gemirro')
67
+ .with('gemirro', version).and_return('gemirro')
68
+
69
+ expect(@fetcher.fetch_gem(gem, version)).to eq('gemirro')
70
+ end
71
+
72
+ it 'should fetch latest gem' do
73
+ allow(Utils.logger).to receive(:info)
74
+ .once.with('Fetching gemirro-0.0.1.gem')
75
+ MirrorDirectory.new('./').add_directory('gems')
76
+ gem = Gem.new('gemirro', :latest)
77
+ version = ::Gem::Version.new('0.0.1')
78
+ allow(@source).to receive(:fetch_gem)
79
+ .with('gemirro', version).and_return('gemirro')
68
80
 
69
81
  expect(@fetcher.fetch_gem(gem, version)).to eq('gemirro')
70
82
  end
@@ -82,6 +94,19 @@ module Gemirro
82
94
  expect(@fetcher.fetch_gemspec(gem, version)).to eq('gemirro')
83
95
  end
84
96
 
97
+ it 'should fetch latest gemspec' do
98
+ allow(Utils.logger).to receive(:info)
99
+ .once.with('Fetching gemirro-0.0.1.gemspec.rz')
100
+ MirrorDirectory.new('./').add_directory('quick/Marshal.4.8')
101
+ gem = Gem.new('gemirro', :latest)
102
+ gem.gemspec = true
103
+ version = ::Gem::Version.new('0.0.1')
104
+ allow(@source).to receive(:fetch_gemspec)
105
+ .once.with('gemirro', version).and_return('gemirro')
106
+
107
+ expect(@fetcher.fetch_gemspec(gem, version)).to eq('gemirro')
108
+ end
109
+
85
110
  it 'should not fetch gemspec if file exists' do
86
111
  allow(Utils.logger).to receive(:info)
87
112
  .once.with('Fetching gemirro-0.0.1.gemspec.rz')
@@ -35,6 +35,8 @@ module Gemirro
35
35
  MirrorFile.new('/var/www/gemirro/test').write('content')
36
36
  Gemirro.configuration.destination = '/var/www/gemirro'
37
37
  Utils.instance_eval('@cache = nil')
38
+ Utils.instance_eval('@gems_orig_collection = nil')
39
+ Utils.instance_eval('@gems_source_collection = nil')
38
40
  FakeFS::FileSystem.clone(Gemirro::Configuration.views_directory)
39
41
  end
40
42
 
data/views/gem.erb CHANGED
@@ -5,7 +5,7 @@
5
5
  </div>
6
6
 
7
7
  <div class="col-lg-12">
8
- <% @gem.by_name do |name, versions| %>
8
+ <% gem.by_name do |name, versions| %>
9
9
  <div class="col-lg-6 center-block pull-none">
10
10
  <div class="panel panel-info">
11
11
  <div class="panel-heading">
data/views/index.erb CHANGED
@@ -6,9 +6,9 @@
6
6
  </div>
7
7
 
8
8
  <div class="col-lg-12">
9
- <% if @gems.any? %>
9
+ <% if gems.any? %>
10
10
  <div class="col-lg-6 center-block pull-none">
11
- <% @gems.by_name do |name, versions| %>
11
+ <% gems.by_name do |name, versions| %>
12
12
  <div class="panel panel-info">
13
13
  <div class="panel-heading">
14
14
  <a href="<%= url("gem/#{name}") %>">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemirro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Rambaud
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  version: '0'
290
290
  requirements: []
291
291
  rubyforge_project:
292
- rubygems_version: 2.4.2
292
+ rubygems_version: 2.5.0
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: Gem for easily creating your own gems mirror.