~fluidity-core/fluidity/embedded_models

« back to all changes in this revision

Viewing changes to libspud/diamond/bin/diamond

  • Committer: Timothy Bond
  • Date: 2011-04-14 15:40:24 UTC
  • Revision ID: timothy.bond@imperial.ac.uk-20110414154024-116ci9gq6mwigmaw
Following the move from svn to bzr we change the nature of inclusion of these
four software libraries. Previously, they were included as svn externals and
pulled at latest version for trunk, pinned to specific versions for release
and stable trunk. Since bzr is less elegant at dealing with externals we have
made the decision to include the packages directly into the trunk instead.

At this import the versions are:

libadaptivity: r163
libvtkfortran: r67
libspud: r545
libmba2d: r28

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
#    This file is part of Diamond.
 
4
#
 
5
#    Diamond is free software: you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation, either version 3 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    Diamond is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with Diamond.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
import getopt
 
19
import os
 
20
import os.path
 
21
import sys
 
22
import traceback
 
23
 
 
24
import gtk
 
25
import gtk.gdk
 
26
gtk.gdk.threads_init()
 
27
import gobject
 
28
 
 
29
# do this right at the start, so we can find the diamond modules
 
30
diamond_path = os.path.join( os.path.realpath(os.path.dirname(__file__)), os.pardir )
 
31
sys.path.insert(0, diamond_path)
 
32
 
 
33
import diamond.debug as debug
 
34
 
 
35
def Help():
 
36
  """
 
37
  Prints usage information to standard output.
 
38
  """
 
39
 
 
40
  debug.dprint("Usage: diamond [OPTIONS] ... [FILE]\n" + \
 
41
               "\n" + \
 
42
               "A Relax NG aware XML editor. [FILE] is the XML file to be opened (a new file is\n" + \
 
43
               "created if this is not supplied).\n" + \
 
44
               "\n" + \
 
45
               "Options:\n" + \
 
46
               "\n" + \
 
47
               "-h               Display this message\n" + \
 
48
               "-s [SCHEMAFILE]  Use the supplied schema file *\n" + \
 
49
               "-t [TRONFILE]    Use the supplied schematron file for extended validation\n" + \
 
50
               "-v               Verbosity switch - if supplied Diamond prints additional\n" + \
 
51
               "                 debugging information to standard output and standard error\n" + \
 
52
               "\n" + \
 
53
               "* Note: The locations of Spud schemas can also be defined in ~/.diamond/schemata/,\n" + \
 
54
               "  see the Spud manual for further details.", 0)
 
55
 
 
56
  return
 
57
 
 
58
def main():
 
59
 
 
60
  # Detach from controlling terminal
 
61
  try:
 
62
    pid = os.fork()
 
63
    if pid == 0:
 
64
      os.setsid()
 
65
      pid = os.fork()
 
66
      if pid != 0:
 
67
        os._exit(0)
 
68
    else:
 
69
      os._exit(0)
 
70
  except:
 
71
    pass
 
72
 
 
73
  try:
 
74
    opts, args = getopt.getopt(sys.argv[1:], "hvs:t:")
 
75
  except:
 
76
    Help()
 
77
    sys.exit(1)
 
78
 
 
79
  if len(args) > 1:
 
80
    Help()
 
81
    sys.exit(1)
 
82
 
 
83
  if not ("-v", "") in opts:
 
84
    debug.SetDebugLevel(0)
 
85
  if ("-h", "") in opts:
 
86
    Help()
 
87
    return
 
88
 
 
89
  import diamond.config as config
 
90
  import diamond.dialogs as dialogs
 
91
  import diamond.interface as interface
 
92
  import diamond.schema as schema
 
93
  import diamond.tree as tree
 
94
  import diamond.plugins as plugins
 
95
 
 
96
  try:
 
97
    input_filename = args[0]
 
98
  except IndexError:
 
99
    input_filename = None
 
100
 
 
101
  logofile = None
 
102
  for possible_logofile in [os.path.join(diamond_path, "gui", "diamond.svg"), "/usr/share/diamond/gui/diamond.svg"]:
 
103
    try:
 
104
      os.stat(possible_logofile)
 
105
      logofile = possible_logofile
 
106
      break
 
107
    except OSError:
 
108
      pass
 
109
 
 
110
 
 
111
  # Let's find a schema.
 
112
 
 
113
  suffix = "xml"
 
114
 
 
115
  # if the user specifies a schema on the command line, use that.
 
116
 
 
117
  input_schemafile = None
 
118
  input_schematron_file = None
 
119
  for opt in opts:
 
120
    if opt[0] == "-s":
 
121
      input_schemafile = opt[1]
 
122
    elif opt[0] == "-t":
 
