Implement new network service for: Updates, CREST.
This commit is contained in:
@@ -1 +1 @@
|
||||
__all__ = ["pyfaGeneralPreferences","pyfaHTMLExportPreferences","pyfaUpdatePreferences","pyfaProxyPreferences"]
|
||||
__all__ = ["pyfaGeneralPreferences","pyfaHTMLExportPreferences","pyfaUpdatePreferences","pyfaNetworkPreferences"]
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import wx
|
||||
import service
|
||||
import urllib2
|
||||
|
||||
from gui.preferenceView import PreferenceView
|
||||
from gui import bitmapLoader
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import wx
|
||||
import service
|
||||
import urllib2
|
||||
import os
|
||||
|
||||
from gui.preferenceView import PreferenceView
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
import wx
|
||||
import service
|
||||
import urllib2
|
||||
|
||||
from gui.preferenceView import PreferenceView
|
||||
from gui import bitmapLoader
|
||||
|
||||
import gui.mainFrame
|
||||
import service
|
||||
import gui.globalEvents as GE
|
||||
|
||||
|
||||
class PFProxyPref ( PreferenceView):
|
||||
title = "Proxy"
|
||||
class PFNetworkPref ( PreferenceView):
|
||||
title = "Network"
|
||||
|
||||
def populatePanel( self, panel ):
|
||||
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.proxySettings = service.settings.ProxySettings.getInstance()
|
||||
self.networkSettings = service.settings.NetworkSettings.getInstance()
|
||||
self.dirtySettings = False
|
||||
|
||||
self.nMode = self.proxySettings.getMode()
|
||||
self.nAddr = self.proxySettings.getAddress()
|
||||
self.nPort = self.proxySettings.getPort()
|
||||
self.nType = self.proxySettings.getType()
|
||||
self.nMode = self.networkSettings.getMode()
|
||||
self.nAddr = self.networkSettings.getAddress()
|
||||
self.nPort = self.networkSettings.getPort()
|
||||
self.nType = self.networkSettings.getType()
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
@@ -89,7 +85,7 @@ class PFProxyPref ( PreferenceView):
|
||||
|
||||
mainSizer.Add(btnSizer, 0, wx.EXPAND,5)
|
||||
|
||||
proxy = self.proxySettings.autodetect()
|
||||
proxy = self.networkSettings.autodetect()
|
||||
|
||||
if proxy is not None:
|
||||
addr,port = proxy
|
||||
@@ -133,10 +129,10 @@ class PFProxyPref ( PreferenceView):
|
||||
self.SaveSettings()
|
||||
|
||||
def SaveSettings(self):
|
||||
self.proxySettings.setMode(self.nMode)
|
||||
self.proxySettings.setAddress(self.nAddr)
|
||||
self.proxySettings.setPort(self.nPort)
|
||||
self.proxySettings.setType(self.nType)
|
||||
self.networkSettings.setMode(self.nMode)
|
||||
self.networkSettings.setAddress(self.nAddr)
|
||||
self.networkSettings.setPort(self.nPort)
|
||||
self.networkSettings.setType(self.nType)
|
||||
|
||||
def UpdateApplyButtonState(self):
|
||||
if self.dirtySettings:
|
||||
@@ -172,4 +168,4 @@ class PFProxyPref ( PreferenceView):
|
||||
def getImage(self):
|
||||
return bitmapLoader.getBitmap("prefs_proxy", "icons")
|
||||
|
||||
PFProxyPref.register()
|
||||
PFNetworkPref.register()
|
||||
@@ -6,3 +6,5 @@ from service.damagePattern import DamagePattern
|
||||
from service.settings import SettingsProvider
|
||||
from service.fleet import Fleet
|
||||
from service.update import Update
|
||||
from service.network import Network
|
||||
from service.eveapi import EVEAPIConnection, ParseXML
|
||||
|
||||
@@ -25,7 +25,7 @@ import Queue
|
||||
|
||||
import eos.db
|
||||
import eos.types
|
||||
from service.settings import SettingsProvider, ProxySettings
|
||||
from service.settings import SettingsProvider, NetworkSettings
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
@@ -78,7 +78,7 @@ class PriceWorkerThread(threading.Thread):
|
||||
|
||||
# Grab prices, this is the time-consuming part
|
||||
if len(requests) > 0:
|
||||
proxy = ProxySettings.getInstance().getProxySettings()
|
||||
proxy = NetworkSettings.getInstance().getProxySettings()
|
||||
if proxy is not None:
|
||||
proxy = "{0}:{1}".format(*proxy)
|
||||
eos.types.Price.fetchPrices(requests, proxy=proxy)
|
||||
|
||||
67
service/network.py
Normal file
67
service/network.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#===============================================================================
|
||||
# Copyright (C) 2014 Ryan Holmes
|
||||
#
|
||||
# This file is part of pyfa.
|
||||
#
|
||||
# pyfa is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# pyfa is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
|
||||
#===============================================================================
|
||||
|
||||
from service.settings import NetworkSettings
|
||||
import urllib2
|
||||
import urllib
|
||||
import config
|
||||
|
||||
class Network():
|
||||
# Request constants - every request must supply this, as it is checked if
|
||||
# enabled or not via settings
|
||||
ENABLED = 1
|
||||
EVE = 2 # Mostly API, but also covers CREST requests
|
||||
PRICES = 4
|
||||
UPDATE = 8
|
||||
|
||||
_instance = None
|
||||
@classmethod
|
||||
def getInstance(cls):
|
||||
if cls._instance == None:
|
||||
cls._instance = Network()
|
||||
|
||||
return cls._instance
|
||||
|
||||
def request(self, url, type=None, postData=None):
|
||||
|
||||
# URL is required to be https as of right now
|
||||
print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,postData)
|
||||
|
||||
# Make sure request is enabled
|
||||
access = NetworkSettings.getInstance().getAccess()
|
||||
|
||||
if not type or not type & access: # @todo: check if enabled
|
||||
print "\tType not enabled"
|
||||
return # @todo: throw exception
|
||||
|
||||
# Set up some things for the request
|
||||
versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion)
|
||||
headers={"User-Agent" : "pyfa {0} (Python-urllib2)".format(versionString)}
|
||||
|
||||
proxy = NetworkSettings.getInstance().getProxySettings()
|
||||
if proxy is not None:
|
||||
print "\tUsing a proxy"
|
||||
proxy = urllib2.ProxyHandler({'https': "{0}:{1}".format(*proxy)})
|
||||
opener = urllib2.build_opener(proxy)
|
||||
urllib2.install_opener(opener)
|
||||
|
||||
request = urllib2.Request(url, headers=headers, data=urllib.urlencode(postData) if postData else None)
|
||||
data = urllib2.urlopen(request)
|
||||
print "\tReturning data"
|
||||
return data
|
||||
@@ -1,5 +1,5 @@
|
||||
#===============================================================================
|
||||
# Copyright (C) 2010 Diego Duclos
|
||||
# Copyright (C) 2014 Ryan Holmes
|
||||
#
|
||||
# This file is part of pyfa.
|
||||
#
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
import re
|
||||
import xml.dom
|
||||
import urllib2
|
||||
import json
|
||||
|
||||
from eos.types import State, Slot, Module, Cargo, Fit, Ship, Drone, Implant, Booster
|
||||
@@ -166,9 +165,9 @@ class Port(object):
|
||||
@staticmethod
|
||||
def importCrest(info):
|
||||
sMkt = service.Market.getInstance()
|
||||
network = service.Network.getInstance()
|
||||
try:
|
||||
# @todo: proxy
|
||||
response = urllib2.urlopen("https://public-crest.eveonline.com/killmails/%s/%s/" % info)
|
||||
response = network.request("https://public-crest.eveonline.com/killmails/%s/%s/" % info, network.EVE)
|
||||
except:
|
||||
return
|
||||
|
||||
@@ -638,7 +637,7 @@ class Port(object):
|
||||
|
||||
for subsystem in sorted(subsystems, key=lambda mod: mod.getModifiedItemAttr("subSystemSlot")):
|
||||
dna += ":{0};1".format(subsystem.itemID)
|
||||
|
||||
|
||||
for drone in fit.drones:
|
||||
dna += ":{0};{1}".format(drone.itemID, drone.amount)
|
||||
|
||||
@@ -688,10 +687,10 @@ class Port(object):
|
||||
else:
|
||||
if not slot in slotNum:
|
||||
slotNum[slot] = 0
|
||||
|
||||
|
||||
slotId = slotNum[slot]
|
||||
slotNum[slot] += 1
|
||||
|
||||
|
||||
hardware = doc.createElement("hardware")
|
||||
hardware.setAttribute("type", module.item.name)
|
||||
slotName = Slot.getName(slot).lower()
|
||||
|
||||
@@ -111,13 +111,12 @@ class Settings():
|
||||
return self.info.items()
|
||||
|
||||
|
||||
|
||||
class ProxySettings():
|
||||
class NetworkSettings():
|
||||
_instance = None
|
||||
@classmethod
|
||||
def getInstance(cls):
|
||||
if cls._instance == None:
|
||||
cls._instance = ProxySettings()
|
||||
cls._instance = NetworkSettings()
|
||||
|
||||
return cls._instance
|
||||
|
||||
@@ -127,33 +126,39 @@ class ProxySettings():
|
||||
# 0 - No proxy
|
||||
# 1 - Auto-detected proxy settings
|
||||
# 2 - Manual proxy settings
|
||||
serviceProxyDefaultSettings = {"mode": 1, "type": "https", "address": "", "port": ""}
|
||||
serviceNetworkDefaultSettings = {"mode": 1, "type": "https", "address": "", "port": "", "access": 15}
|
||||
|
||||
self.serviceProxySettings = SettingsProvider.getInstance().getSettings("pyfaServiceProxySettings", serviceProxyDefaultSettings)
|
||||
self.serviceNetworkSettings = SettingsProvider.getInstance().getSettings("pyfaServiceNetworkSettings", serviceNetworkDefaultSettings)
|
||||
|
||||
def getMode(self):
|
||||
return self.serviceProxySettings["mode"]
|
||||
return self.serviceNetworkSettings["mode"]
|
||||
|
||||
def getAddress(self):
|
||||
return self.serviceProxySettings["address"]
|
||||
return self.serviceNetworkSettings["address"]
|
||||
|
||||
def getPort(self):
|
||||
return self.serviceProxySettings["port"]
|
||||
return self.serviceNetworkSettings["port"]
|
||||
|
||||
def getType(self):
|
||||
return self.serviceProxySettings["type"]
|
||||
return self.serviceNetworkSettings["type"]
|
||||
|
||||
def getAccess(self):
|
||||
return self.serviceNetworkSettings["access"]
|
||||
|
||||
def setMode(self, mode):
|
||||
self.serviceProxySettings["mode"] = mode
|
||||
self.serviceNetworkSettings["mode"] = mode
|
||||
|
||||
def setAddress(self, addr):
|
||||
self.serviceProxySettings["address"] = addr
|
||||
self.serviceNetworkSettings["address"] = addr
|
||||
|
||||
def setPort(self, port):
|
||||
self.serviceProxySettings["port"] = port
|
||||
self.serviceNetworkSettings["port"] = port
|
||||
|
||||
def setType(self, type):
|
||||
self.serviceProxySettings["type"] = type
|
||||
self.serviceNetworkSettings["type"] = type
|
||||
|
||||
def setAccess(self, access):
|
||||
self.serviceNetworkSettings["access"] = access
|
||||
|
||||
def autodetect(self):
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#===============================================================================
|
||||
# Copyright (C) 2010 Diego Duclos
|
||||
# Copyright (C) 2014 Ryan Holmes
|
||||
#
|
||||
# This file is part of pyfa.
|
||||
#
|
||||
@@ -29,16 +29,19 @@ class CheckUpdateThread(threading.Thread):
|
||||
threading.Thread.__init__(self)
|
||||
self.callback = callback
|
||||
self.settings = service.settings.UpdateSettings.getInstance()
|
||||
self.network = service.Network.getInstance()
|
||||
|
||||
def run(self):
|
||||
# Suppress all
|
||||
if (self.settings.get('all')):
|
||||
return
|
||||
|
||||
network = service.Network.getInstance()
|
||||
|
||||
try:
|
||||
# @todo: use proxy settings?
|
||||
response = urllib2.urlopen('https://api.github.com/repos/DarkFenX/Pyfa/releases')
|
||||
jsonResponse = json.loads(response.read());
|
||||
response = network.request('https://api.github.com/repos/DarkFenX/Pyfa/releases', network.UPDATE)
|
||||
jsonResponse = json.loads(response.read())
|
||||
|
||||
for release in jsonResponse:
|
||||
# Suppress pre releases
|
||||
@@ -69,7 +72,7 @@ class CheckUpdateThread(threading.Thread):
|
||||
else:
|
||||
if release['prerelease'] and rVersion > config.expansionVersion:
|
||||
wx.CallAfter(self.callback, release) # Singularity -> Singularity
|
||||
break;
|
||||
break
|
||||
except: # for when there is no internet connection
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user