This file is indexed.

/usr/share/pyshared/arcjobtool/plugins/ScriptPlugin.py is in arcjobtool 0.3.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# -*- coding: iso-8859-15 -*-
# generated by wxGlade HG on Fri Aug 28 10:05:56 2009

import wx

# begin wxGlade: extracode
# end wxGlade

from wx.lib.dialogs import *

import os

from arcjobtool.ArcUtils import *
from arcjobtool.Tasks import *
from arcjobtool.plugins.Plugins import *
from arcjobtool.PlatformUtils import *

runScriptTemplate = """#!/bin/sh
chmod +x ./%s
./%s
"""

class ScriptTask(BaseTask):
    def __init__(self):
        BaseTask.__init__(self)
        
        self.description = "Script"

        # Task specific attributes
        
        self.__mainFile = ""      
        self.packages = []
        self.extraFiles = []
        
    def onCreateRunScript(self, taskName, taskId):
        """
        Abstract routine responsible for returning a
        run-script for the job.
        """
        return runScriptTemplate % (self.__mainFile, self.__mainFile)
        
    def onCreateJobDescription(self, taskName, taskId, taskDir):
        """
        Abstract routines responsible for returning a jobdescription for
        the job.
        """
        
        # Create a managed job description
        
        job = ManagedJobDescription();
        job.Application.Executable.Name = "run.sh"
        job.Identification.JobName = str(taskName)
        job.Resources.TotalWallTime = arc.ScalableTimeInt(self.cpuTime*60)
        #job.addArgument("run.sh")
        
        # Make sure we store the full paths of input files
        
        for inputFile in self.inputFiles.keys():
            url = self.inputFiles[inputFile]
            if url == "":
                fullPath = os.path.join(taskDir, inputFile)
                job.addInputFile(fullPath)
            else:
                job.addInputFile(inputFile, url)
        
        #job.addRuntimeEnvironment("APPS/MATH/Script",">=","1.0.0")
        job.Application.Output = "stdout.txt"
        job.Application.Error = "stderr.txt"
        job.addOutputFile("/", "")
        
        #job.Print(True)
        #print job.UnParse()
              
        return job
    
    def onSaveConfig(self, config):
        config.add_section("scriptplugin")
        config.set("scriptplugin", "mainfile", self.mainFile)
    
    def onLoadConfig(self, config):
        try:
            self.mainFile = config.get("scriptplugin", "mainfile")
        except:
            pass
            
    def setMainFile(self, filename):
        self.__mainFile = filename
        
    def getMainFile(self):
        return self.__mainFile
        
    def addPackage(self, filename):
        pass
    
    def addExtraFile(self, filename):
        pass
    
    def removePackage(self, filename):
        pass
    
    def removeExtraFile(self, filename):
        pass
            
    mainFile = property(getMainFile, setMainFile)

class ScriptPlugin(PluginBase):
    def onInit(self):
        self.__task = ScriptTask()
 
    def onDestroy(self):
        pass
    
    def onEdit(self):
        dlg = ScriptPluginDialog(None, -1, "")
        dlg.task = self.__task
        dlg.ShowModal()
        dlg.Destroy()
        self.__task = dlg.task
    
    def onSave(self, workDir):
        (taskLocation, taskDirName) = os.path.split(workDir)
        self.__task.name = taskDirName.split(".")[0]
        self.__task.workDir = workDir
        self.__task.save()
    
    def onLoad(self, workDir):
        (taskLocation, taskDirName) = os.path.split(workDir)
        self.__task.name = taskDirName.split(".")[0]
        self.__task.workDir = workDir
        self.__task.load()
        
    def onClean(self):
        self.__task.clean()        
        
    def onSetup(self):
        self.__task.setup()
               
    def onGetId(self):
        return "ScriptPlugin"
    
    def onGetVersion(self):
        return (0,1,0)
        
    def onGetDescription(self):
        return "Script job definition plugin."
    
    def onGetShortName(self):
        return "Script job definition."
    
    def onNeedSave(self):
        return self.__task.dirty
    
    def onGetTask(self):
        return self.__task
        
    id = property(onGetId)
    version = property(onGetVersion)
    shortname = property(onGetShortName)
    description = property(onGetDescription)
    task = property(onGetTask)


