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