mram-evedata 0.1.inferno11.3 → 0.1.inferno11.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ Eve Online
2
+ ==========
3
+
4
+ (the following is shamelessly stolen from [Wikipedia (30.08.2012)](http://en.wikipedia.org/wiki/Eve_online):
5
+
6
+ **Eve Online** (stylised **EVE Online**) is a video game by [CCP Games](http://en.wikipedia.org/wiki/CCP_Games). It is a player-driven, persistent-world MMORPG set in a science fiction space setting. Characters pilot customizable ships through a galaxy of over 7,500 star systems. Most star systems are connected to one or more other star systems by means of stargates. The star systems can contain moons, planets, stations, wormholes, asteroid belts and complexes.
7
+
8
+ Players of Eve Online can participate in a number of in-game professions and activities, including mining, piracy, manufacturing, trading, exploration, and combat (both player versus environment and player versus player). The character advancement system is based upon training skills in real time, even while not logged into the game.
9
+
10
+ mram-evedata, aka this gem
11
+ ==========================
12
+
13
+ CCP Games releases a dump of the static database objects of the EVE Online Universe whenever there is a major expansion (additional game content). Information about this can be found [here](http://wiki.eve-id.net/CCP_Static_Data_Dump). Unfortunately, these data dumps come originally as a Microsoft SQL Server Backup file, which not many people consider to be optimal for using in their own portals/community websites/tools etc. Fortunately however, there are people in the community who convert these dumps to other SQL formats, like MySQL, PostgreSQL, and SQLite3.
14
+
15
+ This gem aims to lessen the burden of manually importing new dumps, and also provides an ActiveRecord "abstraction layer" of the data presented.
16
+
17
+ Disclaimer
18
+ ==========
19
+
20
+ * i'm not a professional software developer, let alone a ruby/rails experienced programmer. i do this because i actually play EVE Online and because scripting and hacking together tools is a hobby of mine.
21
+ * all data/information/code is presented to you as is. it might work for you, it might not, it might kill your dog. use at your own risk, you have been warned.
22
+ * initially i planned to diversify this gem to support at least MySQL/PostgreSQL/SQLite, but since i myself only use MySQL for my current projects, i kind of just stuck with that for now.
23
+ * i also had plans to allow for the simultaneous use of different EVE-Db-Dump versions, but scrapped those due to time constraints. so only the latest dump is supported atm.
24
+ * i am **in no way affiliated with CCP Games**, all of the brands and names and whatnot are theirs and theirs only. insert the rest of the legal yadda yadda. i'm not doing this for profit.
25
+
26
+ Data to be imported
27
+ ===================
28
+
29
+ The data this gem is downloading and importing is **not** assembled by me. i am merely providing a "glue layer" to use it easily and (somewhat) efficiently in a Rails application.
30
+ Currently, i am using [this guy's dump files](http://www.fuzzwork.co.uk/dump/) for the import, but this might change at any time.
31
+
@@ -1,4 +1,5 @@
1
1
  module EveData
2
- VERSION = "0.1.inferno11.3"
2
+ VERSION = "0.1.inferno11.4"
3
+ DATAURL = "http://cloud.github.com/downloads/mrambossek/mram-evedata/mysql55-inferno11-extended.sql.bz2"
3
4
  DATAFILE = "mysql55-inferno11-extended.sql.bz2"
4
5
  end
@@ -1,10 +1,71 @@
1
+ # vim: set foldmethod=marker smarttab sw=2: #
2
+
3
+ require 'mram-evedata/version'
4
+ require 'tempfile'
5
+ require 'net/http'
6
+ require 'uri'
7
+ require 'digest/md5'
8
+ require 'fileutils'
9
+ require 'ruby-progressbar'
10
+
1
11
  namespace :eve_data do
12
+ desc "Download EDD to data/#{EveData::DATAFILE}"
13
+ task :download => :environment do # {{{
14
+ data_dir = Rails.root.join('data')
15
+ file_complete = data_dir.join(EveData::DATAFILE)
16
+ md5_complete = "#{file_complete}.md5"
17
+
18
+ if File.readable?(file_complete) then
19
+ puts "#{file_complete} already exists"
20
+ else
21
+ uri = URI(URI.join(EveData::DATAURL, EveData::DATAFILE))
22
+ puts "trying to download #{uri.to_s} to #{file_complete}"
23
+ ret = download_file(uri, file_complete, true)
24
+ puts (ret ? "success." : "failed.")
25
+ end
26
+
27
+ if File.readable?(md5_complete) then
28
+ puts "#{md5_complete} already exists"
29
+ else
30
+ uri = URI(URI.join(EveData::DATAURL, EveData::DATAFILE+".md5"))
31
+ puts "trying to download #{uri.to_s} to #{md5_complete}"
32
+ ret = download_file(uri, md5_complete, false)
33
+ puts (ret ? "success." : "failed.")
34
+ end
35
+
36
+ local_file_is_ok = false
37
+
38
+ File.open(md5_complete, "r") do |f|
39
+ while (line = f.gets) do
40
+ if matches = line.match(/^(?<md5>[a-zA-Z0-9]{32})\ (?<binary>.)(?<filename>.*)$/) then
41
+ if matches[:filename] == EveData::DATAFILE then
42
+ myhash = Digest::MD5.hexdigest(File.read(file_complete))
43
+ printf("local file : %s\n", myhash)
44
+ printf("correct hash: %s\n", matches[:md5])
45
+ local_file_is_ok = (myhash == matches[:md5])
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ if local_file_is_ok then
52
+ puts "local file is ok"
53
+ else
54
+ uri = URI(URI.join(EveData::DATAURL, EveData::DATAFILE))
55
+ puts "local file hash MISMATCH, trying to redownload"
56
+ ret = download_file(uri, file_complete, true)
57
+ puts (ret ? "success." : "failed.")
58
+ end
59
+ end # }}}
60
+
2
61
  desc "Import Eve Online Static Data Dump to EDD database"
3
- task :importdb => :environment do
4
- require 'mram-evedata/version'
5
- require 'tempfile'
62
+ task :import => :environment do # {{{
6
63
 
7
- data_absolute = EveData::Engine.root.join('data', EveData::DATAFILE)
64
+ file_complete = Rails.root.join('data', EveData::DATAFILE)
65
+ unless File.readable?(file_complete) then
66
+ puts "data dump could not be found in #{file_complete}, trying to download"
67
+ Rake::Task["eve_data:download"].invoke
68
+ end
8
69
 
9
70
  unless cfg = ActiveRecord::Base.configurations['eve_data_dump'] then
10
71
  raise IOError, "missing 'eve_data_dump' block in config/database.yml"
@@ -26,11 +87,44 @@ namespace :eve_data do
26
87
  return false
27
88
  end
28
89
 
29
- puts "now trying to import dump from '#{data_absolute}':"
30
- ret = system("bzcat #{data_absolute} | mysql --defaults-extra-file=#{f.path} #{cfg["database"]}")
90
+ puts "now trying to import dump from '#{file_complete}':"
91
+ ret = system("bzcat #{file_complete} | mysql --defaults-extra-file=#{f.path} #{cfg["database"]}")
31
92
  puts (ret ? "success!" : "failed!")
32
93
  end
33
94
 
34
95
  true
35
- end
96
+ end # }}}
36
97
  end
98
+
99
+ def download_file(uri, fname, use_pbar = false) # {{{
100
+ dname = File.dirname(fname)
101
+
102
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
103
+ res = http.request_head(uri.path)
104
+
105
+ case res
106
+ when Net::HTTPSuccess
107
+ when Net::HTTPRedirection then
108
+ uri = URI(res['location'])
109
+ res = http.request_head(uri.path)
110
+ else
111
+ return false
112
+ end
113
+
114
+ if use_pbar then
115
+ pbar = ProgressBar.create(:title => EveData::DATAFILE, :total => res['Content-Length'].to_i, :format => '%a %e |%b>>%i| %p%% %t')
116
+ end
117
+
118
+ http.request_get(uri.path) do |res|
119
+ FileUtils.mkdir_p(dname) unless Dir.exists?(dname)
120
+ open fname, "wb" do |io|
121
+ res.read_body do |chunk|
122
+ io.write chunk
123
+ pbar.progress += chunk.length if pbar
124
+ end
125
+ end
126
+ end
127
+ pbar.finish if pbar
128
+ end
129
+ true
130
+ end # }}}
data/mram-evedata.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency 'rails', "~> 3.2.0"
24
24
  s.add_dependency 'composite_primary_keys', '~> 5.0'
25
+ s.add_dependency 'ruby-progressbar'
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mram-evedata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.inferno11.3
4
+ version: 0.1.inferno11.4
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &13670160 !ruby/object:Gem::Requirement
16
+ requirement: &6133420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13670160
24
+ version_requirements: *6133420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: composite_primary_keys
27
- requirement: &13669700 !ruby/object:Gem::Requirement
27
+ requirement: &6132420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: '5.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *13669700
35
+ version_requirements: *6132420
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby-progressbar
38
+ requirement: &6131420 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *6131420
36
47
  description: this gem will import the EVE Online Static Data Dump into your database
37
48
  and provide a framework for accessing it
38
49
  email:
@@ -44,7 +55,7 @@ files:
44
55
  - .gitignore
45
56
  - Gemfile
46
57
  - MIT-LICENSE
47
- - README.rdoc
58
+ - README.md
48
59
  - Rakefile
49
60
  - app/assets/images/mram-evedata/.gitkeep
50
61
  - app/assets/javascripts/mram-evedata/application.js
@@ -72,7 +83,6 @@ files:
72
83
  - app/models/eve_data/type_requirement.rb
73
84
  - app/views/layouts/mram-evedata/application.html.erb
74
85
  - config/routes.rb
75
- - data/mysql55-inferno11-extended.sql.bz2
76
86
  - lib/generators/eve_data/sample_db_config/sample_db_config_generator.rb
77
87
  - lib/mram-evedata.rb
78
88
  - lib/mram-evedata/engine.rb
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = Mram::EveData
2
-
3
- This project rocks and uses MIT-LICENSE.