diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index ec4c621e..7b026f0c 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -65,7 +65,7 @@ def get_exec_path(): def get_config(file_name, fallback = True): """Looks in cwd and in self.default_config_path for a config file.""" exec_dir = get_exec_path() - if file_name == 'logging.conf': + if file_name == 'logging.conf' and sys.argv[0] != 'fpdb.exe': config_path = os.path.join(exec_dir, 'pyfpdb', file_name) else: config_path = os.path.join(exec_dir, file_name) @@ -107,12 +107,15 @@ def get_config(file_name, fallback = True): def get_logger(file_name, config = "config", fallback = False, log_dir=None): (conf_file,copied) = get_config(file_name, fallback = fallback) + + if log_dir is None: + log_dir = os.path.join(get_exec_path(), 'log') + #print "\nget_logger: checking log_dir:", log_dir + check_dir(log_dir) + file = os.path.join(log_dir, 'logging.out') + if conf_file: try: - if log_dir is None: - log_dir = os.path.join(get_exec_path(), 'log') - check_dir(log_dir) - file = os.path.join(log_dir, 'logging.out') file = file.replace('\\', '\\\\') # replace each \ with \\ # print " ="+file+" "+ str(type(file))+" len="+str(len(file))+"\n" logging.config.fileConfig(conf_file, {"logFile":file}) @@ -122,9 +125,11 @@ def get_logger(file_name, config = "config", fallback = False, log_dir=None): except: pass - log = logging.basicConfig() + log = logging.basicConfig(filename=file, level=logging.INFO) log = logging.getLogger() - log.debug("config logger initialised") + # but it looks like default is no output :-( maybe because all the calls name a module? + log.debug("Default logger initialised for "+file) + print "Default logger intialised for "+file return log def check_dir(path, create = True): @@ -166,6 +171,10 @@ if LOCALE_ENCODING == "US-ASCII": # needs LOCALE_ENCODING (above), imported for sqlite setup in Config class below + +FROZEN = hasattr(sys, "frozen") +EXEC_PATH = get_exec_path() + import Charset @@ -613,7 +622,11 @@ class Config: def save(self, file = None): if file is None: file = self.file - shutil.move(file, file+".backup") + try: + shutil.move(file, file+".backup") + except: + pass + with open(file, 'w') as f: self.doc.writexml(f) @@ -1030,3 +1043,9 @@ if __name__== "__main__": PrettyPrint(site_node, stream=sys.stdout, encoding="utf-8") except: print "xml.dom.ext needs PyXML to be installed!" + + print "FROZEN =", FROZEN + print "EXEC_PATH =", EXEC_PATH + + print "press enter to end" + sys.stdin.readline() diff --git a/pyfpdb/py2exe_setup.py b/pyfpdb/py2exe_setup.py index 671d58a5..32d6d19b 100644 --- a/pyfpdb/py2exe_setup.py +++ b/pyfpdb/py2exe_setup.py @@ -23,11 +23,11 @@ Py2exe script for fpdb. ######################################################################## #TODO: -# include the lib needed to handle png files in mucked # get rid of all the uneeded libraries (e.g., pyQT) # think about an installer -# done: change GuiAutoImport so that it knows to start HUD_main.exe, when appropriate +# done: change GuiAutoImport so that it knows to start HUD_main.exe, when appropriate +# include the lib needed to handle png files in mucked #HOW TO USE this script: # @@ -39,15 +39,34 @@ Py2exe script for fpdb. # MSVCP90.dll. These are somewhere in your windows install, so you # can just copy them to your working folder. (or just assume other # person will have them? any copyright issues with including them?) -#- If it works, you'll have 3 new folders, build and dist and gfx. Build is -# working space and should be deleted. Dist and gfx contain the files to be -# distributed. +#- [ If it works, you'll have 3 new folders, build and dist and gfx. Build is +# working space and should be deleted. Dist and gfx contain the files to be +# distributed. ] +# If it works, you'll have a new dir fpdb-XXX-YYYYMMDD-exe which should +# contain 2 dirs; gfx and pyfpdb and run_fpdb.bat #- Last, you must copy the etc/, lib/ and share/ folders from your -# gtk/bin/ (just /gtk/?) folder to the dist folder. (the whole folders, +# gtk/bin/ (just /gtk/?) folder to the pyfpdb folder. (the whole folders, # not just the contents) #- You can (should) then prune the etc/, lib/ and share/ folders to # remove components we don't need. +# sqlcoder notes: this worked for me with the following notes: +#- I used the following versions: +# python 2.5.4 +# gtk+ 2.14.7 +# pycairo 1.4.12-2 +# pygobject 2.14.2-2 +# pygtk 2.12.1-3 +# matplotlib 0.98.3 +# numpy 1.4.0 +# py2exe-0.6.9 for python 2.5 +# +#- I also copied these dlls manually from /bin to /dist : +# +# libgobject-2.0-0.dll +# libgdk-win32-2.0-0.dll + + import os import sys from distutils.core import setup @@ -57,6 +76,14 @@ import matplotlib from datetime import date +origIsSystemDLL = py2exe.build_exe.isSystemDLL +def isSystemDLL(pathname): + if os.path.basename(pathname).lower() in ("msvcp71.dll", "dwmapi.dll"): + return 0 + return origIsSystemDLL(pathname) +py2exe.build_exe.isSystemDLL = isSystemDLL + + def remove_tree(top): # Delete everything reachable from the directory named in 'top', # assuming there are no symbolic links. @@ -88,12 +115,14 @@ test_and_remove('gfx') today = date.today().strftime('%Y%m%d') -print "\n" + r"Output will be created in \dist\ and \fpdb_XXX_"+today+'\\' +print "\n" + r"Output will be created in \pyfpdb\ and \fpdb_XXX_"+today+'\\' print "Enter value for XXX (any length): ", # the comma means no newline xxx = sys.stdin.readline().rstrip() +dist_dirname = r'fpdb-' + xxx + '-' + today + '-exe' dist_dir = r'..\fpdb-' + xxx + '-' + today + '-exe' print +test_and_remove(dist_dir) setup( name = 'fpdb', @@ -109,7 +138,7 @@ setup( 'packages' : ['encodings', 'matplotlib'], 'includes' : ['cairo', 'pango', 'pangocairo', 'atk', 'gobject' ,'PokerStarsToFpdb', 'matplotlib.numerix.random_array'], - 'excludes' : ['_gtkagg', '_tkagg', '_agg2', 'cocoaagg', 'fltkagg'], + 'excludes' : ['_tkagg', '_agg2', 'cocoaagg', 'fltkagg'], # surely we need this? '_gtkagg' 'dll_excludes': ['libglade-2.0-0.dll', 'libgdk-win32-2.0-0.dll' ,'libgobject-2.0-0.dll'], } @@ -125,7 +154,17 @@ setup( ) -print '\n' + r'If py2exe was successful move the \dist\ directory ' -print 'into \\'+dist_dir+'\\ and rename it as \\pyfpdb\\' -print "Don't forget to add the \\etc \\lib and \\share dirs from your gtk dir\n" +os.rename('dist', 'pyfpdb') + +print '\n' + 'If py2exe was successful add the \\etc \\lib and \\share dirs ' +print 'from your gtk dir to \\%s\\pyfpdb\\\n' % dist_dirname +print 'Also copy libgobject-2.0-0.dll and libgdk-win32-2.0-0.dll from \\bin' +print 'into there' + +dest = os.path.join(dist_dirname, 'pyfpdb') +#print "try renaming pyfpdb to", dest +dest = dest.replace('\\', '\\\\') +#print "dest is now", dest +os.rename( 'pyfpdb', dest ) +