wonko_the_sane 0.1.2 → 0.1.4

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/bin/wonko_the_sane +12 -28
  3. data/data/sources.json +0 -5
  4. data/lib/wonko_the_sane.rb +6 -26
  5. data/lib/wonko_the_sane/input/base_input.rb +5 -10
  6. data/lib/wonko_the_sane/input/forge_installer_profile_input.rb +29 -47
  7. data/lib/wonko_the_sane/input/forgefiles_mods_input.rb +4 -7
  8. data/lib/wonko_the_sane/input/jenkins_input.rb +11 -15
  9. data/lib/wonko_the_sane/input/mojang_input.rb +52 -61
  10. data/lib/wonko_the_sane/{reader_writer.rb → new_format.rb} +31 -35
  11. data/lib/wonko_the_sane/old_format.rb +123 -0
  12. data/lib/wonko_the_sane/registry.rb +38 -23
  13. data/lib/wonko_the_sane/rules.rb +6 -6
  14. data/lib/wonko_the_sane/timestamps.rb +4 -4
  15. data/lib/wonko_the_sane/tools/update_nem.rb +20 -18
  16. data/lib/wonko_the_sane/util/configuration.rb +54 -2
  17. data/lib/wonko_the_sane/util/deep_storage_cache.rb +10 -8
  18. data/lib/wonko_the_sane/util/extraction_cache.rb +5 -4
  19. data/lib/wonko_the_sane/util/file_hash_cache.rb +6 -6
  20. data/lib/wonko_the_sane/util/http_cache.rb +50 -105
  21. data/lib/wonko_the_sane/util/maven_identifier.rb +8 -14
  22. data/lib/wonko_the_sane/util/task_stack.rb +7 -6
  23. data/lib/wonko_the_sane/{version_parser.rb → util/version_parser.rb} +10 -14
  24. data/lib/wonko_the_sane/version.rb +1 -1
  25. data/lib/wonko_the_sane/versionlists/base_version_list.rb +22 -15
  26. data/lib/wonko_the_sane/versionlists/curse_version_list.rb +15 -16
  27. data/lib/wonko_the_sane/versionlists/forge_version_list.rb +34 -37
  28. data/lib/wonko_the_sane/versionlists/forgefiles_mods_list.rb +3 -7
  29. data/lib/wonko_the_sane/versionlists/jenkins_version_list.rb +6 -15
  30. data/lib/wonko_the_sane/versionlists/liteloader_version_list.rb +18 -28
  31. data/lib/wonko_the_sane/versionlists/vanilla_legacy_version_list.rb +6 -6
  32. data/lib/wonko_the_sane/versionlists/vanilla_version_list.rb +6 -8
  33. data/lib/wonko_the_sane/wonko_version.rb +32 -12
  34. metadata +71 -15
  35. data/lib/wonko_the_sane/wonkoweb_uploader.rb +0 -162
@@ -1,27 +1,23 @@
1
1
  class VersionParser
2
2
  private
3
- @@cache = {}
3
+
4
+ cache = {}
5
+
4
6
  def self.parse(string)
5
- if @@cache.has_key? string
6
- return @@cache[string]
7
- end
7
+ return self.cache[string] if self.cache.has_key? string
8
8
  appendix = string.scan(/\-.*$/).first
9
9
  string = string.sub /\-.*$/, ''
10
10
  sections = string.split '.'
11
11
  sections.map! do |sec|
12
12
  test = Integer sec rescue nil
13
- if test.nil?
14
- sec
15
- else
16
- test
17
- end
13
+ test || sec
18
14
  end
19
15
 
20
16
  result = {
21
17
  appendix: appendix,
22
18
  sections: sections
23
19
  }
24
- @@cache[string] = result
20
+ self.cache[string] = result
25
21
  return result
26
22
  end
27
23
 
@@ -42,7 +38,7 @@ class VersionParser
42
38
  when 'pre'
43
39
  [2, digits]
44
40
  end
45
- return ret ? ret : [-1, digits]
41
+ ret || [-1, digits]
46
42
  end
