wonko_the_sane 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7aa648a065bfbc6fea0c7f581308ae4466a578fb
4
- data.tar.gz: b7049aa48d98789256ce1cb5142553f43e29a34e
3
+ metadata.gz: 8aae6ec1255ccf32e504d0d7e8e6cf1faaf4d835
4
+ data.tar.gz: c8426ad171f4b69585999bf476b2b2c1533fc3ea
5
5
  SHA512:
6
- metadata.gz: e3140975588a58455426f638079786fed82ef3e0a525811ed11f0117083a2e8da6095806fc0bce1586f9c32f858cb202f9024d90a9535b80696687df71cb45b8
7
- data.tar.gz: 400710a7384eb938b851c8c018746d3fbc0b3ffe57e0c070b82cf559d270aea6d69212cbe62ed3bc041fb393d6369b475aefbd69109e42908a5cb92314788872
6
+ metadata.gz: 7c0d69626c46d2764b174cfc43f301c431246d71f8e70588190dd2fe5be41a55c2b73d68e73ecf87dd9b7bcab01c4a28658f3d9bc797a26bd0e19c54e646ec87
7
+ data.tar.gz: cfd8cd641b7cc9380810632145c260f4545e4b41e0b2fe85e6f3591903331b826fb854e49215a22fbcea3f2fef4dacdbe75a26cf2de92a512be1fd8397cc077f
data/bin/wonko_the_sane CHANGED
@@ -38,7 +38,7 @@ OptionParser.new do |opts|
38
38
  if list.nil?
39
39
  Logging.logger['General'].warn "Couldn't find the specified list #{id.cyan}"
40
40
  else