class ScriptPluginDialog(wx.Dialog):
    def __init__(self, *args, **kwds):
        # begin wxGlade: ScriptPluginDialog.__init__
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.THICK_FRAME
        wx.Dialog.__init__(self, *args, **kwds)
        self.notebook_1 = wx.Notebook(self, -1, style=0)
        self.generalPane = wx.Panel(self.notebook_1, -1)
        self.nameLabel = wx.StaticText(self.generalPane, -1, "Name", style=wx.ALIGN_RIGHT)
        self.jobNameText = wx.TextCtrl(self.generalPane, -1, "", style=wx.TE_READONLY)
        self.cputTimeLabel = wx.StaticText(self.generalPane, -1, "CPU Time (min)", style=wx.ALIGN_RIGHT)
        self.cpuTimeText = wx.TextCtrl(self.generalPane, -1, "")
        self.notifyLabel = wx.StaticText(self.generalPane, -1, "Notify (email)", style=wx.ALIGN_RIGHT)
        self.notifyText = wx.TextCtrl(self.generalPane, -1, "")
        self.notifyMemoryLabel = wx.StaticText(self.generalPane, -1, "Memory (MB)", style=wx.ALIGN_RIGHT)
        self.memoryText = wx.TextCtrl(self.generalPane, -1, "")
        self.inputFilePane = wx.Panel(self.notebook_1, -1)
        self.inputFilesLabel = wx.StaticText(self.inputFilePane, -1, "Input files")
        self.inputFileList = wx.ListBox(self.inputFilePane, -1, choices=[])
        self.addFileButton = wx.Button(self.inputFilePane, -1, "Add...")
        self.createButton = wx.Button(self.inputFilePane, -1, "Create...")
        self.removeFileButton = wx.Button(self.inputFilePane, -1, "Remove")
        self.clearFilesButton = wx.Button(self.inputFilePane, -1, "Clear")
        self.inputFileEditButton = wx.Button(self.inputFilePane, -1, "Edit...")
        self.mainFileLabel = wx.StaticText(self.inputFilePane, -1, "Main script file")
        self.mainFileChoice = wx.Choice(self.inputFilePane, -1, choices=[])
        self.parameterPane = wx.Panel(self.notebook_1, -1)
        self.parameterFilesLabel = wx.StaticText(self.parameterPane, -1, "Parameter substitution files")
        self.paramFilesList = wx.ListBox(self.parameterPane, -1, choices=[])
        self.AddParamFileButton = wx.Button(self.parameterPane, -1, "Add...")
        self.removeParamFileButton = wx.Button(self.parameterPane, -1, "Remove")
        self.clearParamFilesButton = wx.Button(self.parameterPane, -1, "Clear")
        self.paramFileEditButton = wx.Button(self.parameterPane, -1, "Edit...")
        self.static_line_1 = wx.StaticLine(self.parameterPane, -1)
        self.sweepSizeLabel = wx.StaticText(self.parameterPane, -1, "Sweep size", style=wx.ALIGN_RIGHT)
        self.sweepSizeSpinner = wx.SpinCtrl(self.parameterPane, -1, "0", min=1, max=1000)
        self.saveButton = wx.Button(self, -1, "Save")
        self.closeButton = wx.Button(self, -1, "Close")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.onAddFile, self.addFileButton)
        self.Bind(wx.EVT_BUTTON, self.onCreateFile, self.createButton)
        self.Bind(wx.EVT_BUTTON, self.onRemoveFile, self.removeFileButton)
        self.Bind(wx.EVT_BUTTON, self.onClearFiles, self.clearFilesButton)
        self.Bind(wx.EVT_BUTTON, self.onEditInputFile, self.inputFileEditButton)
        self.Bind(wx.EVT_CHOICE, self.onSelectMainFile, self.mainFileChoice)
        self.Bind(wx.EVT_BUTTON, self.onAddParamFile, self.AddParamFileButton)
        self.Bind(wx.EVT_BUTTON, self.onRemoveParamFileButton, self.removeParamFileButton)
        self.Bind(wx.EVT_BUTTON, self.onClearParamFilesButton, self.clearParamFilesButton)
        self.Bind(wx.EVT_BUTTON, self.onEditParamFile, self.paramFileEditButton)
        self.Bind(wx.EVT_BUTTON, self.onSave, self.saveButton)
        self.Bind(wx.EVT_BUTTON, self.onClose, self.closeButton)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: ScriptPluginDialog.__set_properties
        self.SetTitle("Script job definition")
        self.SetSize((410, 368))
        self.nameLabel.SetMinSize((120, -1))
        self.jobNameText.SetMinSize((-1, 27))
        self.cputTimeLabel.SetMinSize((120, -1))
        self.cpuTimeText.SetMinSize((-1, 27))
        self.notifyLabel.SetMinSize((120, -1))
        self.notifyText.SetMinSize((-1, 27))
        self.notifyMemoryLabel.SetMinSize((120, -1))
        self.memoryText.SetMinSize((-1, 27))
        self.sweepSizeLabel.SetMinSize((120, -1))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: ScriptPluginDialog.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_11 = wx.BoxSizer(wx.VERTICAL)
        sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_13 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_14 = wx.BoxSizer(wx.VERTICAL)
        sizer_9 = wx.BoxSizer(wx.VERTICAL)
        sizer_10 = wx.BoxSizer(wx.VERTICAL)
        sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_9_copy = wx.BoxSizer(wx.VERTICAL)
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4.Add(self.nameLabel, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_4.Add(self.jobNameText, 1, wx.RIGHT|wx.EXPAND, 4)
        sizer_3.Add(sizer_4, 0, wx.TOP|wx.EXPAND, 10)
        sizer_5.Add(self.cputTimeLabel, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_5.Add(self.cpuTimeText, 1, wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
        sizer_3.Add(sizer_5, 0, wx.EXPAND, 0)
        sizer_6.Add(self.notifyLabel, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_6.Add(self.notifyText, 1, wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
        sizer_3.Add(sizer_6, 0, wx.EXPAND, 0)
        sizer_7.Add(self.notifyMemoryLabel, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_7.Add(self.memoryText, 1, wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5)
        sizer_3.Add(sizer_7, 0, wx.EXPAND, 0)
        self.generalPane.SetSizer(sizer_3)
        sizer_9.Add(self.inputFilesLabel, 0, wx.LEFT|wx.TOP|wx.ADJUST_MINSIZE, 4)
        sizer_8.Add(self.inputFileList, 1, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
        sizer_9_copy.Add(self.addFileButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_9_copy.Add(self.createButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_9_copy.Add(self.removeFileButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_9_copy.Add(self.clearFilesButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_9_copy.Add(self.inputFileEditButton, 0, wx.TOP|wx.ADJUST_MINSIZE, 7)
        sizer_8.Add(sizer_9_copy, 0, wx.ALL|wx.EXPAND, 4)
        sizer_9.Add(sizer_8, 1, wx.EXPAND, 0)
        sizer_10.Add(self.mainFileLabel, 0, wx.ADJUST_MINSIZE, 0)
        sizer_10.Add(self.mainFileChoice, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_9.Add(sizer_10, 0, wx.ALL|wx.EXPAND, 4)
        self.inputFilePane.SetSizer(sizer_9)
        sizer_11.Add(self.parameterFilesLabel, 0, wx.LEFT|wx.TOP|wx.ADJUST_MINSIZE, 4)
        sizer_13.Add(self.paramFilesList, 1, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 4)
        sizer_14.Add(self.AddParamFileButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_14.Add(self.removeParamFileButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_14.Add(self.clearParamFilesButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_14.Add(self.paramFileEditButton, 0, wx.TOP|wx.ADJUST_MINSIZE, 7)
        sizer_13.Add(sizer_14, 0, wx.ALL|wx.EXPAND, 4)
        sizer_11.Add(sizer_13, 1, wx.EXPAND, 0)
        sizer_11.Add(self.static_line_1, 0, wx.TOP|wx.EXPAND, 5)
        sizer_12.Add(self.sweepSizeLabel, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_12.Add(self.sweepSizeSpinner, 0, wx.TOP|wx.ADJUST_MINSIZE, 2)
        sizer_11.Add(sizer_12, 0, wx.TOP|wx.BOTTOM|wx.EXPAND, 4)
        self.parameterPane.SetSizer(sizer_11)
        self.notebook_1.AddPage(self.generalPane, "General")
        self.notebook_1.AddPage(self.inputFilePane, "Input files")
        self.notebook_1.AddPage(self.parameterPane, "Parameters")
        sizer_1.Add(self.notebook_1, 1, wx.ALL|wx.EXPAND, 8)
        sizer_2.Add(self.saveButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(self.closeButton, 0, wx.ADJUST_MINSIZE, 0)
        sizer_1.Add(sizer_2, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 4)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade
        
    def __setupInputFiles(self):
        """
        Setup listbox for input files and choice box
        for selecting main file.
        """
        self.inputFileList.Clear()
        self.mainFileChoice.Clear()
        
        filenameDict = {}
        count = 0
        
        # Fill listbox and choice box
        
        if self.__task!=None:
            for inputFile in self.__task.inputFiles.keys():
                self.inputFileList.Append(inputFile)
                filenameDict[inputFile] = count
                count = count + 1 
                self.mainFileChoice.Append(inputFile)
                    
        # Select main file (if any) in the choice box
        
        if filenameDict.has_key(self.__task.mainFile):
            print "filenameDict has key", self.__task.mainFile
            print "Selection = ", filenameDict[self.__task.mainFile]
            self.mainFileChoice.SetSelection(filenameDict[self.__task.mainFile])
            
    def __setupSweepFiles(self):

        self.paramFilesList.Clear()
        
        # Fill listbox
        
        if self.__task!=None:
            for sweepFile in self.__task.sweepFiles.keys():
                print sweepFile     
                self.paramFilesList.Append(sweepFile)
                    

    def onSave(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        self.__task.cpuTime = int(self.cpuTimeText.GetValue())
        self.__task.notify = self.notifyText.GetValue()
        self.__task.memory = int(self.memoryText.GetValue())
        self.__task.sweepSize = int(self.sweepSizeSpinner.GetValue())
        self.__task.dirty = True
        self.Close()

    def onClose(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        self.__task.dirty = False
        self.Close()
        
    def setTask(self, task):
        self.__task = task
        
        self.jobNameText.SetValue(self.__task.name)
        self.cpuTimeText.SetValue(str(self.__task.cpuTime))
        self.notifyText.SetValue(self.__task.notify)
        self.memoryText.SetValue(str(self.__task.memory))
        self.sweepSizeSpinner.SetValue(int(self.__task.sweepSize))
        
        self.__setupInputFiles()
        self.__setupSweepFiles()
        
    def getTask(self):
        return self.__task
    
    def onAddFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        inputFilename = wx.FileSelector("Add input file", default_path=os.getcwd())
        if inputFilename != "":
            self.__task.addAndCopyInputFile(inputFilename)
            self.__setupInputFiles()

    def onRemoveFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        if self.inputFileList.GetStringSelection()!="":
            self.__task.removeInputFile(self.inputFileList.GetStringSelection())
            self.__setupInputFiles()

    def onClearFiles(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        self.__task.clearInputFiles()
        self.__setupInputFiles()

    task = property(getTask, setTask)

    def onSelectMainFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        mainFile = self.mainFileChoice.GetStringSelection()
        if mainFile != "":
            self.__task.mainFile = mainFile

    def onAddParamFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        result = singleChoiceDialog(self, "Add file for substitution", "Input files", self.__task.inputFiles)
        if result.accepted:
            self.__task.addSweepFile(result.selection)
            self.__setupSweepFiles()

    def onRemoveParamFileButton(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        if self.paramFilesList.GetStringSelection()!="":
            self.__task.removeSweepFile(self.paramFilesList.GetStringSelection())
            self.__setupSweepFiles()

    def onClearParamFilesButton(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        self.__task.clearSweepFiles()
        self.__setupSweepFiles()

    def onEditInputFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        if self.inputFileList.GetStringSelection()!="":
            fullPath = os.path.join(self.__task.workDir,self.inputFileList.GetStringSelection())
            editFile(fullPath)

    def onEditParamFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        if self.paramFilesList.GetStringSelection()!="":
            fullPath = os.path.join(self.__task.workDir,self.paramFilesList.GetStringSelection())
            editFile(fullPath)

    def onCreateFile(self, event): # wxGlade: ScriptPluginDialog.<event_handler>
        result = textEntryDialog(self, "Create file", "Filename", "noname.txt")
        
        if result.accepted:
            fullPath = os.path.join(self.__task.workDir, str(result.text))
            
            newFile = open(fullPath, "w")
            newFile.close()
            
            editFile(fullPath)

            self.__task.addAndCopyInputFile(fullPath, copyFile = False)
            self.__setupInputFiles()

# end of class ScriptPluginDialog

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    mainDialog = ScriptPluginDialog(None, -1, "")
    app.SetTopWindow(mainDialog)
    mainDialog.Show()
    app.MainLoop()