47
43
 
48
44
  def self.compare_values(first, second)
@@ -64,7 +60,7 @@ class VersionParser
64
60
  size.times do |index|
65
61
  val1 = par1[:sections].length > index ? par1[:sections][index] : 0
66
62
  val2 = par2[:sections].length > index ? par2[:sections][index] : 0
67
- if val1.is_a? Integer and val2.is_a? Integer
63
+ if val1.is_a? Integer && val2.is_a?(Integer)
68
64
  ret = VersionParser.compare_values val1, val2
69
65
  elsif val1.is_a? Integer
70
66
  ret = VersionParser.compare_values val1.to_s, val2
@@ -76,7 +72,7 @@ class VersionParser
76
72
  break unless ret == 0
77
73
  end
78
74
  if ret == 0
79
- if par1[:appendix] and par2[:appendix]
75
+ if par1[:appendix] && par2[:appendix]
80
76
  appendix1 = VersionParser.appendix_values par1[:appendix]
81
77
  appendix2 = VersionParser.appendix_values par2[:appendix]
82
78
  ret = VersionParser.compare_values appendix1[0], appendix2[0]
@@ -112,4 +108,4 @@ class VersionParser
112
108
  def self.not_equal?(string1, string2)
113
109
  VersionParser.compare(string1, string2) != 0
114
110
  end
115
- end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module WonkoTheSane
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -2,43 +2,50 @@ class BaseVersionList
2
2
  attr_accessor :artifact
3
3
  # @processed contains a list of version ids for all versions that have been processed. simply clear it to invalidate caches
4
4
  attr_accessor :processed
5
- attr_accessor :lastError
5
+ attr_accessor :last_error
6
6
 
7
7
  def initialize(artifact)
8
8
  @artifact = artifact
9
9
  if File.exist? cache_file
10
10
  data = JSON.parse File.read(cache_file), symbolize_names: true
11
- @processed = data[:versions] ? data[:versions] : []
12
- @lastError = data[:lastError]
11
+ @processed = data[:versions] || []
12
+ @last_error = data[:last_error]
13
13
  else
14
14
  @processed = []
15
- @lastError = nil
16
15
  end
17
16
  end
18
17
 
19
18
  def refresh
20
- @lastError = nil
19
+ @last_error = nil
21
20
  versions = get_versions
22
21
 
23
22
  # check if some versions aren't in @processed (likely new ones) and fetch and process them
24
23
  versions.each do |version|
24
+ next if version.nil?
25
25
  begin
26
- next if not version
27
26
  id = version.is_a?(Array) ? version.first : version
28
27
  unless @processed.include? id
29
28
  files = get_version version
30
- next if files.nil? or (files.is_a? Array and files.empty?)
29
+ next if files.nil? || (files.is_a?(Array) && files.empty?)
31
30
 
32
- files.flatten.each do |file|
33
- file.is_complete = true
34
- Registry.instance.store file
35
- end if files and files.is_a? Array
36
- files.is_complete = true if files and files.is_a? WonkoVersion
37
- Registry.instance.store files if files and files.is_a? WonkoVersion
31
+ if files.is_a?(Array)
32
+ files.flatten.each do |file|
33
+ file.is_complete = true
34
+ Registry.instance.store file
35
+ end
36
+ else
37
+ files.is_complete = true
38
+ Registry.instance.store files
39
+ end
38
40
 
39
41
  @processed << id
40
42
  write_cache_file
41
43
  end
44
+ rescue => e
45
+ logger.error e.message
46
+ logger.warn e.backtrace.first
47
+ binding.pry if $stdout.isatty && ENV['DEBUG_ON_ERROR']
48
+ @last_error = e.message
42
49
  end
43
50
  end
44
51
 
@@ -47,7 +54,7 @@ class BaseVersionList
47
54
  logger.error e.message
48
55
  logger.warn e.backtrace.first
49
56
  binding.pry if $stdout.isatty && ENV['DEBUG_ON_ERROR']
50
- @lastError = e.message
57
+ @last_error = e.message
51
58
  end
