3
# This file is part of Diamond.
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.
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.
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/>.
26
gtk.gdk.threads_init()
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)
33
import diamond.debug as debug
37
Prints usage information to standard output.
40
debug.dprint("Usage: diamond [OPTIONS] ... [FILE]\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" + \
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" + \
53
"* Note: The locations of Spud schemas can also be defined in ~/.diamond/schemata/,\n" + \
54
" see the Spud manual for further details.", 0)
60
# Detach from controlling terminal
74
opts, args = getopt.getopt(sys.argv[1:], "hvs:t:")
83
if not ("-v", "") in opts:
84
debug.SetDebugLevel(0)
85
if ("-h", "") in opts:
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
97
input_filename = args[0]
102
for possible_logofile in [os.path.join(diamond_path, "gui", "diamond.svg"), "/usr/share/diamond/gui/diamond.svg"]:
104
os.stat(possible_logofile)
105
logofile = possible_logofile
111
# Let's find a schema.
115
# if the user specifies a schema on the command line, use that.
117
input_schemafile = None
118
input_schematron_file = None
121
input_schemafile = opt[1]
123
input_schematron_file = opt[1]
125
# if the user has specified a file to work on, use the suffix as a key
127
if input_filename is not None and input_schemafile is None:
128
suffix = input_filename.split(".")[-1]
130
input_schemafile = config.schemata[suffix][1]
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)
140
# if there is only one schema, use that
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]
147
# otherwise ask the user to choose
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]
155
# ensure that the specified schema actually exists!
158
if 'http' not in input_schemafile:
159
os.stat(input_schemafile)
161
debug.deprint("Could not find schemafile %s!" % input_schemafile, 0)
164
if input_schematron_file is not None:
165
# ensure that the specified schematron file actually exists!
167
os.stat(input_schematron_file)
169
debug.deprint("Could not find Schematron file %s!" % input_schematron_file, 0)
172
if input_filename is not None:
174
os.stat(input_filename)
178
# Import the GUI Glade file.
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"]:
185
os.stat(possible_gladefile)
186
gladefile = possible_gladefile
190
if gladefile is None:
191
debug.deprint("Cannot locate GUI!", 0)
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)
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")
205
plugins.configure_plugins(suffix)
207
i = interface.Diamond(gladefile = gladefile, logofile = logofile, suffix = suffix)
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()
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)
222
if __name__ == "__main__":
224
# prof = hotshot.Profile("hotshot_stats.prof")