Skip to content

Commit

Permalink
Maddavo plugin now supports system and station deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Mar 2, 2015
1 parent bceffb6 commit 76fc3b8
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions plugins/maddavo_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class ImportPlugin(plugins.ImportPluginBase):
'use3h': "Force download of the 3-hours .prices file",
'use2d': "Force download of the 2-days .prices file",
'usefull': "Force download of the full .prices file",
'syscsv': "DEPRECATED - see --opt=systems",
'stncsv': "DEPRECATED - see --opt=stations",
}


Expand All @@ -65,8 +63,8 @@ def __init__(self, tdb, tdenv):
self.filename = self.defaultImportFile
stampFilePath = pathlib.Path(ImportPlugin.stampFile)
self.stampPath = tdb.dataPath / stampFilePath
self.newSystems = 0
self.newStations = 0
self.modSystems = 0
self.modStations = 0


def load_timestamp(self):
Expand Down Expand Up @@ -193,18 +191,38 @@ def import_systems(self):
stream = transfers.CSVStream(SYSTEMS_URL)
for _, values in stream:
name = values[0].upper()
x, y, z = float(values[1]), float(values[2]), float(values[3])
added, modified = values[4], values[5]
system = systems.get(name, None)

added = values[4]
if added == "DELETED":
if system:
tdb.removeLocalSystem(
system
)
self.modSystems += 1
continue

x, y, z = float(values[1]), float(values[2]), float(values[3])
modified = values[5]
if not system:
tdb.addLocalSystem(name, x, y, z, added, modified)
self.newSystems += 1
tdb.addLocalSystem(
name, x, y, z, added, modified,
commit=False,
)
self.modSystems += 1
elif system.posX != x or system.posY != y or system.posZ != z:
print("{} position change: {}v{}, {}v{}, {}v{}".format(
name, system.posX, x, system.posY, y, system.posZ, z
))
tdb.updateLocalSystem(system, name, x, y, z, added, modified)
self.newSystems += 1
tdb.updateLocalSystem(
system, name, x, y, z, added, modified,
commit=False,
)
self.modSystems += 1

if self.modSystems:
tdenv.DEBUG0("commit")
tdb.getDB().commit()


def import_stations(self):
Expand Down Expand Up @@ -245,6 +263,11 @@ def import_stations(self):
continue
station = system.getStation(stnName)
lsFromStar = int(values[2])
if lsFromStar < 0:
if station:
tdb.removeLocalStation(station, commit=False)
self.modStations += 1
continue
blackMarket = values[3]
maxPadSize = values[4]
market = values[5] if len(values) > 4 else '?'
Expand All @@ -260,8 +283,9 @@ def import_stations(self):
shipyard=shipyard,
maxPadSize=maxPadSize,
modified=modified,
commit=False,
):
self.newStations += 1
self.modStations += 1
else:
tdb.addLocalStation(
system=system,
Expand All @@ -272,8 +296,13 @@ def import_stations(self):
shipyard=shipyard,
maxPadSize=maxPadSize,
modified=modified,
commit=False,
)
self.newStations += 1
self.modStations += 1

if self.modStations:
tdenv.DEBUG0("commit")
tdb.getDB().commit()


def refresh_csv(self):
Expand All @@ -293,24 +322,6 @@ def refresh_csv(self):
def run(self):
tdb, tdenv = self.tdb, self.tdenv

if self.getOption("syscsv") or self.getOption("stncsv"):
raise PluginException(
"\a--opt=syscsv and --opt=stncsv have been REPLACED.\n"
"\n"
"The behavior of the Maddavo plugin has changed drastically "
"in version 6.10.0.\n"
"\n"
"The old options, syscsv and stncsv, would download the "
"corresponding file from Maddavo's and REPLACE your local "
"file with his data.\n"
"\n"
"The new options, --opt=systems and --opt=stations, will "
"read his files and MERGE his data into your local db.\n"
"\n"
"An additional option, --opt=exportcsv, was also added "
"to export the resulting, merged data, to your .csv files."
)

# It takes a while to download these files, so we want
# to record the start time before we download. What we
# care about is when we downloaded relative to when the
Expand Down

0 comments on commit 76fc3b8

Please sign in to comment.