A corporation manager and dashboard for EVE Online
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

207 lignes
5.9 KiB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import gzip
  4. from pathlib import Path
  5. import shutil
  6. import sys
  7. import yaml
  8. _REGION = 3
  9. _CONSTELLATION = 4
  10. _SOLAR_SYSTEM = 5
  11. def _load_yaml(filename):
  12. with filename.open("rb") as fp:
  13. return yaml.load(fp, Loader=yaml.CLoader)
  14. def _verify_typeids(sde_dir):
  15. print("Verifying typeIDs... ", end="", flush=True)
  16. filename = sde_dir / "fsd" / "typeIDs.yaml"
  17. with filename.open("rb") as fp:
  18. data = yaml.load(fp.read(1024 * 16), Loader=yaml.CLoader)
  19. assert data[_REGION]["groupID"] == _REGION
  20. assert data[_REGION]["name"]["en"] == "Region"
  21. assert data[_CONSTELLATION]["groupID"] == _CONSTELLATION
  22. assert data[_CONSTELLATION]["name"]["en"] == "Constellation"
  23. assert data[_SOLAR_SYSTEM]["groupID"] == _SOLAR_SYSTEM
  24. assert data[_SOLAR_SYSTEM]["name"]["en"] == "Solar System"
  25. print("done.")
  26. def _load_ids(sde_dir):
  27. print("Loading itemIDs... ", end="", flush=True)
  28. data = _load_yaml(sde_dir / "bsd" / "invItems.yaml")
  29. ids = {_REGION: [], _CONSTELLATION: [], _SOLAR_SYSTEM: []}
  30. for entry in data:
  31. if entry["typeID"] in ids:
  32. ids[entry["typeID"]].append(entry["itemID"])
  33. print("done.")
  34. return ids
  35. def _load_names(sde_dir):
  36. print("Loading itemNames... ", end="", flush=True)
  37. data = _load_yaml(sde_dir / "bsd" / "invNames.yaml")
  38. names = {}
  39. for entry in data:
  40. name = entry["itemName"]
  41. assert isinstance(name, str)
  42. names[entry["itemID"]] = name
  43. print("done.")
  44. return names
  45. def _build_galaxy_skeleton(ids, names):
  46. print("Building galaxy skeleton... ", end="", flush=True)
  47. galaxy = {"regions": {}, "constellations": {}, "systems": {}}
  48. d = galaxy["regions"]
  49. for rid in ids[_REGION]:
  50. assert isinstance(rid, int)
  51. d[rid] = {
  52. "name": names[rid]
  53. }
  54. d = galaxy["constellations"]
  55. for cid in ids[_CONSTELLATION]:
  56. assert isinstance(cid, int)
  57. d[cid] = {
  58. "name": names[cid],
  59. "region": -1
  60. }
  61. d = galaxy["systems"]
  62. for sid in ids[_SOLAR_SYSTEM]:
  63. assert isinstance(sid, int)
  64. d[sid] = {
  65. "name": names[sid],
  66. "constellation": -1, "region": -1, "security": 0.0
  67. }
  68. print("done.")
  69. return galaxy
  70. def _load_galaxy_associations(sde_dir, galaxy):
  71. print("Loading galaxy staticdata... ", end="", flush=True)
  72. univdir = sde_dir / "fsd" / "universe"
  73. for base in univdir.iterdir():
  74. if not base.is_dir():
  75. continue
  76. for region in base.iterdir():
  77. if not region.is_dir():
  78. continue
  79. rdata = _load_yaml(region / "region.staticdata")
  80. rid = rdata["regionID"]
  81. assert isinstance(rid, int)
  82. assert rid >= 0
  83. for constellation in region.iterdir():
  84. if not constellation.is_dir():
  85. continue
  86. cdata = _load_yaml(constellation / "constellation.staticdata")
  87. cid = cdata["constellationID"]
  88. assert isinstance(cid, int)
  89. assert cid >= 0
  90. galaxy["constellations"][cid]["region"] = rid
  91. for system in constellation.iterdir():
  92. if not system.is_dir():
  93. continue
  94. sdata = _load_yaml(system / "solarsystem.staticdata")
  95. sid = sdata["solarSystemID"]
  96. sec = sdata["security"]
  97. assert isinstance(sid, int)
  98. assert isinstance(sec, float)
  99. assert sid >= 0
  100. assert sec >= -1.0 and sec <= 1.0
  101. galaxy["systems"][sid]["constellation"] = cid
  102. galaxy["systems"][sid]["region"] = rid
  103. galaxy["systems"][sid]["security"] = sec
  104. print("done.")
  105. for cid, constellation in galaxy["constellations"].items():
  106. if constellation["region"] < 0:
  107. print("[WARNING] Orphaned constellation: %d=%s" % (
  108. cid, constellation["name"]))
  109. for sid, system in galaxy["systems"].items():
  110. if system["region"] < 0 or system["constellation"] < 0:
  111. print("[WARNING] Orphaned system: %d=%s" % (sid, system["name"]))
  112. def _dump_galaxy(out_dir, galaxy):
  113. print("Dumping galaxy... ", end="", flush=True)
  114. filename = out_dir / "galaxy.yml"
  115. with filename.open("w") as fp:
  116. fp.write(yaml.dump(galaxy, Dumper=yaml.CDumper))
  117. print("done.")
  118. def _compress_galaxy(out_dir):
  119. print("Compressing galaxy... ", end="", flush=True)
  120. fn_src = out_dir / "galaxy.yml"
  121. fn_dst = out_dir / "galaxy.yml.gz"
  122. with fn_src.open("rb") as f_in:
  123. with gzip.open(str(fn_dst), "wb") as f_out:
  124. shutil.copyfileobj(f_in, f_out)
  125. print("done.")
  126. def _cleanup(out_dir):
  127. print("Cleaning up... ", end="", flush=True)
  128. (out_dir / "galaxy.yml").unlink()
  129. print("done.")
  130. def import_sde(sde_dir, out_dir):
  131. """Import the SDE unzipped at sde_dir to out_dir."""
  132. print("EVE Online static data import")
  133. print("- from: %s" % sde_dir)
  134. print("- to: %s" % out_dir)
  135. _verify_typeids(sde_dir)
  136. ids = _load_ids(sde_dir)
  137. print("Counts: regions=%d, constellations=%d, systems=%d" % (
  138. len(ids[_REGION]), len(ids[_CONSTELLATION]), len(ids[_SOLAR_SYSTEM])))
  139. names = _load_names(sde_dir)
  140. galaxy = _build_galaxy_skeleton(ids, names)
  141. del ids
  142. del names
  143. _load_galaxy_associations(sde_dir, galaxy)
  144. _dump_galaxy(out_dir, galaxy)
  145. del galaxy
  146. _compress_galaxy(out_dir)
  147. _cleanup(out_dir)
  148. def main():
  149. if len(sys.argv) < 2:
  150. print("usage: %s <sde_directory>" % sys.argv[0])
  151. exit(1)
  152. sde_dir = Path(sys.argv[1]).resolve()
  153. out_dir = Path(__file__).resolve().parent.parent / "data" / "universe"
  154. import_sde(sde_dir, out_dir)
  155. if __name__ == "__main__":
  156. main()