1
2
3
4 import wx
5
6
7
8
9 from wx.lib.dialogs import *
10
11 import os
12
13 from arcjobtool.ArcUtils import *
14 from arcjobtool.Tasks import *
15 from arcjobtool.plugins.Plugins import *
16 from arcjobtool.PlatformUtils import *
17
18 runScriptTemplate = """#!/bin/sh
19 chmod +x ./%s
20 ./%s
21 """
22
25 BaseTask.__init__(self, createRunScript=False)
26
27 self.description = "Xrsl"
28
29
30
31 self.jobDescriptionFilename = "job.df"
32 self.jobDescription = """&(executable="/bin/echo")
33 (arguments="hello")
34 (inputFiles=("run.sh" ""))
35 (outputFiles=("result.txt" ""))
36 (stdout="stdout.txt")
37 (stderr="stderr.txt")
38 (wallTime="5 minutes")
39 """
40
42 """
43 Abstract routine responsible for returning a
44 run-script for the job.
45 """
46 return runScriptTemplate % (self.__mainFile, self.__mainFile)
47
49 """
50 Abstract routines responsible for returning a jobdescription for
51 the job.
52 """
53
54
55
56 job = arc.JobDescription();
57 job.Parse(str(self.jobDescription % {"id":taskId, "taskdir":taskDir}))
58 job.Identification.JobName = str(taskName)
59 return job
60
62 """
63 Loads the job description file from job definition dir.
64 """
65 descrFile = open(os.path.join(self.workDir, self.jobDescriptionFilename), "r")
66 self.jobDescription = descrFile.read()
67 descrFile.close()
68
70 """
71 Saves the job definition file to job definition dir.
72 """
73 descrFile = open(os.path.join(self.workDir, self.jobDescriptionFilename), "w")
74 descrFile.write(self.jobDescription)
75 descrFile.close()
76
77
79 """
80 Save configuration data specific to this plugin.
81 """
82 config.add_section("xrslplugin")
83 config.set("xrslplugin", "descrfilename", self.jobDescriptionFilename)
84 self.saveJobDescription()
85
87 """
88 Loads configuration settings specific to this plugin.
89 """
90 try:
91 self.jobDescriptionFilename = config.get("xrslplugin", "descrfilename")
92 except:
93 return
94
95 self.loadJobDescription()
96
152
153
156
157 self.__applicationDir = os.path.dirname(sys.argv[0])
158
159 if os.environ.has_key("ARCJOBTOOL_SHARE"):
160 self.__imageDir = os.path.join(os.environ["ARCJOBTOOL_SHARE"], "images")
161 else:
162 self.__imageDir = os.path.join(self.__applicationDir, "../share/arcjobtool/images")
163
164 ARCGUI_VALIDATE_XRSL = os.path.join(self.__imageDir, "preview-xrsl.png")
165 ARCGUI_EDIT_XRSL = os.path.join(self.__imageDir, "document-new.png")
166 ARCGUI_IMPORT_XRSL = os.path.join(self.__imageDir, "folder-open.png")
167
168
169 kwds["style"] = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.THICK_FRAME
170 wx.Dialog.__init__(self, *args, **kwds)
171 self.notebook_1 = wx.Notebook(self, -1, style=0)
172 self.generalPane = wx.Panel(self.notebook_1, -1)
173 self.validateDescriptionButton = wx.BitmapButton(self.generalPane, -1, wx.Bitmap(ARCGUI_VALIDATE_XRSL,wx.BITMAP_TYPE_ANY), style=wx.NO_BORDER)
174 self.editDescriptionButton = wx.BitmapButton(self.generalPane, -1, wx.Bitmap(ARCGUI_EDIT_XRSL,wx.BITMAP_TYPE_ANY), style=wx.NO_BORDER)
175 self.importJobDescriptionButton = wx.BitmapButton(self.generalPane, -1, wx.Bitmap(ARCGUI_IMPORT_XRSL,wx.BITMAP_TYPE_ANY), style=wx.NO_BORDER)
176 self.jobDescriptionText = wx.TextCtrl(self.generalPane, -1, "", style=wx.TE_MULTILINE|wx.HSCROLL|wx.TE_RICH)
177 self.inputFilePane = wx.Panel(self.notebook_1, -1)
178 self.inputFilesLabel = wx.StaticText(self.inputFilePane, -1, "Input files")
179 self.inputFileList = wx.ListBox(self.inputFilePane, -1, choices=[])
180 self.addFileButton = wx.Button(self.inputFilePane, -1, "Add...")
181 self.createFileButton = wx.Button(self.inputFilePane, -1, "Create...")
182 self.removeFileButton = wx.Button(self.inputFilePane, -1, "Remove")
183 self.clearFilesButton = wx.Button(self.inputFilePane, -1, "Clear")
184 self.inputFileEditButton = wx.Button(self.inputFilePane, -1, "Edit...")
185 self.parameterPane = wx.Panel(self.notebook_1, -1)
186 self.parameterFilesLabel = wx.StaticText(self.parameterPane, -1, "Parameter substitution files")
187 self.paramFilesList = wx.ListBox(self.parameterPane, -1, choices=[])
188 self.AddParamFileButton = wx.Button(self.parameterPane, -1, "Add...")
189 self.removeParamFileButton = wx.Button(self.parameterPane, -1, "Remove")
190 self.clearParamFilesButton = wx.Button(self.parameterPane, -1, "Clear")
191 self.paramFileEditButton = wx.Button(self.parameterPane, -1, "Edit...")
192 self.static_line_1 = wx.StaticLine(self.parameterPane, -1)
193 self.sweepSizeLabel = wx.StaticText(self.parameterPane, -1, "Sweep size", style=wx.ALIGN_RIGHT)
194 self.sweepSizeSpinner = wx.SpinCtrl(self.parameterPane, -1, "0", min=1, max=1000)
195 self.saveButton = wx.Button(self, -1, "Save")
196 self.closeButton = wx.Button(self, -1, "Close")
197
198 self.__set_properties()
199 self.__do_layout()
200
201 self.Bind(wx.EVT_BUTTON, self.onValidateDescription, self.validateDescriptionButton)
202 self.Bind(wx.EVT_BUTTON, self.onEditDescription, self.editDescriptionButton)
203 self.Bind(wx.EVT_BUTTON, self.onImportJobDescription, self.importJobDescriptionButton)
204 self.Bind(wx.EVT_BUTTON, self.onAddFile, self.addFileButton)
205 self.Bind(wx.EVT_BUTTON, self.onCreateFile, self.createFileButton)
206 self.Bind(wx.EVT_BUTTON, self.onRemoveFile, self.removeFileButton)
207 self.Bind(wx.EVT_BUTTON, self.onClearFiles, self.clearFilesButton)
208 self.Bind(wx.EVT_BUTTON, self.onEditInputFile, self.inputFileEditButton)
209 self.Bind(wx.EVT_BUTTON, self.onAddParamFile, self.AddParamFileButton)
210 self.Bind(wx.EVT_BUTTON, self.onRemoveParamFileButton, self.removeParamFileButton)
211 self.Bind(wx.EVT_BUTTON, self.onClearParamFilesButton, self.clearParamFilesButton)
212 self.Bind(wx.EVT_BUTTON, self.onEditParamFile, self.paramFileEditButton)
213 self.Bind(wx.EVT_BUTTON, self.onSave, self.saveButton)
214 self.Bind(wx.EVT_BUTTON, self.onClose, self.closeButton)
215
216
218
219 self.SetTitle("XRSL job definition")
220 self.SetSize((488, 421))
221 self.validateDescriptionButton.SetToolTipString("Validate job description")
222 self.validateDescriptionButton.SetSize(self.validateDescriptionButton.GetBestSize())
223 self.editDescriptionButton.SetToolTipString("Edit with external editor")
224 self.editDescriptionButton.SetSize(self.editDescriptionButton.GetBestSize())
225 self.importJobDescriptionButton.SetToolTipString("Import job description")
226 self.importJobDescriptionButton.SetSize(self.importJobDescriptionButton.GetBestSize())
227 self.jobDescriptionText.SetFont(wx.Font(10, wx.SCRIPT, wx.NORMAL, wx.NORMAL, 0, "Courier"))
228 self.sweepSizeLabel.SetMinSize((120, -1))
229
230
232
233 sizer_1 = wx.BoxSizer(wx.VERTICAL)
234 sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
235 sizer_11 = wx.BoxSizer(wx.VERTICAL)
236 sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
237 sizer_13 = wx.BoxSizer(wx.HORIZONTAL)
238 sizer_14 = wx.BoxSizer(wx.VERTICAL)
239 sizer_9 = wx.BoxSizer(wx.VERTICAL)
240 sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
241 sizer_9_copy = wx.BoxSizer(wx.VERTICAL)
242 sizer_34 = wx.BoxSizer(wx.VERTICAL)
243 sizer_35 = wx.BoxSizer(wx.HORIZONTAL)
244 sizer_35.Add(self.validateDescriptionButton, 0, wx.ADJUST_MINSIZE, 0)
245 sizer_35.Add(self.editDescriptionButton, 0, wx.ADJUST_MINSIZE, 0)
246 sizer_35.Add(self.importJobDescriptionButton, 0, wx.ADJUST_MINSIZE, 0)
247 sizer_34.Add(sizer_35, 0, wx.ALL|wx.EXPAND, 4)
248 sizer_34.Add(self.jobDescriptionText, 1, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
249 self.generalPane.SetSizer(sizer_34)
250 sizer_9.Add(self.inputFilesLabel, 0, wx.LEFT|wx.TOP|wx.ADJUST_MINSIZE, 4)
251 sizer_8.Add(self.inputFileList, 1, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
252 sizer_9_copy.Add(self.addFileButton, 0, wx.ADJUST_MINSIZE, 0)
253 sizer_9_copy.Add(self.createFileButton, 0, wx.ADJUST_MINSIZE, 0)
254 sizer_9_copy.Add(self.removeFileButton, 0, wx.ADJUST_MINSIZE, 0)
255 sizer_9_copy.Add(self.clearFilesButton, 0, wx.ADJUST_MINSIZE, 0)
256 sizer_9_copy.Add(self.inputFileEditButton, 0, wx.TOP|wx.ADJUST_MINSIZE, 7)
257 sizer_8.Add(sizer_9_copy, 0, wx.ALL|wx.EXPAND, 4)
258 sizer_9.Add(sizer_8, 1, wx.EXPAND, 0)
259 self.inputFilePane.SetSizer(sizer_9)
260 sizer_11.Add(self.parameterFilesLabel, 0, wx.LEFT|wx.TOP|wx.ADJUST_MINSIZE, 4)
261 sizer_13.Add(self.paramFilesList, 1, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
262 sizer_14.Add(self.AddParamFileButton, 0, wx.ADJUST_MINSIZE, 0)
263 sizer_14.Add(self.removeParamFileButton, 0, wx.ADJUST_MINSIZE, 0)
264 sizer_14.Add(self.clearParamFilesButton, 0, wx.ADJUST_MINSIZE, 0)
265 sizer_14.Add(self.paramFileEditButton, 0, wx.TOP|wx.ADJUST_MINSIZE, 7)
266 sizer_13.Add(sizer_14, 0, wx.ALL|wx.EXPAND, 4)
267 sizer_11.Add(sizer_13, 1, wx.EXPAND, 0)
268 sizer_11.Add(self.static_line_1, 0, wx.TOP|wx.EXPAND, 5)
269 sizer_12.Add(self.sweepSizeLabel, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
270 sizer_12.Add(self.sweepSizeSpinner, 0, wx.TOP|wx.ADJUST_MINSIZE, 2)
271 sizer_11.Add(sizer_12, 0, wx.TOP|wx.BOTTOM|wx.EXPAND, 4)
272 self.parameterPane.SetSizer(sizer_11)
273 self.notebook_1.AddPage(self.generalPane, "XRSL")
274 self.notebook_1.AddPage(self.inputFilePane, "Input files")
275 self.notebook_1.AddPage(self.parameterPane, "Parameters")
276 sizer_1.Add(self.notebook_1, 1, wx.ALL|wx.EXPAND, 8)
277 sizer_2.Add(self.saveButton, 0, wx.ADJUST_MINSIZE, 0)
278 sizer_2.Add(self.closeButton, 0, wx.ADJUST_MINSIZE, 0)
279 sizer_1.Add(sizer_2, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 4)
280 self.SetSizer(sizer_1)
281 self.Layout()
282
283
301
303
304 self.paramFilesList.Clear()
305
306
307
308 if self.__task!=None:
309 for sweepFile in self.__task.sweepFiles.keys():
310 self.paramFilesList.Append(sweepFile)
311
312
314
315
316
317 self.__task.sweepSize = int(self.sweepSizeSpinner.GetValue())
318 self.__task.jobDescription = str(self.jobDescriptionText.GetValue())
319 self.__task.dirty = True
320 self.Close()
321
323 self.__task.dirty = False
324 self.Close()
325
327 self.__task = task
328
329
330
331
332
333 self.sweepSizeSpinner.SetValue(int(self.__task.sweepSize))
334 self.jobDescriptionText.SetValue(self.task.jobDescription)
335
336 self.__setupInputFiles()
337 self.__setupSweepFiles()
338
341
343 inputFilename = wx.FileSelector("Add input file", default_path=os.getcwd())
344 if inputFilename != "":
345 self.__task.addAndCopyInputFile(inputFilename)
346 self.__setupInputFiles()
347
349 if self.inputFileList.GetStringSelection()!="":
350 self.__task.removeInputFile(self.inputFileList.GetStringSelection())
351 self.__setupInputFiles()
352
354 self.__task.clearInputFiles()
355 self.__setupInputFiles()
356
358 result = singleChoiceDialog(self, "Add file for substitution", "Input files", self.__task.inputFiles)
359 if result.accepted:
360 self.__task.addSweepFile(result.selection)
361 self.__setupSweepFiles()
362
364 if self.paramFilesList.GetStringSelection()!="":
365 self.__task.removeSweepFile(self.paramFilesList.GetStringSelection())
366 self.__setupSweepFiles()
367
369 self.__task.clearSweepFiles()
370 self.__setupSweepFiles()
371
373 if self.inputFileList.GetStringSelection()!="":
374 fullPath = os.path.join(self.__task.workDir,self.inputFileList.GetStringSelection())
375 editFile(fullPath)
376
378 if self.paramFilesList.GetStringSelection()!="":
379 fullPath = os.path.join(self.__task.workDir,self.paramFilesList.GetStringSelection())
380 editFile(fullPath)
381
383 result = textEntryDialog(self, "Create file", "Filename", "noname.txt")
384
385 if result.accepted:
386 fullPath = os.path.join(self.__task.workDir, str(result.text))
387
388 newFile = open(fullPath, "w")
389 newFile.close()
390
391 editFile(fullPath)
392
393 self.__task.addAndCopyInputFile(fullPath, copyFile = False)
394 self.__setupInputFiles()
395
397 """
398 Validate job description.
399 """
400
401 currDir = os.getcwd()
402
403 os.chdir(self.__task.workDir)
404
405 job = ManagedJobDescription()
406
407 self.__task.jobDescription = str(self.jobDescriptionText.GetValue())
408
409
410 jobDescription = self.__task.jobDescription % {"taskdir":self.__task.workDir}
411
412
413
414 print jobDescription
415
416 if job.Parse(str(jobDescription)) and job.UnParse("xrsl"):
417 wx.MessageBox("Job description checks out ok.")
418 else:
419 wx.MessageBox("Job description does not validate. Please check log for more details.")
420
421 os.chdir(currDir)
422
424 """
425 Edit job description with external editor.
426 """
427 editFile(os.path.join(self.__task.workDir, self.__task.jobDescriptionFilename))
428 self.__task.loadJobDescription()
429
431 inputFilename = wx.FileSelector("Import XRSL file", default_path=os.getcwd())
432 if inputFilename != "":
433 descrFile = open(inputFilename, "r")
434 jobDescription = descrFile.read()
435 descrFile.close()
436
437 self.jobDescriptionText.SetValue(jobDescription)
438
439 task = property(getTask, setTask)
440
441
442
443
444
445 if __name__ == "__main__":
446 app = wx.PySimpleApp(0)
447 wx.InitAllImageHandlers()
448 mainDialog = XrslPluginDialog(None, -1, "")
449 app.SetTopWindow(mainDialog)
450 mainDialog.Show()
451 app.MainLoop()
452