Fix non ascii chars in the html export causing a crash
This commit is contained in:
@@ -10,10 +10,10 @@ class exportHtml():
|
||||
cls._instance = exportHtml()
|
||||
|
||||
return cls._instance
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.thread = exportHtmlThread()
|
||||
|
||||
|
||||
def refreshFittingHTMl(self):
|
||||
settings = service.settings.HTMLExportSettings.getInstance()
|
||||
|
||||
@@ -23,73 +23,73 @@ class exportHtml():
|
||||
self.thread.start()
|
||||
|
||||
class exportHtmlThread(threading.Thread):
|
||||
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
self.stopRunning = False
|
||||
|
||||
def stop(self):
|
||||
self.stopRunning = True
|
||||
|
||||
|
||||
def run(self):
|
||||
# wait 1 second just in case a lot of modifications get made
|
||||
time.sleep(1);
|
||||
if self.stopRunning:
|
||||
if self.stopRunning:
|
||||
return;
|
||||
|
||||
sMarket = service.Market.getInstance()
|
||||
sFit = service.Fit.getInstance()
|
||||
settings = service.settings.HTMLExportSettings.getInstance()
|
||||
|
||||
|
||||
HTML = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My Page</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My Page</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
|
||||
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
|
||||
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
|
||||
</head>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas" data-role="page">
|
||||
<div id="canvas" data-role="page">
|
||||
<div data-role="header">
|
||||
<h1>PyFa fits</h1>
|
||||
</div>
|
||||
<div data-role="content">
|
||||
"""
|
||||
|
||||
<div data-role="content">
|
||||
"""
|
||||
|
||||
HTML += '<ul data-role="listview" data-inset="true" data-filter="true">';
|
||||
categoryList = [];
|
||||
self.categoryList = list(sMarket.getShipRoot())
|
||||
self.categoryList.sort(key=lambda ship: ship.name)
|
||||
for shipType in self.categoryList:
|
||||
ships = sMarket.getShipList(shipType.ID)
|
||||
for ship in ships:
|
||||
HTMLship = '<li><h2>' + ship.name + '</h2><ul>'
|
||||
fits = sFit.getFitsWithShip(ship.ID)
|
||||
for fit in fits:
|
||||
if self.stopRunning:
|
||||
return;
|
||||
dnaFit = sFit.exportDna(fit[0])
|
||||
HTMLship += "<li><a href=\"javascript:CCPEVE.showFitting('" + dnaFit + "');\" >" + fit[1] + "</a></li>"
|
||||
ships = sMarket.getShipList(shipType.ID)
|
||||
for ship in ships:
|
||||
HTMLship = '<li><h2>' + ship.name + '</h2><ul>'
|
||||
fits = sFit.getFitsWithShip(ship.ID)
|
||||
for fit in fits:
|
||||
if self.stopRunning:
|
||||
return;
|
||||
dnaFit = sFit.exportDna(fit[0])
|
||||
HTMLship += "<li><a href=\"javascript:CCPEVE.showFitting('" + dnaFit + "');\" >" + fit[1] + "</a></li>"
|
||||
|
||||
HTMLship += "</ul></li>"
|
||||
if len(fits) > 0:
|
||||
HTML += HTMLship
|
||||
HTMLship += "</ul></li>"
|
||||
if len(fits) > 0:
|
||||
HTML += HTMLship
|
||||
|
||||
HTML += """
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
FILE = open(settings.getPath(), "w")
|
||||
FILE.write(HTML);
|
||||
FILE.write(HTML.encode('utf-8'));
|
||||
FILE.close();
|
||||
except IOError:
|
||||
print "Failed to write to " + settings.getPath()
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user