52
59
 
53
60
  def logger
@@ -74,7 +81,7 @@ class BaseVersionList
74
81
  def write_cache_file
75
82
  File.write cache_file, JSON.pretty_generate({
76
83
  versions: @processed,
77
- lastError: @lastError
84
+ lastError: @last_error
78
85
  })
79
86
  end
80
87
 
@@ -1,38 +1,37 @@
1
1
  class CurseVersionList < BaseVersionList
2
- def initialize(uid, curseId, fileRegex)
3
- super(uid)
4
- @curseId = curseId
5
- @fileRegex = fileRegex.gsub /\?P\</, '?<'
2
+ def initialize(uid, curse_id, file_regex)
3
+ super uid
4
+ @curse_id = curse_id
5
+ @file_regex = file_regex.gsub /\?P\</, '?<'
6
6
  end
7
7
 
8
8
  def get_versions
9
- result = Oga.parse_html HTTPCache.file('http://curse.com/project/' + @curseId, ctxt: @artifact, key: 'curse/' + @curseId + '.html', check_stale: false)
9
+ result = Oga.parse_html HTTPCache.file('http://curse.com/project/' + @curse_id, ctxt: @artifact, key: 'curse/' + @curse_id + '.html', check_stale: false)
10
10
  # start by getting rid of some elements that standard xml parsers have issues with
11
- result.each_node do |node| node.remove if node.is_a? Oga::XML::Element and ['script', 'like'].include? node.name end
12
- rows = result.xpath("html/body/#{'div/' * 14}table/tbody/tr")
11
+ result.each_node { |node| node.remove if node.is_a?(Oga::XML::Element) && ['script', 'like'].include?(node.name) }
12
+ rows = result.xpath "html/body/#{'div/' * 14}table/tbody/tr"
13
13
 
14
- return rows.map do |row|
15
- match = row.xpath('td/a/text()').first.text.match @fileRegex
16
- next if not match
17
- version = match[:version]
14
+ rows.map do |row|
15
+ match = row.xpath('td/a/text()').first.text.match @file_regex
16
+ next if match.nil?
18
17
  [
19
- version,
18
+ match[:version],
20
19
  {
21
20
  url: row.xpath('td/a/@href').first.value,
22
21
  fileId: row.xpath('td/a/text()').first.text,
23
22
  type: row.xpath('td[2]/text()').first.text,
24
23
  mcVersion: row.xpath('td[3]/text()').first.text,
25
24
  timestamp: row.xpath('td[5]/@data-sort-value').first.value.to_i / 1000,
26
- version: version
25
+ version: match[:version]
27
26
  }
28
27
  ]
29
28
  end
30
29
  end
31
30
 
32
31
  def get_version(id)
33
- urlId = id[1][:url].match(/\/(\d*)$/)[1]
32
+ url_id = id[1][:url].match(/\/(\d*)$/)[1]
34
33
  dl = FileDownload.new
35
- dl.internalUrl = "http://addons-origin.cursecdn.com/files/#{urlId[0...4]}/#{urlId[4...7]}/#{id[1][:fileId]}"
34
+ dl.internal_url = "http://addons-origin.cursecdn.com/files/#{url_id[0...4]}/#{url_id[4...7]}/#{id[1][:fileId]}"
36
35
  dl.url = "http://curse.com" + id[1][:url]
37
36
  dl.destination = "mods/#{@artifact}-#{id.first}.jar"
38
37
 
@@ -43,6 +42,6 @@ class CurseVersionList < BaseVersionList
43
42
  file.time = id[1][:timestamp]
44
43
  file.requires << Referenced.new('net.minecraft', id[1][:mcVersion])
45
44
  file.common.downloads << dl
46
- return BaseSanitizer.sanitize file
45
+ BaseSanitizer.sanitize file
47
46
  end
48
47
  end
@@ -16,20 +16,20 @@ def fml_libs_mappings
16
16
  ]
17
17
 
