Merge branch 'development' into LogBook_v2
Conflicts: config.py eos/saveddata/fit.py gui/bitmapLoader.py gui/graphFrame.py gui/utils/exportHtml.py pyfa.py service/crest.py service/price.py service/server.py
This commit is contained in:
@@ -168,19 +168,23 @@ class Crest(object):
|
||||
self.stopServer()
|
||||
time.sleep(1)
|
||||
# we need this to ensure that the previous get_request finishes, and then the socket will close
|
||||
self.httpd = StoppableHTTPServer(('', 6461), AuthHandler)
|
||||
thread.start_new_thread(self.httpd.serve, (self.handleLogin,))
|
||||
self.httpd = StoppableHTTPServer(('localhost', 6461), AuthHandler)
|
||||
|
||||
self.serverThread = threading.Thread(target=self.httpd.serve, args=(self.handleLogin,))
|
||||
self.serverThread.name = "CRESTServer"
|
||||
self.serverThread.daemon = True
|
||||
self.serverThread.start()
|
||||
|
||||
self.state = str(uuid.uuid4())
|
||||
return self.eve.auth_uri(scopes=self.scopes, state=self.state)
|
||||
|
||||
def handleLogin(self, message):
|
||||
if not message:
|
||||
return
|
||||
raise Exception("Could not parse out querystring parameters.")
|
||||
|
||||
if message['state'][0] != self.state:
|
||||
pyfalog.warn("OAUTH state mismatch")
|
||||
return
|
||||
raise Exception("OAUTH State Mismatch.")
|
||||
|
||||
pyfalog.debug("Handling CREST login with: {0}", message)
|
||||
|
||||
@@ -222,5 +226,3 @@ class Crest(object):
|
||||
eos.db.save(char)
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.SsoLogin(type=CrestModes.USER))
|
||||
|
||||
self.stopServer()
|
||||
|
||||
@@ -728,7 +728,13 @@ class Fit(object):
|
||||
fit.drones.remove(d1)
|
||||
|
||||
d2.amount += d1.amount
|
||||
d2.amountActive += d1.amountActive if d1.amountActive > 0 else -d2.amountActive
|
||||
d2.amountActive += d1.amountActive
|
||||
|
||||
# If we have less than the total number of drones active, make them all active. Fixes #728
|
||||
# This could be removed if we ever add an enhancement to make drone stacks partially active.
|
||||
if d2.amount > d2.amountActive:
|
||||
d2.amountActive = d2.amount
|
||||
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
return True
|
||||
@@ -943,21 +949,27 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
|
||||
def toggleModulesState(self, fitID, base, modules, click):
|
||||
changed = False
|
||||
proposedState = self.__getProposedState(base, click)
|
||||
|
||||
if proposedState != base.state:
|
||||
changed = True
|
||||
base.state = proposedState
|
||||
for mod in modules:
|
||||
if mod != base:
|
||||
mod.state = self.__getProposedState(mod, click,
|
||||
proposedState)
|
||||
p = self.__getProposedState(mod, click, proposedState)
|
||||
mod.state = p
|
||||
if p != mod.state:
|
||||
changed = True
|
||||
|
||||
eos.db.commit()
|
||||
fit = eos.db.getFit(fitID)
|
||||
if changed:
|
||||
eos.db.commit()
|
||||
fit = eos.db.getFit(fitID)
|
||||
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
self.recalc(fit)
|
||||
# Then, check states of all modules and change where needed. This will recalc if needed
|
||||
self.checkStates(fit, base)
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
self.recalc(fit)
|
||||
# Then, check states of all modules and change where needed. This will recalc if needed
|
||||
self.checkStates(fit, base)
|
||||
|
||||
# Old state : New State
|
||||
localMap = {
|
||||
|
||||
@@ -25,6 +25,7 @@ from eos import db
|
||||
from service.network import Network, TimeoutError
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
from service.fit import Fit
|
||||
|
||||
VALIDITY = 24 * 60 * 60 # Price validity period, 24 hours
|
||||
REREQUEST = 4 * 60 * 60 # Re-request delay for failed fetches, 4 hours
|
||||
@@ -40,8 +41,6 @@ class Price(object):
|
||||
"Hek": 30002053
|
||||
}
|
||||
|
||||
currentSystemId = ""
|
||||
|
||||
@classmethod
|
||||
def invalidPrices(cls, prices):
|
||||
for price in prices:
|
||||
@@ -80,9 +79,10 @@ class Price(object):
|
||||
# This will store POST data for eve-central
|
||||
data = []
|
||||
|
||||
sFit = Fit.getInstance()
|
||||
# Base request URL
|
||||
baseurl = "https://eve-central.com/api/marketstat"
|
||||
data.append(("usesystem", Price.currentSystemId)) # Use Jita for market
|
||||
data.append(("usesystem", cls.systemsList[sFit.serviceFittingOptions["priceSystem"]])) # Use Jita for market
|
||||
|
||||
for typeID in toRequest: # Add all typeID arguments
|
||||
data.append(("typeid", typeID))
|
||||
@@ -143,15 +143,12 @@ class Price(object):
|
||||
typeIDs.append(mod.itemID)
|
||||
|
||||
for drone in fit.drones:
|
||||
for _ in xrange(drone.amount):
|
||||
typeIDs.append(drone.itemID)
|
||||
typeIDs.append(drone.itemID)
|
||||
|
||||
for fighter in fit.fighters:
|
||||
for _ in xrange(fighter.amountActive):
|
||||
typeIDs.append(fighter.itemID)
|
||||
typeIDs.append(fighter.itemID)
|
||||
|
||||
for cargo in fit.cargo:
|
||||
for _ in xrange(cargo.amount):
|
||||
typeIDs.append(cargo.itemID)
|
||||
typeIDs.append(cargo.itemID)
|
||||
|
||||
return typeIDs
|
||||
|
||||
@@ -43,7 +43,7 @@ class FileCache(APICache):
|
||||
os.mkdir(self.path, 0o700)
|
||||
|
||||
def _getpath(self, key):
|
||||
return config.parsePath(self.path, str(hash(key)) + '.cache')
|
||||
return os.path.join(self.path, str(hash(key)) + '.cache')
|
||||
|
||||
def put(self, key, value):
|
||||
with open(self._getpath(key), 'wb') as f:
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import BaseHTTPServer
|
||||
import urlparse
|
||||
import socket
|
||||
import thread
|
||||
import threading
|
||||
from logbook import Logger
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
from service.settings import CRESTSettings
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -19,12 +16,13 @@ HTML = '''
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
<title>pyfa Local Server</title>
|
||||
<style type="text/css">
|
||||
body { text-align: center; padding: 150px; }
|
||||
h1 { font-size: 40px; }
|
||||
body { font: 20px Helvetica, sans-serif; color: #333; }
|
||||
#article { display: block; text-align: left; width: 650px; margin: 0 auto; }
|
||||
a { color: #dc8100; text-decoration: none; }
|
||||
a:hover { color: #333; text-decoration: none; }
|
||||
body {{ text-align: center; padding: 150px; }}
|
||||
h1 {{ font-size: 40px; }}
|
||||
h2 {{ font-size: 32px; }}
|
||||
body {{ font: 20px Helvetica, sans-serif; color: #333; }}
|
||||
#article {{ display: block; text-align: left; width: 650px; margin: 0 auto; }}
|
||||
a {{ color: #dc8100; text-decoration: none; }}
|
||||
a:hover {{ color: #333; text-decoration: none; }}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -33,26 +31,36 @@ HTML = '''
|
||||
<!-- Layout from Short Circuit's CREST login. Shout out! https://github.com/farshield/shortcircuit -->
|
||||
<div id="article">
|
||||
<h1>pyfa</h1>
|
||||
<div>
|
||||
<p>If you see this message then it means you should be logged into CREST. You may close this window and return to the application.</p>
|
||||
</div>
|
||||
{0}
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function extractFromHash(name, hash) {
|
||||
function extractFromHash(name, hash) {{
|
||||
var match = hash.match(new RegExp(name + "=([^&]+)"));
|
||||
return !!match && match[1];
|
||||
}
|
||||
}}
|
||||
|
||||
var hash = window.location.hash;
|
||||
var token = extractFromHash("access_token", hash);
|
||||
var step2 = extractFromHash("step2", hash);
|
||||
|
||||
if (token){
|
||||
var redirect = window.location.origin.concat('/?', window.location.hash.substr(1));
|
||||
window.location = redirect;
|
||||
}
|
||||
else {
|
||||
console.log("do nothing");
|
||||
}
|
||||
function doRedirect() {{
|
||||
if (token){{
|
||||
// implicit authentication
|
||||
var redirect = window.location.origin.concat('/?', window.location.hash.substr(1), '&step=2');
|
||||
window.location = redirect;
|
||||
}}
|
||||
else {{
|
||||
// user-defined
|
||||
var redirect = window.location.href + '&step=2';
|
||||
window.location = redirect;
|
||||
}}
|
||||
}}
|
||||
|
||||
// do redirect if we are not already on step 2
|
||||
if (window.location.href.indexOf('step=2') == -1) {{
|
||||
setTimeout(doRedirect(), 1000);
|
||||
}}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -64,13 +72,30 @@ class AuthHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path == "/favicon.ico":
|
||||
return
|
||||
|
||||
parsed_path = urlparse.urlparse(self.path)
|
||||
parts = urlparse.parse_qs(parsed_path.query)
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(HTML)
|
||||
msg = ""
|
||||
|
||||
wx.CallAfter(self.server.callback, parts)
|
||||
step2 = 'step' in parts
|
||||
|
||||
try:
|
||||
if step2:
|
||||
self.server.callback(parts)
|
||||
msg = "If you see this message then it means you should be logged into CREST. You may close this window and return to the application."
|
||||
else:
|
||||
# For implicit mode, we have to serve up the page which will take the hash and redirect useing a querystring
|
||||
msg = "Processing response from EVE Online"
|
||||
except Exception, ex:
|
||||
msg = "<h2>Error</h2>\n<p>{}</p>".format(ex.message)
|
||||
finally:
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(HTML.format(msg))
|
||||
|
||||
if step2:
|
||||
# Only stop once if we've received something in the querystring
|
||||
self.server.stop()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
return
|
||||
@@ -86,7 +111,7 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
|
||||
sec = self.settings.get('timeout')
|
||||
pyfalog.debug("Running server for {0} seconds", sec)
|
||||
|
||||
self.socket.settimeout(0.5)
|
||||
self.socket.settimeout(1)
|
||||
self.max_tries = sec / self.socket.gettimeout()
|
||||
self.tries = 0
|
||||
self.run = True
|
||||
@@ -111,7 +136,7 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
|
||||
pyfalog.debug("Server timed out waiting for connection")
|
||||
self.stop()
|
||||
|
||||
def serve(self, callback):
|
||||
def serve(self, callback=None):
|
||||
self.callback = callback
|
||||
while self.run:
|
||||
try:
|
||||
@@ -119,11 +144,12 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
|
||||
except TypeError:
|
||||
pyfalog.debug("Caught exception in serve")
|
||||
pass
|
||||
|
||||
self.server_close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
httpd = StoppableHTTPServer(('', 6461), AuthHandler)
|
||||
thread.start_new_thread(httpd.serve, ())
|
||||
t = threading.Thread(target=httpd.serve)
|
||||
raw_input("Press <RETURN> to stop server\n")
|
||||
httpd.stop()
|
||||
|
||||
@@ -25,7 +25,7 @@ import config
|
||||
|
||||
|
||||
class SettingsProvider(object):
|
||||
BASE_PATH = config.getSavePath("settings")
|
||||
BASE_PATH = os.path.join(config.savePath, 'settings')
|
||||
settings = {}
|
||||
_instance = None
|
||||
|
||||
@@ -44,7 +44,7 @@ class SettingsProvider(object):
|
||||
|
||||
s = self.settings.get(area)
|
||||
if s is None:
|
||||
p = config.parsePath(self.BASE_PATH, area)
|
||||
p = os.path.join(self.BASE_PATH, area)
|
||||
|
||||
if not os.path.exists(p):
|
||||
info = {}
|
||||
|
||||
Reference in New Issue
Block a user