1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/usr/bin/python
#
# Strain Analyser
# Copyright (C) 2009-2010 Malcolm Scott <Malcolm.Scott@cl.cam.ac.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from optparse import OptionParser
from strainanalyser import gtkcrashhandler
gtkcrashhandler.initialize(app_name="Strain Analyser")
parser = OptionParser()
parser.add_option("-l", "--livecoding",
dest="livecoding", action="store_true", default=False,
help="use livecoding module to aid code editing and debugging")
(options, args) = parser.parse_args()
if options.livecoding:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("strainanalyser")
logger.warning("loading livecoding in strainanalyser/")
from livecoding import reloader
import sys, os
# don't want to accidentally import strainanalyser directly, rather than through livecoding!
sys.path.remove(os.getcwd())
logger.debug("sys.path = %s" % sys.path)
cr = reloader.CodeReloader()
# livecoding defaults to putting all files' contents in the same module,
# rather than Python's default of one-module-per-file; override this to
# match Python's default to avoid having two sets of import statements
class MyReloadableScriptFile(reloader.ReloadableScriptFile):
def __init__(self, filePath, namespacePath, implicitLoad=True):
# ignore whatever namespace livecoding has come up with; figure it out ourselves
# (and assume that namespace = path...)
myNamespace = os.path.splitext(filePath)[0].replace(os.sep, ".")
super(MyReloadableScriptFile, self).__init__(filePath, myNamespace, implicitLoad)
def Run(self):
# also it misses out magic globals...
self.scriptGlobals = {"__file__": self.filePath}
# the following code copied from namespace.ScriptFile.Run...
try:
eval(self.codeObject, self.scriptGlobals, self.scriptGlobals)
except (ImportError, AttributeError):
import sys, traceback
self.lastError = traceback.format_exception(*sys.exc_info())
return False
return True
class MyReloadableScriptDirectory(reloader.ReloadableScriptDirectory):
scriptFileClass = MyReloadableScriptFile
def SetModuleAttributes(self, scriptFile, namespace, overwritableAttributes=set()):
# the code already sets __file__ but too late, and then complains about the one I added above!
# => allow my one to override the default one
overwritableAttributes.add("__file__")
super(MyReloadableScriptDirectory, self).SetModuleAttributes(scriptFile, namespace, overwritableAttributes)
cr.scriptDirectoryClass = MyReloadableScriptDirectory
cr.AddDirectory("strainanalyser", "strainanalyser")
from strainanalyser.datasetdiff import run
run()
|