zold 0.4 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51f052404d2cb4a53a1a15c304bd264a5c19762f
4
- data.tar.gz: 17aa5f67c5b295fc68c2ca50bde2dd1be8236477
3
+ metadata.gz: 295d14430d8ebdd3388c4389ac84aa4690ea589d
4
+ data.tar.gz: 7f63a6461a39f5b4f14486d4ef2cf7ccf8a19795
5
5
  SHA512:
6
- metadata.gz: c9413af92527b0f5a07e856b7ff986e0a656736173b0282440821543f3b7f5dd91b13eceb5e8b7020c5682a0c60a986ad16a7363fe0e8d359ceb00d462f462ec
7
- data.tar.gz: 94f2c08f15b3539a2478b2934adb7c389ce4f9b4b0eaf3ee5e421be1867b254a9cb6f5c704696eee445eca41fb8e87ab3edfc539caf94e204ab4d3fca28d0632
6
+ metadata.gz: '008090bc5576401be63bb0366996f1c3e8509299d0ef9fdc691e513ee13c384fb83f35f9053294911787e50e774b8a8baa8b61525b96ea5ee186705ef24dfb5d'
7
+ data.tar.gz: a0d184623087e94ec76bf33ce0954c010de8f3d5793d8638bdd2a2a2209741f7f1f4f9360ae6cbd104e935f5b1b96109e94eb8794ad24104e991464b0fffd92d
data/README.md CHANGED
@@ -68,7 +68,7 @@ You will need PGP keys in `~/.ssh`. To generate them, if you don't have them
68
68
  yet, you can run:
69
69
 
70
70
  ```bash
71
- ssh-keygen -t rsa -b 4096
71
+ $ ssh-keygen -t rsa -b 4096
72
72
  ```
73
73
 
74
74
  ## Glossary
data/bin/zold CHANGED
@@ -40,19 +40,19 @@ Encoding.default_internal = Encoding::UTF_8
40
40
 
41
41
  log = Zold::Log.new
42
42
 
43
- begin
44
- args = []
45
- config = File.expand_path('~/.zold')
46
- if File.exist?(config)
47
- body = File.read(config)
48
- extra = body.split(/[\r\n]+/).map(&:strip)
49
- args += extra
50
- log.debug("Found #{body.split(/\n/).length} lines in #{config}")
51
- else
52
- log.debug("Default config file #{config} not found")
53
- end
54
- args += ARGV
43
+ args = []
44
+ config = File.expand_path('~/.zold')
45
+ if File.exist?(config)
46
+ body = File.read(config)
47
+ extra = body.split(/[\r\n]+/).map(&:strip)
48
+ args += extra
49
+ log.debug("Found #{body.split(/\n/).length} lines in #{config}")
50
+ else
51
+ log.debug("Default config file #{config} not found")
52
+ end
53
+ args += ARGV
55
54
 
55
+ begin
56
56
  opts = Slop.parse(args, strict: false, suppress_errors: true) do |o|
57
57
  o.banner = "Usage: zold [options] command [arguments]
58
58
  Available commands:
@@ -117,7 +117,7 @@ Available options:"
117
117
 
118
118
  command = opts.arguments[0]
119
119
 
120
- args = ARGV[(ARGV.index(command) + 1)..-1]
120
+ args = args[(args.index(command) + 1)..-1]
121
121
 
122
122
  wallets = Zold::Wallets.new(opts['dir'])
123
123
  remotes = Zold::Remotes.new(File.join(opts['dir'], '.zold/remotes'))
@@ -94,11 +94,11 @@ module Zold
94
94
  end
95
95
 
96
96
  def debug(msg)
97
- @log.debug(msg)
97
+ # nothing
98
98
  end
99
99
 
100
100
  def debug?
101
- @log.debug?
101
+ @log.info?
102
102
  end
103
103
  end
104
104
  end
@@ -56,7 +56,7 @@ Available options:"
56
56
  def push(wallet, _)
57
57
  raise 'The wallet is absent' unless wallet.exists?
58
58
  remote = @remotes.all[0]
59
- uri = URI("#{remote[:home]}/wallet/#{wallet.id}")
59
+ uri = URI("#{remote[:home]}wallet/#{wallet.id}")
60
60
  response = Http.new(uri).put(File.read(wallet.path))
61
61
  unless response.code == '200'
62
62
  raise "Failed to push to #{uri}: #{response.code}/#{response.message}"
@@ -76,6 +76,7 @@ Available options:"
76
76
  remove(opts.arguments[1], opts.arguments[2].to_i)
77
77
  when 'update'
78
78
  update(opts)
79
+ update(opts, false)
79
80
  else
80
81
  @log.info(opts.to_s)
81
82
  end
@@ -110,7 +111,7 @@ Available options:"
110
111
  @log.info("There are #{@remotes.all.count} remote nodes in the list")
111
112
  end
112
113
 
113
- def update(opts)
114
+ def update(opts, deep = true)
114
115
  @remotes.all.each do |r|
115
116
  uri = URI("#{r[:home]}remotes")
116
117
  res = Http.new(uri).get
@@ -145,9 +146,11 @@ Available options:"
145
146
  next