18
18
  {
19
- '1.3.2' => [
19
+ :'1.3.2' => [
20
20
  create_fmllib_download('argo-2.25.jar'),
21
21
  create_fmllib_download('guava-12.0.1.jar'),
22
22
  create_fmllib_download('asm-all-4.0.jar')
23
23
  ],
24
- '1.4' => libs14,
25
- '1.4.1' => libs14,
26
- '1.4.2' => libs14,
27
- '1.4.3' => libs14,
28
- '1.4.4' => libs14,
29
- '1.4.5' => libs14,
30
- '1.4.6' => libs14,
31
- '1.4.7' => libs14,
32
- '1.5' => [
24
+ :'1.4' => libs14,
25
+ :'1.4.1' => libs14,
26
+ :'1.4.2' => libs14,
27
+ :'1.4.3' => libs14,
28
+ :'1.4.4' => libs14,
29
+ :'1.4.5' => libs14,
30
+ :'1.4.6' => libs14,
31
+ :'1.4.7' => libs14,
32
+ :'1.5' => [
33
33
  create_fmllib_download('argo-small-3.2.jar'),
34
34
  create_fmllib_download('guava-14.0-rc3.jar'),
35
35
  create_fmllib_download('asm-all-4.1.jar'),
@@ -37,7 +37,7 @@ def fml_libs_mappings
37
37
  create_fmllib_download('deobfuscation_data_1.5.zip'),
38
38
  create_fmllib_download('scala-library.jar', false)
39
39
  ],
40
- '1.5.1' => [
40
+ :'1.5.1' => [
41
41
  create_fmllib_download('argo-small-3.2.jar'),
42
42
  create_fmllib_download('guava-14.0-rc3.jar'),
43
43
  create_fmllib_download('asm-all-4.1.jar'),
@@ -45,7 +45,7 @@ def fml_libs_mappings
45
45
  create_fmllib_download('deobfuscation_data_1.5.1.zip'),
46
46
  create_fmllib_download('scala-library.jar', false)
47
47
  ],
48
- '1.5.2' => [
48
+ :'1.5.2' => [
49
49
  create_fmllib_download('argo-small-3.2.jar'),
50
50
  create_fmllib_download('guava-14.0-rc3.jar'),
51
51
  create_fmllib_download('asm-all-4.1.jar'),
@@ -73,7 +73,7 @@ class ForgeVersionList < BaseVersionList
73
73
  baseurl: result[:webpath]
74
74
  })
75
75
  end
76
- return out
76
+ out
77
77
  end
78
78
 
79
79
  def get_version(id)
@@ -83,40 +83,37 @@ class ForgeVersionList < BaseVersionList
83
83
  result = []
84
84
 
85
85
  files = id[1][:files]
86
- installerFile = files.find do |file| file[1] == 'installer' end
87
- universalFile = files.find do |file| file[1] == 'universal' end
88
- clientFile = files.find do |file| file[1] == 'client' end
89
- serverFile = files.find do |file| file[1] == 'server' end
86
+ installer_file = files.find { |file| file[1] == 'installer' }
87
+ universal_file = files.find { |file| file[1] == 'universal' }
88
+ client_file = files.find { |file| file[1] == 'client' }
89
+ server_file = files.find { |file| file[1] == 'server' }
90
90
 
91
91
  # installer versions of forge
92
- if not installerFile.nil? and id[1][:mcversion] != '1.5.2'
93
- path = "#{version}/#{id[1][:artifact]}-#{version}-#{installerFile[1]}.#{installerFile[0]}"
92
+ if !installer_file.nil? && id[1][:mcversion] != '1.5.2'
93
+ path = "#{version}/#{id[1][:artifact]}-#{version}-#{installer_file[1]}.#{installer_file[0]}"
94
94
  url = id[1][:baseurl] + '/' + path
95
95
  HTTPCache.get url, ctxt: @artifact, key: 'forgeinstallers/' + path, check_stale: false
96
96
  result << @input.parse(ExtractionCache.get('cache/network/forgeinstallers/' + path, :zip, 'install_profile.json'), id[1][:version])
97
- elsif not universalFile.nil?
97
+ elsif !universal_file.nil?
98
98
  res = construct_base_version id[1]
99
99
  mod = Jarmod.new
100
- mod.name = "net.minecraftforge:#{id[1][:artifact]}:#{version}:universal@#{universalFile[0]}"
101
- mod.mavenBaseUrl = 'http://files.minecraftforge.net/maven/'
100
+ mod.name = "net.minecraftforge:#{id[1][:artifact]}:#{version}:universal@#{universal_file[0]}"
101
+ mod.maven_base_url = 'http://files.minecraftforge.net/maven/'
102
102
  res.client.downloads << mod
103
103
  res.client.downloads |= fml_libs_mappings[id[1][:mcversion]] if fml_libs_mappings[id[1][:mcversion]]
104
104
  result << res
105
- else
106
- unless clientFile.nil?
107
- res = construct_base_version id[1]
108
- mod = Jarmod.new
109
- mod.name = "net.minecraftforge:#{id[1][:artifact]}:#{version}:client@#{clientFile[0]}"
110
- mod.mavenBaseUrl = 'http://files.minecraftforge.net/maven/'
111
- res.client.downloads << mod
112
- res.client.downloads |= fml_libs_mappings[id[1][:mcversion]] if fml_libs_mappings[id[1][:mcversion]]
113
- result << res
114
- end
115
- unless serverFile.nil?
116
-
117
- end
105
+ elsif !client_file.nil?
106
+ res = construct_base_version id[1]
107
+ mod = Jarmod.new
108
+ mod.name = "net.minecraftforge:#{id[1][:artifact]}:#{version}:client@#{client_file[0]}"
109
+ mod.maven_base_url = 'http://files.minecraftforge.net/maven/'
110
+ res.client.downloads << mod
111
+ res.client.downloads |= fml_libs_mappings[id[1][:mcversion]] if fml_libs_mappings[id[1][:mcversion]]
112
+ result << res
113
+ elsif !server_file.nil?
114
+ # TODO
118
115
  end
119
- return result.flatten
116
+ result.flatten
120
117
  end
121
118
 
122
119
  def construct_base_version(data)
@@ -137,6 +134,6 @@ end
137
134
 
138
135
  class FMLVersionList < ForgeVersionList
139
136
  def initialize
140
- super('net.minecraftforge.fml', 'fml')
137
+ super 'net.minecraftforge.fml', 'fml'
141
138
  end
142
139
  end
@@ -1,16 +1,12 @@
1
- require 'pry'
2
-
3
1
  class ForgeFilesModsList < BaseVersionList
4
- def initialize(artifact, urlId)
2
+ def initialize(artifact, url_id)
5
3
  super(artifact)
6
- @urlId = urlId
4
+ @url_id = url_id
7
5
  @input = ForgeFilesModsInput.new(artifact)
8
6
  end
9
7
 
10
8
  def get_versions
11
- result = get_json "http://files.minecraftforge.net/#{@urlId}/json"
12
-
13
- return result[:builds].map do |build|
9
+ get_json("http://files.minecraftforge.net/#{@url_id}/json")[:builds].map do |build|
14
10
  [
15
11
  build[:version],
16
12
  build
@@ -1,26 +1,17 @@
1
- require 'pry'
2
-
3
1
  class JenkinsVersionList < BaseVersionList
4
- def initialize(artifact, baseUrl, job, fileRegex)
2
+ def initialize(artifact, base_url, job, file_regex)
5
3
  super(artifact)
6
- @baseUrl = baseUrl
4
+ @base_url = base_url
7
5
  @job = job
8
- @input = JenkinsInput.new(artifact, fileRegex)
6
+ @input = JenkinsInput.new(artifact, file_regex)
9
7
 
10
- if @baseUrl[@baseUrl.length - 1] == '/'
11
- @baseUrl[@baseUrl.length - 1] = ''
8
+ if @base_url[@base_url.length - 1] == '/'
9
+ @base_url[@base_url.length - 1] = ''
12
10
  end
13
11
  end
14
12
 
15
13
  def get_versions
16
- result = get_json "#{@baseUrl}/job/#{@job}/api/json"
17
-
18
- return result[:builds].map do |build|
19
- [
20
- build[:number],
21
- build[:url]
22
- ]
23
- end
14
+ get_json("#{@base_url}/job/#{@job}/api/json")[:builds].map { |build| [build[:number], build[:url]] }
24
15
  end
25
16
 
26
17
  def get_version(id)
@@ -4,7 +4,7 @@ require 'time'
4
4
 
5
5
  class LiteLoaderVersionList < BaseVersionList
6
6
  def initialize
7
- super('com.mumfrey.liteloader')
7
+ super 'com.mumfrey.liteloader'
8
8
  end
9
9
 
10
10
  def get_versions
@@ -15,34 +15,26 @@ class LiteLoaderVersionList < BaseVersionList
15
15
  minecraft = mcver.first
16
16
  mcver[1][:artefacts].each do |artefact|
17
17
  if artefact.first == :'com.mumfrey:liteloader'
18
- latest = nil
19
- artefact[1].each do |item|
20
- if item.first == 'latest'
21
- latest = item[1][:version]
22
- break
23
- end
24
- end
25
- artefact[1].each do |item|
26
- if item.first != 'latest'
27
- out << [
28
- item[1][:version],
29
- item[1].merge({
30
- minecraft: minecraft.to_s,
31
- type: latest == item[1][:version] ? 'latest' : nil
32
- })
33
- ]
34
- end
18
+ latest = artefact[1].find { |i| i[0] == 'latest' }[1][:version]
19
+ artefact[1].reject { |i| i.first == 'latest' }.each do |item|
20
+ out << [
21
+ item[1][:version],
22
+ item[1].merge({
23
+ minecraft: minecraft.to_s,
24
+ type: latest == item[1][:version] ? 'latest' : nil
25
+ })
26
+ ]
35
27
  end
36
28
  end
37
29
  end
38
30
  end
39
- return out
31
+ out
40
32
  end
41
33
 
42
34
  def get_version(id)
43
- liteloaderLib = VersionLibrary.new
44
- liteloaderLib.name = 'com.mumfrey:liteloader:' + id[1][:version]
45
- liteloaderLib.url = 'http://dl.liteloader.com/versions/com/mumfrey/liteloader/' + id[1][:minecraft] + '/' + id[1][:file]
35
+ liteloader_lib = VersionLibrary.new
36
+ liteloader_lib.name = 'com.mumfrey:liteloader:' + id[1][:version]
37
+ liteloader_lib.url = 'http://dl.liteloader.com/versions/com/mumfrey/liteloader/' + id[1][:minecraft] + '/' + id[1][:file]
46
38
 
47
39
  file = WonkoVersion.new
48
40
  file.uid = 'com.mumfrey.liteloader'
@@ -53,14 +45,12 @@ class LiteLoaderVersionList < BaseVersionList
53
45
  file.client.tweakers = [ id[1][:tweakClass] ]
54
46
  file.client.mainClass = 'net.minecraft.launchwrapper.Launch'
55
47
  file.client.downloads = id[1][:libraries].map do |lib|
56
- libs = MojangInput.sanetize_mojang_library lib
57
- if lib[:name] == 'org.ow2.asm:asm-all:5.0.3'
58
- libs[0].mavenBaseUrl = 'http://repo.maven.apache.org/maven2/'
59
- end
48
+ libs = MojangInput.sanitize_mojang_library lib
49
+ libs[0].maven_base_url = 'http://repo.maven.apache.org/maven2/' if lib[:name] == 'org.ow2.asm:asm-all:5.0.3'
60
50
  libs
61
51
  end.flatten 1
62
52
  file.client.folders['minecraft/mods'] = ['mc.liteloadermods']
63
- file.client.downloads.unshift liteloaderLib
64
- return BaseSanitizer.sanitize file
53
+ file.client.downloads << liteloader_lib
54
+ BaseSanitizer.sanitize file
65
55
  end
66
56
  end