From 7294d2e5c0be4d111f2d11fc309b1646f552d15a Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Mon, 8 Feb 2010 22:43:15 +0000 Subject: [PATCH 1/6] make sure log dir is created, refine py2exe operation --- pyfpdb/Configuration.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index ec4c621e..45b767eb 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) @@ -105,26 +105,31 @@ def get_config(file_name, fallback = True): sys.exit() return (file_name,True) -def get_logger(file_name, config = "config", fallback = False, log_dir=None): +def get_logger(file_name, module = "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}) - log = logging.getLogger(config) - log.debug("%s logger initialised" % config) + log = logging.getLogger(module) + log.debug("%s logger initialised" % module) return log 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): From 333ae224d456d7fcbb6602b5ef2cd1e746238316 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Mon, 8 Feb 2010 23:02:08 +0000 Subject: [PATCH 2/6] add some comments --- pyfpdb/py2exe_setup.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pyfpdb/py2exe_setup.py b/pyfpdb/py2exe_setup.py index 28f13cc1..191fd907 100644 --- a/pyfpdb/py2exe_setup.py +++ b/pyfpdb/py2exe_setup.py @@ -48,6 +48,23 @@ Py2exe script for fpdb. #- 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 From 6df8bddc620a338d548852097477a8e200ffa122 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Mon, 8 Feb 2010 23:38:18 +0000 Subject: [PATCH 3/6] undo stupid param name change (need to change all the calls as well if doing it) --- pyfpdb/Configuration.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 45b767eb..143fb72b 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -105,7 +105,7 @@ def get_config(file_name, fallback = True): sys.exit() return (file_name,True) -def get_logger(file_name, module = "config", fallback = False, log_dir=None): +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: @@ -119,8 +119,8 @@ def get_logger(file_name, module = "config", fallback = False, log_dir=None): file = file.replace('\\', '\\\\') # replace each \ with \\ # print " ="+file+" "+ str(type(file))+" len="+str(len(file))+"\n" logging.config.fileConfig(conf_file, {"logFile":file}) - log = logging.getLogger(module) - log.debug("%s logger initialised" % module) + log = logging.getLogger(config) + log.debug("%s logger initialised" % config) return log except: pass From d3cb41bed1e6a33ced7e4f18fc25fb9dd0fe5636 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 9 Feb 2010 09:14:36 +0000 Subject: [PATCH 4/6] do rename to pyfpdb, user still needs to move it into fpdb-0.12... dir manually --- pyfpdb/py2exe_setup.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyfpdb/py2exe_setup.py b/pyfpdb/py2exe_setup.py index 191fd907..cc3d5435 100644 --- a/pyfpdb/py2exe_setup.py +++ b/pyfpdb/py2exe_setup.py @@ -105,7 +105,7 @@ 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_dir = r'..\fpdb-' + xxx + '-' + today + '-exe' @@ -126,7 +126,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'], } @@ -142,7 +142,9 @@ 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' + r'If py2exe was successful move the \pyfpdb\ directory ' +print 'into \\'+dist_dir +print "Then add the \\etc \\lib and \\share dirs from your gtk dir to \\pyfpdb\\\n" From 4e89b1b0009e0b5d5151c6a4fbae8d934e7024f9 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 9 Feb 2010 22:54:04 +0000 Subject: [PATCH 5/6] more py2exe refinements --- pyfpdb/py2exe_setup.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/pyfpdb/py2exe_setup.py b/pyfpdb/py2exe_setup.py index cc3d5435..2e9c894d 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,11 +39,13 @@ 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. @@ -74,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. @@ -108,9 +118,11 @@ today = date.today().strftime('%Y%m%d') 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', @@ -144,7 +156,15 @@ setup( os.rename('dist', 'pyfpdb') -print '\n' + r'If py2exe was successful move the \pyfpdb\ directory ' -print 'into \\'+dist_dir -print "Then add the \\etc \\lib and \\share dirs from your gtk dir to \\pyfpdb\\\n" +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 ) + From 965adc7b2760747368ae05236ad07fcc9f2e56ef Mon Sep 17 00:00:00 2001 From: Eratosthenes Date: Tue, 9 Feb 2010 18:51:37 -0500 Subject: [PATCH 6/6] Add EXEC_PATH to constants. --- pyfpdb/Configuration.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index ec4c621e..c3c93293 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -166,6 +166,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 +617,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 +1038,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()