146
147
  end
147
148
  @remotes.rescore(r[:host], r[:port], score.value)
148
- json['all'].each do |s|
149
- unless @remotes.exists?(s['host'], s['port'])
150
- add(s['host'], s['port'])
149
+ if deep
150
+ json['all'].each do |s|
151
+ unless @remotes.exists?(s['host'], s['port'])
152
+ add(s['host'], s['port'])
153
+ end
151
154
  end
152
155
  end
153
156
  @log.info("#{r[:host]}:#{r[:port]}: #{Rainbow(score.value).green} \
@@ -20,6 +20,7 @@
20
20
 
21
21
  require 'rainbow'
22
22
  require 'net/http'
23
+ require_relative 'version'
23
24
  require_relative 'score'
24
25
 
25
26
  # HTTP page.
@@ -61,7 +62,8 @@ module Zold
61
62
 
62
63
  def headers
63
64
  headers = {
64
- 'User-Agent': 'Zold'
65
+ 'User-Agent': "Zold #{VERSION}",
66
+ 'Connection': 'close'
65
67
  }
66
68
  if @score.valid? && @score.value >= 3
67
69
  headers[SCORE_HEADER] = score.reduced(4).to_s
@@ -29,6 +29,13 @@ STDOUT.sync = true
29
29
  module Zold
30
30
  # Logging
31
31
  class Log
32
+ MUTEX = Mutex.new
33
+ def self.print(text)
34
+ MUTEX.synchronize do
35
+ puts(text)
36
+ end
37
+ end
38
+
32
39
  def debug(msg)
33
40
  # nothing
34
41
  end
@@ -38,7 +45,7 @@ module Zold
38
45
  end
39
46
 
40
47
  def info(msg)
41
- puts msg
48
+ Log.print(msg)
42
49
  end
43
50
 
44
51
  def info?
@@ -46,13 +53,13 @@ module Zold
46
53
  end
47
54
 
48
55
  def error(msg)
49
- puts "#{Rainbow('ERROR').red}: #{msg}"
56
+ Log.print("#{Rainbow('ERROR').red}: #{msg}")
50
57
  end
51
58
 
52
59
  # Extra verbose log
53
60
  class Verbose
54
61
  def debug(msg)
55
- puts msg
62
+ Log.print(msg)
56
63
  end
57
64
 
58
65
  def debug?
@@ -60,7 +67,7 @@ module Zold
60
67
  end
61
68
 
62
69
  def info(msg)
63
- puts msg
70
+ Log.print(msg)
64
71
  end
65
72
 
66
73
  def info?
@@ -68,7 +75,7 @@ module Zold
68
75
  end
69
76
 
70
77
  def error(msg)
71
- puts "#{Rainbow('ERROR').red}: #{msg}"
78
+ Log.print("#{Rainbow('ERROR').red}: #{msg}")
72
79
  end
73
80
  end
74
81
 
@@ -46,7 +46,7 @@ module Zold
46
46
  set :logging, true
47
47
  set :dump_errors, true
48
48
  set :start, Time.now
49
- set :lock, true
49
+ set :lock, false
50
50
  set :log, Log.new
51
51
  set :show_exceptions, false
52
52
  set :home, Dir.pwd
@@ -109,9 +109,15 @@ module Zold
109
109
  cps = copies(id)
110
110
  cps.add(request.body.read, 'remote', Remotes::PORT, 0)
111
111
  require_relative '../commands/fetch'
112
- Zold::Fetch.new(remotes: remotes, copies: cps.root).run([id.to_s])
112
+ Zold::Fetch.new(
113
+ remotes: remotes, copies: cps.root,
114
+ log: settings.log
115
+ ).run([id.to_s])
113
116
  require_relative '../commands/merge'
114
- Zold::Merge.new(wallets: wallets, copies: cps.root).run([id.to_s])
117
+ Zold::Merge.new(
118
+ wallets: wallets, copies: cps.root,
119
+ log: settings.log
120
+ ).run([id.to_s])
115
121
  cps.remove('remote', Remotes::PORT)
116
122
  "Success, #{wallet.id} balance is #{wallet.balance}"
117
123
  end
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.4'.freeze
26
+ VERSION = '0.4.1'.freeze
27
27
  end
@@ -48,13 +48,19 @@ class TestRemote < Minitest::Test
48
48
  stub_request(:get, 'http://localhost:2/remotes').to_return(
49
49
  status: 404
50
50
  )
51
+ stub_request(:get, 'http://localhost:888/remotes').to_return(
52
+ status: 404
53
+ )
54
+ stub_request(:get, 'http://localhost:999/remotes').to_return(
55
+ status: 404
56
+ )
51
57
  cmd = Zold::Remote.new(remotes: remotes)
52
58
  cmd.run(['clean'])
53
59
  cmd.run(%w[add localhost 1])
54
60
  cmd.run(%w[add localhost 2])
55
61
  assert_equal(2, remotes.all.count)
56
62
  cmd.run(['update', '--ignore-score-weakness'])
57
- assert_equal(3, remotes.all.count)
63
+ assert_equal(1, remotes.all.count)
58
64
  end
59
65
  end
60
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko