Merge branch 'master' into fleet

This commit is contained in:
blitzmann
2014-03-03 11:20:06 -05:00
10 changed files with 382 additions and 15 deletions

View File

@@ -5,3 +5,4 @@ from service.character import Character
from service.damagePattern import DamagePattern
from service.settings import SettingsProvider
from service.fleet import Fleet
from service.update import Update

View File

@@ -630,10 +630,13 @@ class Market():
def searchShips(self, name):
"""Find ships according to given text pattern"""
results = eos.db.searchItems(name)
filter = eos.types.Category.name.in_(["Ship"])
results = eos.db.searchItems(name, where=filter,
join=(eos.types.Item.group, eos.types.Group.category),
eager=("icon", "group.category", "metaGroup", "metaGroup.parent"))
ships = set()
for item in results:
if self.getCategoryByItem(item).name == "Ship" and self.getPublicityByItem(item):
if self.getPublicityByItem(item):
ships.add(item)
return ships

View File

@@ -38,6 +38,7 @@ class SettingsProvider():
os.mkdir(self.BASE_PATH);
def getSettings(self, area, defaults=None):
s = self.settings.get(area)
if s is None:
p = os.path.join(self.BASE_PATH, area)
@@ -215,4 +216,31 @@ class HTMLExportSettings():
return self.serviceHTMLExportSettings["path"]
def setPath(self, path):
self.serviceHTMLExportSettings["path"] = path
self.serviceHTMLExportSettings["path"] = path
"""
Settings used by update notification
"""
class UpdateSettings():
_instance = None
@classmethod
def getInstance(cls):
if cls._instance == None:
cls._instance = UpdateSettings()
return cls._instance
def __init__(self):
# Settings
# all - If True, suppress all update notifications
# prerelease - If True, suppress only prerelease notifications
# version - Set to release tag that user does not want notifications for
serviceUpdateDefaultSettings = { "all": False, "prerelease": True, 'version': None }
self.serviceUpdateSettings = SettingsProvider.getInstance().getSettings("pyfaServiceUpdateSettings", serviceUpdateDefaultSettings)
def get(self, type):
return self.serviceUpdateSettings[type]
def set(self, type, value):
self.serviceUpdateSettings[type] = value

86
service/update.py Normal file
View File

@@ -0,0 +1,86 @@
#===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# 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/>.
#===============================================================================
import threading
import wx
import urllib2
import json
import config
import service
class CheckUpdateThread(threading.Thread):
def __init__(self, callback):
threading.Thread.__init__(self)
self.callback = callback
self.settings = service.settings.UpdateSettings.getInstance()
def run(self):
# Suppress all
if (self.settings.get('all')):
return
try:
# @todo: use proxy settings?
response = urllib2.urlopen('https://api.github.com/repos/DarkFenX/Pyfa/releases')
jsonResponse = json.loads(response.read());
i = 0
while (True):
release = jsonResponse[i]
# Suppress pre releases
if (release['prerelease'] and self.settings.get('prerelease')):
i += 1
continue
# Handle use-case of updating to suppressed version
if self.settings.get('version') == 'v'+config.version:
self.settings.set('version', None)
# Suppress version
if (release['tag_name'] == self.settings.get('version')):
return
version = release['tag_name'].replace('v', '', 1)
if self.versiontuple(version) > self.versiontuple(config.version):
wx.CallAfter(self.callback, jsonResponse[i])
break;
except: # for when there is no internet connection
pass
def versiontuple(self, v):
return tuple(map(int, (v.split("."))))
class Update():
instance = None
def __init__(self):
pass
def CheckUpdate(self, callback):
thread = CheckUpdateThread(callback)
thread.start()
@classmethod
def getInstance(cls):
if cls.instance == None:
cls.instance = Update()
return cls.instance