123
      input_schematron_file = opt[1]
 
124
 
 
125
  # if the user has specified a file to work on, use the suffix as a key
 
126
 
 
127
  if input_filename is not None and input_schemafile is None:
 
128
    suffix = input_filename.split(".")[-1]
 
129
    try:
 
130
      input_schemafile = config.schemata[suffix][1]
 
131
    except:
 
132
      debug.deprint("Could not find schema matching suffix %s." % suffix, 0)
 
133
      debug.deprint("Have you registered it in /etc/diamond/schemata/ or $HOME/.diamond/schemata?", 0)
 
134
      debug.deprint("To register a schema, place a file in one of those directories, and let its name be the suffix of your language.", 0)
 
135
      debug.deprint("The file should have two lines in it:", 0)
 
136
      debug.deprint("A Verbal Description Of The Language Purpose", 0)
 
137
      debug.deprint("/path/to/the/schema/file.rng", 0)
 
138
      sys.exit(1)
 
139
 
 
140
  # if there is only one schema, use that
 
141
 
 
142
  if input_schemafile is None:
 
143
    if len(config.schemata) == 1:
 
144
      suffix = config.schemata.keys()[0]
 
145
      input_schemafile = config.schemata[suffix][1]
 
146
 
 
147
  # otherwise ask the user to choose
 
148
 
 
149
  if input_schemafile is None:
 
150
    choices = [key + ": " + config.schemata[key][0] for key in config.schemata]
 
151
    choice = dialogs.radio_dialog("Choose a schema", "Choose a schema to use:", choices, logofile)
 
152
    suffix = choice.split(":")[0]
 
153
    input_schemafile = config.schemata[suffix][1]
 
154
 
 
155
  # ensure that the specified schema actually exists!
 
156
 
 
157
  try:
 
158
    if 'http' not in input_schemafile:
 
159
      os.stat(input_schemafile)
 
160
  except OSError:
 
161
    debug.deprint("Could not find schemafile %s!" % input_schemafile, 0)
 
162
    sys.exit(1)
 
163
 
 
164
  if input_schematron_file is not None:
 
165
    # ensure that the specified schematron file actually exists!
 
166
    try:
 
167
      os.stat(input_schematron_file)
 
168
    except OSError:
 
169
      debug.deprint("Could not find Schematron file %s!" % input_schematron_file, 0)
 
170
      sys.exit(1)
 
171
 
 
172
  if input_filename is not None:
 
173
    try:
 
174
      os.stat(input_filename)
 
175
    except OSError:
 
176
       pass
 
177
 
 
178
  # Import the GUI Glade file.
 
179
 
 
180
  gladefile = None
 
181
  for possible_gladefile in [os.path.join(diamond_path, "gui", "gui.glade"),
 
182
                             os.path.join(diamond_path, "share", "diamond", "gui", "gui.glade"),
 
183
                             "/usr/share/diamond/gui/gui.glade"]:
 
184
    try:
 
185
      os.stat(possible_gladefile)
 
186
      gladefile = possible_gladefile
 
187
      break
 
188
    except OSError:
 
189
      pass
 
190
  if gladefile is None:
 
191
    debug.deprint("Cannot locate GUI!", 0)
 
192
    sys.exit(1)
 
193
 
 
194
  # If input_schemafile doesn't exist, use the fluidity_options schema.
 
195
  if input_schemafile is None:
 
196
    debug.deprint("Cannot locate schemafile!", 0)
 
197
    sys.exit(1)
 
198
 
 
199
  debug.dprint("\n" + \
 
200
               "Glade file:  " + str(gladefile) + "\n" + \
 
201
               "Schema file: " + str(input_schemafile) + "\n" + \
 
202
               "Logo file:   " + str(logofile) + "\n" + \
 
203
               "Input file:  " + str(input_filename) + "\n")
 
204
 
 
205
  plugins.configure_plugins(suffix)
 
206
 
 
207
  i = interface.Diamond(gladefile = gladefile, logofile = logofile, suffix = suffix)
 
208
 
 
209
  def initialise(i, s, f):
 
210
    i.open_file(schemafile = s, filename = f)
 
211
    i.main_window.window.set_cursor(None)
 
212
    i.statusbar.clear_statusbar()
 
213
 
 
214
  i.statusbar.set_statusbar("Loading ...")
 
215
  i.main_window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
 
216
  initialise(i, input_schemafile, input_filename)
 
217
 
 
218
  gtk.main()
 
219
 
 
220
  return
 
221
 
 
222
if __name__ == "__main__":
 
223
#  import hotshot
 
224
#  prof = hotshot.Profile("hotshot_stats.prof")
 
225
#  prof.runcall(main)
 
226
#  prof.close()
 
227
  main()