41
- TaskStack.push(Proc.new do
41
+ WonkoTheSane.tasks.push(Proc.new do
42
42
  Logging.logger[list.artifact].info 'Refreshing'
43
43
  list.refresh
44
44
  Logging.logger[list.artifact].error list.last_error if list.last_error
@@ -47,7 +47,7 @@ OptionParser.new do |opts|
47
47
  end
48
48
  opts.on '-a', '--refresh-all', 'Refresh all lists' do
49
49
  WonkoTheSane.lists.each do |list|
50
- TaskStack.push(Proc.new do
50
+ WonkoTheSane.tasks.push(Proc.new do
51
51
  Logging.logger[list.artifact].info 'Refreshing'
52
52
  list.refresh
53
53
  Logging.logger[list.artifact].error list.last_error if list.last_error
@@ -83,4 +83,4 @@ OptionParser.new do |opts|
83
83
  end
84
84
  end.parse!
85
85
 
86
- TaskStack.pop_all
86
+ WonkoTheSane.tasks.pop_all
@@ -10,6 +10,7 @@ require 'digest'
10
10
  require 'date'
11
11
  require 'time'
12
12
  require 'oga'
13
+ require 'pathname'
13
14
  require 'active_support/core_ext/hash/indifferent_access'
14
15
  require 'active_support/core_ext/object/blank'
15
16
 
@@ -49,20 +50,16 @@ require 'wonko_the_sane/version_index'
49
50
  require 'wonko_the_sane/wonko_version'
50
51
 
51
52
  module WonkoTheSane
52
- def self.wonkoweb_uploader
53
- @uploader ||= WonkoWebUploader.new
54
- end
55
-
56
53
  def self.lists
57
54
  configuration.lists
58
55
  end
59
56
 
60
- def self.settings_file
61
- File.dirname(__FILE__) + '/../wonko_the_sane.yml'
57
+ def self.tasks
58
+ @tasks ||= WonkoTheSane::Util::TaskStack.new
62
59
  end
63
60
 
64
61
  def self.data(file)
65
- configuration.data_path + '/' + file
62
+ Pathname.new(configuration.data_path) + file
66
63
  end
67
64
 
68
65
  def self.data_json(file)
@@ -98,20 +98,20 @@ module Writer
98
98
  def write_resource(side, resource, out)
99
99
  data = {}
100
100
 
101
- data[:'general.traits'] = resource.traits if resource.traits and not resource.traits.empty?
102
- data[:'general.launcher'] = resource.launchMethod if resource.launchMethod
103
- data[:'general.folders'] = resource.folders if resource.folders and not resource.folders.empty?
101
+ data[:'general.traits'] = resource.traits unless resource.traits.blank?
102
+ data[:'general.launcher'] = resource.launchMethod unless resource.launchMethod.blank?
103
+ data[:'general.folders'] = resource.folders unless resource.folders.blank?
104
104
  resource.downloads.each do |dl|
105
105
  data[dl.type] = [] unless data[dl.type]
106
106
  data[dl.type] << dl.to_json
107
107
  end
108
- data[:'java.mainClass'] = resource.mainClass if resource.mainClass and resource.mainClass != ''
109
- data[:'mc.jarModTarget'] = resource.jarModTarget if resource.jarModTarget
108
+ data[:'java.mainClass'] = resource.mainClass unless resource.mainClass.blank?
109
+ data[:'mc.jarModTarget'] = resource.jarModTarget unless resource.jarModTarget.blank?
110
110
 
111
- data[:'mc.tweakers'] = resource.tweakers if resource.tweakers and not resource.tweakers.empty?
112
- data[:'mc.appletClass'] = resource.appletClass if resource.appletClass and resource.appletClass != ''
113
- data[:'mc.assets'] = resource.assets if resource.assets and resource.assets != ''
114
- data[:'mc.arguments'] = resource.minecraftArguments if resource.minecraftArguments and resource.minecraftArguments != ''
111
+ data[:'mc.tweakers'] = resource.tweakers unless resource.tweakers.blank?
112
+ data[:'mc.appletClass'] = resource.appletClass unless resource.appletClass.blank?
113
+ data[:'mc.assets'] = resource.assets unless resource.assets.blank?
114
+ data[:'mc.arguments'] = resource.minecraftArguments unless resource.minecraftArguments.blank?
115
115
 
116
116
  unless data.empty?
117
117
  if side == :client || side == :server
@@ -139,7 +139,7 @@ module Writer
139
139
  obj = { uid: req.uid }
140
140
  obj[:version] = req.version if req.version
141
141
  obj
142
- end if version.requires and not version.requires.empty?
142
+ end unless version.requires.blank?
143
143
 
144
144
  write_resource(:client, version.client, json[:data]) if version.is_complete
145
145
  write_resource(:server, version.server, json[:data]) if version.is_complete
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'active_support/core_ext/string/inflections'
2
3
 
3
4
  module WonkoTheSane
4
5
  module Util
@@ -9,13 +10,6 @@ module WonkoTheSane
9
10
  attr_accessor :bucket
10
11
  end
11
12
 
12
- class WonkoWeb
13
- attr_accessor :host
14
- attr_accessor :email
15
- attr_accessor :token
16
- attr_accessor :name
17
- end
18
-
19
13
  attr_reader :aws
20
14
  attr_reader :wonkoweb
21
15
  attr_reader :lists
@@ -25,7 +19,7 @@ module WonkoTheSane
25
19
  def initialize
26
20
  @lists = []
27
21
  @aws = Aws.new
28
- @wonkoweb = WonkoWeb.new
22
+ @data_path = Dir.pwd + '/data'
29
23
  end
30
24
 
31
25
  def load_from_env
@@ -33,35 +27,28 @@ module WonkoTheSane
33
27
  @aws.client_secret = ENV['WTS_AWS_CLIENT_SECRET'] if ENV['WTS_AWS_CLIENT_SECRET']
34
28
  @aws.bucket = ENV['WTS_AWS_BUCKET'] if ENV['WTS_AWS_BUCKET']
35
29
 
36
- @wonkoweb.host = ENV['WTS_WONKOWEB_HOST'] if ENV['WTS_WONKOWEB_HOST']
37
- @wonkoweb.email = ENV['WTS_WONKOWEB_EMAIL'] if ENV['WTS_WONKOWEB_EMAIL']
38
- @wonkoweb.token = ENV['WTS_WONKOWEB_TOKEN'] if ENV['WTS_WONKOWEB_TOKEN']
39
- @wonkoweb.token = ENV['WTS_WONKOWEB_NAME'] if ENV['WTS_WONKOWEB_NAME']
40
-
41
30
  @data_path = ENV['WTS_DATA_PATH'] if ENV['WTS_DATA_PATH']
42
31
  @out_dir = ENV['WTS_OUT_DIR'] if ENV['WTS_OUT_DIR']
43
32
  end
44
33
 
45
34
  def load_from_file(filename)
46
- raw = YAML.load_file filename
47
- @aws.client_id = raw['aws']['client_id']
48
- @aws.client_secret = raw['aws']['client_secret']
49
- @aws.bucket = raw['aws']['bucket']
50
-
51
- @wonkoweb.host = raw['wonkoweb']['host']
52
- @wonkoweb.email = raw['wonkoweb']['email']
53
- @wonkoweb.token = raw['wonkoweb']['token']
54
- @wonkoweb.name = raw['wonkoweb']['name']
35
+ raw = YAML.load_file(filename).with_indifferent_access
36
+ if raw.key? 'aws'
37
+ aws = raw['aws']
38
+ @aws.client_id = aws['client_id'] if aws.key? 'client_id'
39
+ @aws.client_secret = aws['client_secret'] if aws.key? 'client_secret'
40
+ @aws.bucket = aws['bucket'] if aws.key? 'bucket'
41
+ end
55
42
 
56
- @data_path = raw['data_path']
57
- @out_dir = raw['out_dir']
43
+ @data_path = raw['data_path'] if raw.key? 'data_path'
44
+ @out_dir = raw['out_dir'] if raw.key? 'out_dir'
58
45
  end
59
46
 
60
47
  def register_list(list)
61
48
  case list
62
- when String
63
- register_list list.to_sym
64
49
  when Symbol
50
+ register_list list.to_s.constantize
51
+ when String
65
52
  register_list list.constantize
66
53
  when Class
67
54
  register_list list.new
@@ -70,8 +57,12 @@ module WonkoTheSane
70
57
  end
71
58
  end
72
59
 
73
- def register_lists_from_sources
74
- sources = WonkoTheSane.data_json 'sources.json'
60
+ def register_lists_from_sources(filename = 'sources.json')
61
+ sources = if filename.is_a? String
62
+ WonkoTheSane.data_json filename
63
+ else
64
+ filename
65
+ end
75
66
  sources[:forgefiles].each do |uid, urlId|
76
67
  register_list ForgeFilesModsList.new(uid.to_s, urlId)
77
68
  end if sources[:forgefiles]
@@ -29,7 +29,7 @@ module WonkoTheSane
29
29
 
30
30
  object = @bucket.object info[:file]
31
31
  unless object.exists? && object.size == info[:size]
32
- TaskStack.in_background do
32
+ WonkoTheSane.tasks.in_background do
33
33
  # convert the hex-encoded md5 to a base64-encoded md5, which is what S3 expects
34
34
  # http://anthonylewis.com/2011/02/09/to-hex-and-back-with-ruby/
35
35
  md5 = [info[:md5].scan(/../).map { |x| x.hex.chr }.join].pack 'm0'
@@ -37,7 +37,7 @@ class HTTPCache
37
37
 
38
38
  return if File.exists?(cached_path) && !check_stale
39
39
 
40
- TaskStack.in_background do
40
+ WonkoTheSane.tasks.in_background do
41
41
  uri = URI.parse url
42
42
  host = URI::HTTP.new(uri.scheme, uri.userinfo, uri.host, uri.port, nil, nil, nil, nil, nil).to_s
43
43
 
@@ -1,22 +1,30 @@
1
- class TaskStack
2
- class << self; attr_accessor :queue; end
3
- self.queue = []
4
- def self.push(task)
5
- self.queue.push task
6
- end
7
- def self.push_defered(task)
8
- self.queue.unshift task
9
- end
10
- def self.pop
11
- task = self.queue.pop
12
- task.call
13
- end
14
- def self.pop_all
15
- self.pop until self.queue.empty?
16
- end
17
- def self.in_background(&block)
18
- thread = Thread.new &block
19
- TaskStack.pop_all
20
- thread.join.value
1
+ module WonkoTheSane
2
+ module Util
3
+ class TaskStack
4
+ attr_reader :queue
5
+
6
+ def initialize
7
+ @queue = []
8
+ end
9
+
10
+ def push(task)
11
+ @queue.push task
12
+ end
13
+ def push_defered(task)
14
+ @queue.unshift task
15
+ end
16
+ def pop
17
+ task = @queue.pop
18
+ task.call
19
+ end
20
+ def pop_all
21
+ pop until @queue.empty?
22
+ end
23
+ def in_background(&block)
24
+ thread = Thread.new &block
25
+ pop_all
26
+ thread.join.value
27
+ end
28
+ end
21
29
  end
22
30
  end
@@ -1,111 +1,107 @@
1
- class VersionParser
2
- private
1
+ module WonkoTheSane
2
+ module Util
3
+ class VersionParser
4
+ private
3
5
 
4
- cache = {}
6
+ class << self; attr_accessor :cache; end
7
+ self.cache = {}
5
8
 
6
- def self.parse(string)
7
- return self.cache[string] if self.cache.has_key? string
8
- appendix = string.scan(/\-.*$/).first
9
- string = string.sub /\-.*$/, ''
10
- sections = string.split '.'
11
- sections.map! do |sec|
12
- test = Integer sec rescue nil
13
- test || sec
14
- end
15
-
16
- result = {
17
- appendix: appendix,
18
- sections: sections
19
- }
20
- self.cache[string] = result
21
- return result
22
- end
9
+ def self.parse(string)
10
+ return self.cache[string] if self.cache.has_key? string
11
+ appendix = string.scan(/\-.*$/).first
12
+ sections = string.sub(/\-.*$/, '').split '.'
13
+ sections.map! do |sec|
14
+ test = Integer sec rescue nil
15
+ test || sec
16
+ end
23
17
 
24
- def self.appendix_values(appendix)
25
- str = appendix.scan /[a-zA-Z]*/
26
- digits = appendix.scan(/\d*/).join.to_i
27
- ret = case str
28
- when 'a'
29
- [0, digits]
30
- when 'alpha'
31
- [0, digits]
32
- when 'b'
33
- [1, digits]
34
- when 'beta'
35
- [1, digits]
36
- when 'rc'
37
- [2, digits]
38
- when 'pre'
39
- [2, digits]
40
- end
41
- ret || [-1, digits]
42
- end
18
+ result = {
19
+ appendix: appendix,
20
+ sections: sections
21
+ }
22
+ self.cache[string] = result
23
+ return result
24
+ end
43
25
 
44
- def self.compare_values(first, second)
45
- if first < second
46
- -1
47
- elsif first > second
48
- 1
49
- else
50
- 0
51
- end
52
- end
26
+ def self.appendix_values(appendix)
27
+ str = appendix.scan /[a-zA-Z]*/
28
+ digits = appendix.scan(/\d*/).join.to_i
29
+ ret = case str.find { |s| !s.blank? }
30
+ when 'a'
31
+ [0, digits]
32
+ when 'alpha'
33
+ [0, digits]
34
+ when 'b'
35
+ [1, digits]
36
+ when 'beta'
37
+ [1, digits]
38
+ when 'rc'
39
+ [2, digits]
40
+ when 'pre'
41
+ [2, digits]
42
+ end
43
+ ret || [-1, digits]
44
+ end
53
45
 
54
- public
55
- def self.compare(string1, string2)
56
- par1 = VersionParser.parse string1
57
- par2 = VersionParser.parse string2
58
- size = [par1[:sections].length, par2[:sections].length].max
59
- ret = 0
60
- size.times do |index|
61
- val1 = par1[:sections].length > index ? par1[:sections][index] : 0
62
- val2 = par2[:sections].length > index ? par2[:sections][index] : 0
63
- if val1.is_a? Integer && val2.is_a?(Integer)
64
- ret = VersionParser.compare_values val1, val2
65
- elsif val1.is_a? Integer
66
- ret = VersionParser.compare_values val1.to_s, val2
67
- elsif val2.is_a? Integer
68
- ret = VersionParser.compare_values val1, val2.to_s
69
- else
70
- ret = VersionParser.compare_values val1.to_s, val2.to_s
46
+ def self.compare_values(first, second)
47
+ if first < second
48
+ -1
49
+ elsif first > second
50
+ 1
51
+ else
52
+ 0
53
+ end
71
54
  end
72
- break unless ret == 0
73
- end
74
- if ret == 0
75
- if par1[:appendix] && par2[:appendix]
76
- appendix1 = VersionParser.appendix_values par1[:appendix]
77
- appendix2 = VersionParser.appendix_values par2[:appendix]
78
- ret = VersionParser.compare_values appendix1[0], appendix2[0]
55
+
56
+ public
57
+ def self.compare(string1, string2)
58
+ par1 = VersionParser.parse string1
59
+ par2 = VersionParser.parse string2
60
+ size = [par1[:sections].length, par2[:sections].length].max
61
+ ret = 0
62
+ size.times do |index|
63
+ val1 = par1[:sections].length > index ? par1[:sections][index] : 0
64
+ val2 = par2[:sections].length > index ? par2[:sections][index] : 0
65
+ ret = VersionParser.compare_values val1.to_i, val2.to_i
66
+ break unless ret == 0
67
+ end
79
68
  if ret == 0
80
- ret = VersionParser.compare_values appendix1[1], appendix2[1]
69
+ if par1[:appendix] && par2[:appendix]
70
+ appendix1 = VersionParser.appendix_values par1[:appendix]
71
+ appendix2 = VersionParser.appendix_values par2[:appendix]
72
+ ret = VersionParser.compare_values appendix1[0], appendix2[0]
73
+ if ret == 0
74
+ ret = VersionParser.compare_values appendix1[1], appendix2[1]
75
+ end
76
+ elsif par1[:appendix]
77
+ ret = -1
78
+ elsif par2[:appendix]
79
+ ret = 1
80
+ end
81
81
  end
82
- elsif par1[:appendix]
83
- ret = -1
84
- elsif par2[:appendix]
85
- ret = 1
82
+ return ret
86
83
  end
87
- end
88
- return ret
89
- end
90
84
 
91
- def self.less?(string1, string2)
92
- VersionParser.compare(string1, string2) == -1
93
- end
94
- def self.greater?(string1, string2)
95
- VersionParser.compare(string1, string2) == 1
96
- end
97
- def self.equal?(string1, string2)
98
- VersionParser.compare(string1, string2) == 0
99
- end
100
- def self.less_or_equal?(string1, string2)
101
- ret = VersionParser.compare string1, string2
102
- ret == 0 or ret == -1
103
- end
104
- def self.greater_or_equal?(string1, string2)
105
- ret = VersionParser.compare string1, string2
106
- ret == 0 or ret == 1
107
- end
108
- def self.not_equal?(string1, string2)
109
- VersionParser.compare(string1, string2) != 0
85
+ def self.less?(string1, string2)
86
+ VersionParser.compare(string1, string2) == -1
87
+ end
88
+ def self.greater?(string1, string2)
89
+ VersionParser.compare(string1, string2) == 1
90
+ end
91
+ def self.equal?(string1, string2)
92
+ VersionParser.compare(string1, string2) == 0
93
+ end
94
+ def self.less_or_equal?(string1, string2)
95
+ ret = VersionParser.compare string1, string2
96
+ ret == 0 or ret == -1
97
+ end
98
+ def self.greater_or_equal?(string1, string2)
99
+ ret = VersionParser.compare string1, string2
100
+ ret == 0 or ret == 1
101
+ end
102
+ def self.not_equal?(string1, string2)
103
+ VersionParser.compare(string1, string2) != 0
104
+ end
105
+ end
110
106
  end
111
107
  end
@@ -1,3 +1,3 @@
1
1
  module WonkoTheSane
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -26,11 +26,10 @@ class VanillaLegacyVersionList < BaseVersionList
26
26
  file.client.downloads = [ main_lib ]
27
27
 
28
28
  file.client.folders['minecraft/screenshots'] = ['general.screenshots']
29
- file.client.folders['minecraft/resourcepackks'] = ['mc.resourcepacks'] if file.time >= 1372430921
30
29
  file.client.folders['minecraft/texturepacks'] = ['mc.texturepacks'] if file.time < 1372430921
31
30
  file.client.folders['minecraft/saves'] = ['mc.saves.anvil'] if file.time >= 1330552800
32
- file.client.folders['minecraft/saves'] = ['mc.saves.region'] if file.time >= 1298325600 and file.time < 1330552800
33
- file.client.folders['minecraft/saves'] = ['mc.saves.infdev'] if file.time >= 1291327200 and file.time < 1298325600
31
+ file.client.folders['minecraft/saves'] = ['mc.saves.region'] if file.time >= 1298325600 && file.time < 1330552800
32
+ file.client.folders['minecraft/saves'] = ['mc.saves.infdev'] if file.time >= 1291327200 && file.time < 1298325600
34
33
  file.client.traits.delete 'texturepacks' if file.client.traits
35
34
  file.client.traits.delete 'no-resourcepacks' if file.client.traits
36
35
 
@@ -19,8 +19,8 @@ class Download
19
19
  size: @size,
20
20
  sha256: @sha256
21
21
  }
22
- obj[:rules] = @rules.map do |rule| rule.to_json end if @rules and not @rules.empty?
23
- return obj
22
+ obj[:rules] = @rules.map { |rule| rule.to_json } unless @rules.blank?
23
+ obj
24
24
  end
25
25
 
26
26
  def from_json(json)
@@ -100,7 +100,7 @@ class VersionLibrary < Download
100
100
  def to_json
101
101
  obj = super
102
102
  obj[:name] = @name
103
- obj[:@maven_base_url] = @maven_base_url if @maven_base_url
103
+ obj[:@maven_base_url] = @maven_base_url unless @maven_base_url.blank?
104
104
 
105
105
  unless @url
106
106
  obj.delete :url
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wonko_the_sane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 02JanDal
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-03 00:00:00.000000000 Z
13
+ date: 2015-10-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -375,7 +375,6 @@ files:
375
375
  - lib/wonko_the_sane/rules.rb
376
376
  - lib/wonko_the_sane/timestamps.rb
377
377
  - lib/wonko_the_sane/tools/update_nem.rb
378
- - lib/wonko_the_sane/util.rb
379
378
  - lib/wonko_the_sane/util/benchmark.rb
380
379
  - lib/wonko_the_sane/util/configuration.rb
381
380
  - lib/wonko_the_sane/util/deep_storage_cache.rb
@@ -1,17 +0,0 @@
1
- module Util
2
- def self.deep_map_keys(val, &block)
3
- Util.deep_map_hash val do |k, v|
4
- [yield(k), v]
5
- end
6
- end
7
-
8
- def self.deep_map(val, &block)
9
- if val.is_a? Array
10
- val.map { |item| deep_map_hash item, &block }
11
- elsif val.is_a? Hash
12
- Hash[val.map { |k, v| yield k, deep_map_hash(v, &block) }]
13
- else
14
- yield nil, val
15
- end
16
- end
17
- end