From 07a19ac3eb22d1fd9810196d6d280840610c181a Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 29 Nov 2011 19:11:39 +0400 Subject: [PATCH] Add option to store saveddata in pyfa root Useful for these who use folder synchronization tools (e.g. dropbox) --- config.py | 68 +++++++++++++++++++++++++++++++++++-------------------- pyfa.py | 31 +++++++++++++++++-------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/config.py b/config.py index bb3391ba5..f2844b590 100644 --- a/config.py +++ b/config.py @@ -9,6 +9,8 @@ except ImportError: # Turns on debug mode debug = False +# Defines if our saveddata will be in pyfa root or not +saveInRoot = False # Version data version = "1.1" @@ -16,35 +18,51 @@ tag = "git" expansionName = "Crucible" expansionVersion = "1.0" -# You can adjust these paths to your needs +pyfaPath = None +savePath = None +staticPath = None +saveDB = None +gameDB = None -# The main pyfa directory which contains run.py -# Python 2.X uses ANSI by default, so we need to convert the character encoding -pyfaPath = getattr(configforced, "pyfaPath", None) -if pyfaPath is None: - pyfaPath = unicode(os.path.dirname(os.path.abspath(sys.modules['__main__'].__file__)), sys.getfilesystemencoding()) +def defPaths(): + global pyfaPath + global savePath + global staticPath + global saveDB + global gameDB + global saveInRoot + # The main pyfa directory which contains run.py + # Python 2.X uses ANSI by default, so we need to convert the character encoding + pyfaPath = getattr(configforced, "pyfaPath", None) + if pyfaPath is None: + pyfaPath = unicode(os.path.dirname(os.path.abspath(sys.modules['__main__'].__file__)), sys.getfilesystemencoding()) -# Where we store the saved fits etc, default is the current users home directory -savePath = getattr(configforced, "savePath", None) -if savePath is None: - savePath = unicode(os.path.expanduser(os.path.join("~", ".pyfa")), sys.getfilesystemencoding()) + # Where we store the saved fits etc, default is the current users home directory + if saveInRoot is True: + savePath = getattr(configforced, "savePath", None) + if savePath is None: + savePath = os.path.join(pyfaPath, "saveddata") + else: + savePath = getattr(configforced, "savePath", None) + if savePath is None: + savePath = unicode(os.path.expanduser(os.path.join("~", ".pyfa")), sys.getfilesystemencoding()) -# Static EVE Data from the staticdata repository, should be in the staticdata directory in our pyfa directory -staticPath = os.path.join(pyfaPath, "staticdata") + # Static EVE Data from the staticdata repository, should be in the staticdata directory in our pyfa directory + staticPath = os.path.join(pyfaPath, "staticdata") -# The database where we store all the fits etc -saveDB = os.path.join(savePath, "saveddata.db") + # The database where we store all the fits etc + saveDB = os.path.join(savePath, "saveddata.db") -# The database where the static EVE data from the datadump is kept. -# This is not the standard sqlite datadump but a modified version created by eos -# maintenance script -gameDB = os.path.join(staticPath, "eve.db") + # The database where the static EVE data from the datadump is kept. + # This is not the standard sqlite datadump but a modified version created by eos + # maintenance script + gameDB = os.path.join(staticPath, "eve.db") -## DON'T MODIFY ANYTHING BELOW ## -import eos.config + ## DON'T MODIFY ANYTHING BELOW ## + import eos.config -#Caching modifiers, disable all gamedata caching, its unneeded. -eos.config.gamedataCache = False -# saveddata db location modifier, shouldn't ever need to touch this -eos.config.saveddata_connectionstring = "sqlite:///" + saveDB + "?check_same_thread=False" -eos.config.gamedata_connectionstring = "sqlite:///" + gameDB + "?check_same_thread=False" + #Caching modifiers, disable all gamedata caching, its unneeded. + eos.config.gamedataCache = False + # saveddata db location modifier, shouldn't ever need to touch this + eos.config.saveddata_connectionstring = "sqlite:///" + saveDB + "?check_same_thread=False" + eos.config.gamedata_connectionstring = "sqlite:///" + gameDB + "?check_same_thread=False" diff --git a/pyfa.py b/pyfa.py index 22eae09a1..aedb71839 100755 --- a/pyfa.py +++ b/pyfa.py @@ -54,17 +54,30 @@ if not hasattr(sys, 'frozen'): print "Cannot find sqlalchemy.\nYou can download sqlalchemy (0.6+) from http://www.sqlalchemy.org/" sys.exit(1) -import wx -import os -import os.path - -import config -import eos.db -import service.prefetch - -from gui.mainFrame import MainFrame +from optparse import OptionParser if __name__ == "__main__": + # Parse command line options + usage = "usage: %prog [--root]" + parser = OptionParser(usage=usage) + parser.add_option("-r", "--root", action="store_true", dest="rootsavedata", help="if you want pyfa to store its data in root folder, use this option", default=False) + (options, args) = parser.parse_args() + + import config + # Configure paths + if options.rootsavedata is True: + config.saveInRoot = True + config.defPaths() + + # Import everything + import wx + import os + import os.path + + import eos.db + import service.prefetch + from gui.mainFrame import MainFrame + #Make sure the saveddata db exists if not os.path.exists(config.savePath): os.mkdir(config.savePath)