source: palm/trunk/SCRIPTS/palmrungui @ 4427

Last change on this file since 4427 was 4427, checked in by maronga, 4 years ago

small adjustments in palmrungui

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 59.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#--------------------------------------------------------------------------------#
4# This file is part of the PALM model system.
5#
6# PALM is free software: you can redistribute it and/or modify it under the terms
7# of the GNU General Public License as published by the Free Software Foundation,
8# either version 3 of the License, or (at your option) any later version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
17# Copyright 1997-2018  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: palmrungui 4427 2020-02-27 11:29:51Z maronga $
27# Small fixes and adjustments
28#
29# 4420 2020-02-24 14:13:56Z maronga
30# Bugfix: minor fixes related to start buttons
31#
32# 4411 2020-02-18 14:28:02Z maronga
33# Added new features: individual tag for submitted runs, automatic finding of
34# configuration, start of palmbuild from GUI
35#
36# 4405 2020-02-12 19:11:11Z maronga
37# Major revisions: New layout. Merged with palm job manager (palm_jm).
38# Minor revisions: Misc. bugs fixed.
39#
40# 4394 2020-02-04 21:40:38Z maronga
41# Bugfix: harmonized naming convention of configuration files
42#
43# 4393 2020-02-04 21:24:48Z maronga
44# Removed PALM_BIN dependency and os calls
45#
46# 3487 2018-11-05 07:18:02Z maronga
47# Renamed options -d and -h to -r and -c.
48#
49# 2825 2018-02-20 21:48:27Z maronga
50# Adjusted to work with newest version of palmrun
51#
52# 2718 2018-01-02 08:49:38Z maronga
53# Corrected "Former revisions" section
54#
55# 2696 2017-12-14 17:12:51Z kanani
56# Change in file header (GPL part)
57#
58# 2484 2017-09-20 14:22:42Z maronga
59# Added PALM logo
60#
61# 2480 2017-09-19 06:24:14Z maronga
62# option -A (project account number) added
63#
64# 2477 2017-09-18 08:42:29Z maronga
65# Renamed restart run appendix from "f" to "r". Bugfix for displaying restart runs.>
66# Revised list of recently submitted jobs
67#
68# 2413 2017-09-06 12:48:29Z maronga
69# Renamed to palmrungui and adapted for use with palmrun instead of mrun.
70#
71# 2316 2017-07-20 07:53:42Z maronga
72# Initial revision in python
73#
74#
75#
76# Description:
77# ------------
78# Graphical user interface for the palmrun script.
79# @author Felix Gaschler
80# @author Björn Maronga (maronga@muk.uni-hannover.de)
81#
82# Instructions:
83# -------------
84#
85#------------------------------------------------------------------------------!
86
87import sys
88import subprocess
89from PyQt4 import QtCore, QtGui, uic
90from PyQt4.QtCore import QProcess,pyqtSlot,SIGNAL,SLOT
91from time import strftime
92import os
93import shutil
94
95
96
97# Determine PALM directories
98try: 
99   devnull = open(os.devnull, 'w')     
100   palm_dir = os.getcwd()
101   palm_bin = palm_dir + '/trunk/SCRIPTS'
102   job_dir = palm_dir + '/JOBS'
103   user_dir = palm_dir + '/USER_CODE'
104   with open(palm_bin + '/palmrungui', 'r') as fh:
105      # file found
106      out = None
107except:   
108   print "Error. palmrungui probably called in wrong directory."
109   raise SystemExit
110
111
112palmrunline = ""
113set_list = []
114
115Ui_MainWindow = uic.loadUiType("%s/palmrungui_files/mainwindow.ui" % (palm_bin))[0]
116Ui_helpDialog = uic.loadUiType("%s/palmrungui_files/help.ui" % (palm_bin))[0]
117Ui_aboutDialog = uic.loadUiType("%s/palmrungui_files/about.ui" % (palm_bin))[0]
118
119class HelpDialog(QtGui.QDialog,Ui_helpDialog):
120    def __init__(self, parent=None):
121        super(HelpDialog,self).__init__()
122        self.setupUi(self)
123       
124class AboutDialog(QtGui.QDialog,Ui_aboutDialog):
125    def __init__(self, parent=None):
126        super(AboutDialog,self).__init__()
127        self.setupUi(self)       
128
129class Mainwindow(QtGui.QMainWindow, Ui_MainWindow):
130    def __init__(self, parent=None):
131        super(Mainwindow, self).__init__()
132        self.setupUi(self)
133   
134        self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))       
135       
136        self.recent_jobs(50)
137        self.load_jobs()
138
139        # look up configuration files and add to combo box
140       
141        self.group_execution.findChild(QtGui.QComboBox,"combo_configuration").addItem("")
142       
143        for files in os.listdir(palm_dir):
144           if files.startswith(".palm.config"):
145              tmpstring = filter(None,files.split(".palm.config."))[0]
146              self.group_execution.findChild(QtGui.QComboBox,"combo_configuration").addItem(tmpstring)
147
148        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
149        commandline.setText("")
150       
151        self.tabWidget.setCurrentIndex(0) 
152       
153       
154        filename = "%s/.palmrungui.default" % (palm_dir) 
155        if os.path.exists(filename):
156            pass
157        else:
158            return
159       
160        file = open(filename, "r")
161        if ( file is not None ):
162            # File opened successfully
163            palmrunline = file.readline()
164            #if neue zeile zeichen
165            palmrunline = palmrunline[:len(palmrunline)-1]
166            file.close() 
167
168        # In case a palmrunline was found, load it to mainwindow
169        if ( palmrunline != ""):
170            palmrunline = palmrunline[17:] 
171            commandline.setText(palmrunline)
172            self.setup_gui(palmrunline)
173
174
175
176   
177        QtGui.QApplication.processEvents()
178
179
180       
181    # starts xterm with palmrun commandline
182    #######################################
183    def startpalmrun(self):
184        palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text())
185        userline    = str(self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text())
186       
187        # Check for empty line
188        palmrunline_save = palmrunline
189        if (userline != ""):
190            palmrunline = "%s %s" % (palmrunline,userline)
191        history_line = palmrunline       
192       
193        # Disable the main window
194        self.tabWidget.setEnabled(False)
195        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False)
196        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False)
197        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("wait...")     
198        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText("Executing palmrun in xterm...")       
199       
200        # Wait until all commands have been executed (ugly) ?
201        #for i in range(0,21):
202        #    qApp->processEvents()       
203       
204        # Start xterm as QProcess
205        palmrun = QProcess()
206        palmrun.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels
207        palmrun.setWorkingDirectory(palm_dir)
208   
209        geomet = self.frameGeometry()
210       
211        posx = geomet.x()+geomet.width()
212        posy = geomet.y()
213     
214        s = " -title \"Executing palmrun...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy)
215        palmrunline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmrunline.replace("\"","\'"))
216       
217        mString = "xterm %s" % (palmrunline)
218        palmrun.start(mString)
219   
220        if( palmrun.waitForStarted() is False ):
221            return
222       
223        # Wait until palmrun has finished or wait for 200 minutes
224        palmrun.waitForFinished(3600000)       
225       
226        # Jobs has been submitted or aborted. Continuing...
227        # Save the palmrun command to history file
228        filename = "%s/.palmrungui.history" % (palm_dir)
229        tmstamp = strftime("%Y/%m/%d %H:%M")
230        tag = str(self.groupBox.findChild(QtGui.QLineEdit,"line_tag").text())
231   
232        file = open(filename,"a")
233        s = "%s %s (%s)\n" % (tmstamp,history_line,tag)
234        file.write(s)
235        file.close()             
236       
237        # Enable main window again
238        self.tabWidget.setEnabled(True)
239        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True)
240        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("palmrun") 
241        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline_save)
242        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
243       
244        # Reload recent jobs
245        self.recent_jobs(50)
246       
247       
248       
249    # starts xterm with palmbuild commandline
250    #######################################
251    def startpalmbuild(self):
252        palmbuildline = 'palmbuild -c ' + str(self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").currentText())
253       
254        palmrunline_save = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text())
255       
256        # Disable the main window
257        palmbuildline_save = palmbuildline
258        self.tabWidget.setEnabled(False)
259        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False)
260        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False) 
261        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("wait...") 
262        self.group_execution.findChild(QtGui.QPushButton,"button_palmbuild").setText("wait...") 
263        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText("Executing palmbuild in xterm...")       
264       
265        # Wait until all commands have been executed (ugly) ?
266        #for i in range(0,21):
267        #    qApp->processEvents()       
268       
269        # Start xterm as QProcess
270        palmbuild = QProcess()
271        palmbuild.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels
272        palmbuild.setWorkingDirectory(palm_dir)
273   
274        geomet = self.frameGeometry()
275       
276        posx = geomet.x()+geomet.width()
277        posy = geomet.y()
278     
279        s = " -title \"Executing palmbuild...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy)
280        palmbuildline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmbuildline.replace("\"","\'"))
281       
282        mString = "xterm %s" % (palmbuildline)
283        palmbuild.start(mString)
284   
285        if( palmbuild.waitForStarted() is False ):
286            return
287       
288        # Wait until palmbuild has finished or wait for 200 minutes
289        palmbuild.waitForFinished(3600000)       
290       
291         
292       
293        # Enable main window again
294        self.tabWidget.setEnabled(True)
295        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True)
296        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
297        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("palmrun") 
298        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline_save)
299        self.group_execution.findChild(QtGui.QPushButton,"button_palmbuild").setText("(re-)build")     
300        # Reload recent jobs
301        self.recent_jobs(50)
302
303    # loads recent jobs
304    ######################################
305    def recent_jobs(self, number):
306        fileDir = "%s/.palmrungui.history" % (palm_dir)
307        if os.path.exists(fileDir):
308            pass
309        else:
310            return
311       
312        file = open(fileDir,"r")
313        history = file.readlines()
314        tmphistory = list()
315        tmptag = list()
316        file.close()
317        j = 0
318
319        list_jobname = self.group_history.findChild(QtGui.QListWidget,"list_jobname")
320        list_jobname.clear()
321
322        # Read history entries and append to recent job list
323        i=len(history)-1
324        count = 0
325        while i>=0 and count<number:
326            timestamp = history[i][:16]
327            listitem = history[i][17:len(history[i])-1]
328            tagitem = listitem
329            matchitems = list_jobname.findItems(listitem, QtCore.Qt.MatchExactly)
330
331            if ( len(matchitems) == 0 ):
332                listitem = filter(None,listitem.split(" -r"))[1]
333                listitem = filter(None,listitem.split(" -"))[0]
334                listitem = listitem.replace(" ","") 
335                list_jobname.addItem(listitem)
336                s = "%s: %s" % (timestamp,listitem)
337                tmphistory.append(s)
338               
339               
340                tagitem = filter(None,tagitem.split(" ("))[1]
341                tagitem = tagitem.replace(")","") 
342                if ( len(tagitem) == 0 ): 
343                   s = "Tag: empty"
344                else:
345                   s = "Tag: %s" % (tagitem)               
346                tmptag.append(s)
347                count = count +1
348
349                j = j+1
350               
351            if ( j == number ):
352                break
353            i = i-1
354           
355        # Send to list
356        list_jobname.clear()
357       
358        i=0
359        while i<len(tmphistory):
360            list_jobname.addItem(tmphistory[i])
361            list_jobname.item(i).setToolTip(tmptag[i])
362            i = i+1
363           
364
365    # Enables coupled settings
366    ###############################
367    def enable_coupled(self):
368        coupledState = self.group_execution.findChild(QtGui.QComboBox, "drop_job").currentText()
369        group = self.group_execution.findChild(QtGui.QGroupBox, "group_coupled")
370       
371        if (coupledState == "Restart run (coupled atmosphere ocean)" or coupledState == "Initial run (coupled atmosphere ocean)"):
372            self.group_coupled.setEnabled(True)
373        else: 
374            self.group_coupled.setEnabled(False)
375           
376
377    # select a job via click from list
378    #################################
379    def choosejob_list(self):
380        #  Get selected item from list
381        list_jobname = self.group_history.findChild(QtGui.QListWidget,"list_jobname")
382        filename = str(list_jobname.currentItem().text())
383           
384        timestamp = filename[:16]
385        jobname = filename[18:]
386               
387        itemint = list_jobname.currentRow()
388
389        # Reload list
390        self.recent_jobs(50)
391        self.load_jobs()
392   
393        # Set selected item to jobname
394        list_jobname.item(itemint).setSelected(True)
395   
396        # Set selected item to jobname in "available jobs" list
397        item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
398       
399        if ( item2int != [] ):
400           self.list_jobs.setCurrentItem(item2int[0])
401        self.update_input()
402           
403   
404        fileDir = "%s/.palmrungui.history" % (palm_dir)
405        file = open(fileDir,"r")
406        history = file.readlines()
407        tmphistory = list()
408        file.close()       
409   
410        i = len(history)
411        while i>=1:
412            listitem = history[i-1][17:len(history[i-1])-1]
413            listitem = filter(None,listitem.split(" -r"))[1]
414            listitem = filter(None,listitem.split(" -"))[0]
415            listitem = listitem.replace(" ","") 
416
417            # Select command line with correct timestamp and jobname
418            if (history[i-1][:16] == timestamp and listitem == jobname):
419                palmrunline = history[i-1]
420                palmrunline = palmrunline[17:]
421                palmrunline = palmrunline[:len(palmrunline)-1]
422                palmrunline = filter(None,palmrunline.split("("))[0]
423                self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline)
424               
425             
426                tag = history[i-1].split('\n')[0]
427                tag = filter(None,tag.split("("))[1]
428                tag = tag.replace(")","")
429
430                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setText(tag)
431                self.setup_gui(palmrunline)
432                self.list_jobname.item(itemint).setSelected(True)   
433               
434                return
435            i = i-1
436               
437    # Change run identifer (initial, restart, coupled...)
438    ######################################################
439    def change_rc_list(self):
440        drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText()   
441        self.change_commandline("a","")
442   
443        # Enable PE distribution for atmosphere/ocean
444        if ( drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"):
445            drop_atmos = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text() 
446            drop_ocean = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text() 
447            s = "%s %s" % (drop_atmos,drop_ocean)
448            self.change_commandline("Y",s)
449   
450   
451        if ( drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"):
452           self.change_commandline("r","")
453
454        # Check of ocean runs
455        else:
456            self.delete_commandline("Y")
457            if (drop_job == "Precursor run (ocean)"):
458                self.activate_flag("y")
459            else:
460                self.deactivate_flag("y")
461           
462    # changes commandline depending on parameters
463    ##########################################################     
464    def change_commandline(self, id_str, fwt_str):
465        fwt_str = str(fwt_str) 
466        initialize = False
467        palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text())   
468        s = " -%s " % (id_str)
469        splitline = filter(None,palmrunline.split(s))
470
471        if ( len(splitline) == 0 ):
472                splitline.append("palmrun")
473                splitline.append(" ")
474                initialize = True
475
476        elif ( len(splitline) == 1 ):
477            splitline.append(" ")
478       
479        param = splitline[1].split("-")
480   
481        # Change in parameter "r" (jobname)
482        if (id_str == "r"):
483            filename = str(self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").text())
484            s = filename.split("JOBS/") 
485            param[0] = s[len(s)-1]
486     
487            if ( initialize == True ):#and self.group_runcontrol.isEnabled() == True ):
488                self.group_execution.setEnabled(True)
489                self.group_execution.findChild(QtGui.QComboBox,"drop_job").setEnabled(True)
490                self.group_advanced.setEnabled(True)
491                self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) 
492                self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True)
493                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
494           
495            elif ( param[0] == ""):           
496                self.group_execution.setEnabled(False)
497                self.group_execution.findChild(QtGui.QComboBox,"drop_job").setEnabled(False)
498                self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) 
499                self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False)
500                self.group_advanced.setEnabled(False)
501                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
502                self.delete_commandline("r")
503                self.change_commandline("a","remove")
504                return 1 
505           
506            else:
507
508                # Check if _p3dr file is available, otherwise notice user
509                drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText()
510                if ( self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState() == 2 or 
511                     drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"     ):
512
513                    jobname = self.group_execution.findChild(QtGui.QLineEdit, "line_jobname").text()
514                    restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname)
515
516                    if (os.path.exists(restartfile) == True):                 
517                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("")
518               
519
520                        if ( drop_job == "Restart run (coupled atmosphere ocean)" ):
521                            restartfileo = "%s/JOBS/%s/INPUT/%s_p3dor" % (palm_dir,jobname,jobname)
522                            if (os.path.exists(restartfileo) == True):                 
523                                self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("hooo")
524                 
525                            else:       
526                                self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dor file found!</font>")   
527               
528                    else:       
529                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file found!</font>")
530         
531               
532                       
533                self.group_execution.setEnabled(True)
534                self.drop_job.setEnabled(True)
535                self.group_advanced.setEnabled(True)
536                   
537        # Change in parameter "a" (run control list)
538        elif (id_str == "a"): 
539   
540            drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText()
541            rc_flag = "#"
542   
543            if (drop_job == "Initial run"):
544                rc_flag = "#"
545           
546            elif (drop_job == "Restart run"):           
547                rc_flag = "r"
548           
549            elif (drop_job == "Precursor run (atmosphere)"):           
550                rc_flag = "#"
551           
552            elif (drop_job == "Precursor run (ocean)"):           
553                rc_flag = "o#"
554
555            elif (drop_job == "Initial run (coupled atmosphere ocean)"):           
556                rc_flag = "#"
557           
558            elif (drop_job == "Restart run (coupled atmosphere ocean)"):           
559                rc_flag = "r"
560           
561            param[0] = "\"d3%s" % (rc_flag)
562   
563   
564            if (drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"):
565                if (rc_flag == "#"):
566                   rc_flag = "o#"
567                else:
568                   rc_flag = "or"
569
570                param[0] = "%s d3%s" % (param[0],rc_flag)
571   
572            status_restarts = self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState()
573
574            if (status_restarts == 2):
575                param[0]="%s restart" % (param[0])
576   
577                # Check if _p3dr file is available, otherwise notice user
578                if (status_restarts == 2):
579                    jobname = str(self.group_execution.findChild(QtGui.QLineEdit, "line_jobname").text())
580                    restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname)
581                    if (os.path.exists(restartfile) == True):                   
582                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("")
583                   
584                    else:                   
585                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file found!</font>")
586
587            else: 
588                self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("")
589
590            status_cycfill = self.group_execution.findChild(QtGui.QCheckBox,"check_cycfill").checkState()
591   
592            if (status_cycfill == 2):           
593                param[0]="%s fill" % (param[0])
594           
595            status_svf = self.group_execution.findChild(QtGui.QCheckBox,"check_svf").checkState()
596   
597            if (status_svf == 2):           
598                param[0]="%s svf" % (param[0])
599
600            param[0]="%s\"" % (param[0])
601 
602 
603            if ( fwt_str == "remove"):           
604                self.delete_commandline(id_str)
605                return 1
606           
607            else:           
608                self.button_start.setEnabled(True)
609                self.action_save.setEnabled(True)
610                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
611
612        # Change in any other parameter
613        else:
614            if ( fwt_str != ""):           
615                param[0] = "\"%s\"" % (fwt_str)
616           
617            else:           
618                self.delete_commandline(id_str)
619                return 1
620                       
621        # Join the new palmrunline
622        splitline[1]= " -".join(param)
623               
624               
625        s = " -%s " % (id_str)
626        newpalmrunline = s.join(splitline)
627   
628        # Pr the new palmrunline to mainwindow
629        newpalmrunline = newpalmrunline.replace("  "," ")
630        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(newpalmrunline)
631
632    # change lineinput depending on sender
633    ###################################################################################
634    def change_lineinput(self):
635        if ( self.sender() == self.group_execution.findChild(QtGui.QComboBox, "combo_configuration") ):
636            tmptext = self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").currentText()
637            if tmptext.isEmpty():
638               self.change_commandline("c"," ")
639               self.group_execution.findChild(QtGui.QPushButton,'button_palmbuild').setEnabled(False)
640            else:
641               self.change_commandline("c",tmptext)
642               self.group_execution.findChild(QtGui.QPushButton,'button_palmbuild').setEnabled(True)         
643
644        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_q")):
645            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_q").text()
646            self.change_commandline("q",tmptext)
647       
648        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_account")):
649            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_account").text()
650            self.change_commandline("A",tmptext)
651       
652        elif ( self.sender() ==  self.group_execution.findChild(QtGui.QLineEdit,"line_pe")):
653            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_pe").text()
654            self.change_commandline("X",tmptext)
655       
656        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_tpn")):
657            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").text()
658            self.change_commandline("T",tmptext)
659               
660        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_time")):
661            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_time").text()
662            self.change_commandline("t",tmptext)
663       
664        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_M")):
665            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_M").text()
666            self.change_commandline("M",tmptext)
667       
668        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_m")):
669            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_m").text()
670            self.change_commandline("m",tmptext)
671       
672        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_D")):
673            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_D").text()
674            self.change_commandline("D",tmptext)
675       
676        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_c")):
677            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_c").text()
678            if ( tmptext == ".palmrungui.config"):
679                tmptext = ""
680            self.change_commandline("c",tmptext)
681       
682        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_s")):
683            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_s").text()
684            self.change_commandline("s",tmptext)
685               
686        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_w")):
687            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_w").text()
688            self.change_commandline("w",tmptext)
689       
690        elif ( self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos") or 
691               self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean")):
692            t1 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text()
693            t2 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text()           
694            tmptext = "%s %s" % (t1,t2)
695           
696            self.change_commandline("Y",tmptext)
697
698            # try catch sowas in der art
699            pe1 = 0
700            pe2 = 0
701           
702            try:
703                pe1 = int(t1)
704            except ValueError:           
705                pass
706               
707            try:
708                pe2 = int(t2)
709            except ValueError:
710                pass
711               
712            PE_total = pe1+pe2   
713            self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(str(PE_total))
714            self.change_commandline("X",str(PE_total))
715         
716    # deletes parameter from commandline
717    #####################################################################################
718    def delete_commandline(self, id_str):   
719        # Read palmrunline
720        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
721        palmrunline = str(commandline.text())
722        s = " -%s" % (id_str)
723        splitline = filter(None,palmrunline.split(s))
724       
725        if ( len(splitline) == 1):
726            return 1
727        else:
728            param = splitline[1].split("-")
729            param[0] = ""
730            splitline[1]= " -".join(param)
731            newpalmrunline = "".join(splitline)
732            newpalmrunline = newpalmrunline.replace("  "," ")
733   
734            # Print new palmrunline to screen
735            commandline.setText(newpalmrunline)
736       
737    # controls flags
738    ###################################################################################
739    def check_flags(self):
740        status = self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files" ).checkState()
741        if (status == 2):     
742            self.activate_flag("B")
743        else:
744            self.deactivate_flag("B")
745   
746        status = self.group_execution.findChild(QtGui.QCheckBox,"check_verbose" ).checkState()
747        if (status == 2):
748            self.activate_flag("v") 
749        else:
750            self.deactivate_flag("v")
751       
752        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_b" ).checkState() 
753        if (status == 2):
754            self.activate_flag("b")
755        else:
756            self.deactivate_flag("b")
757   
758        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_F" ).checkState()   
759        if (status == 2):
760            self.activate_flag("F")
761        else:
762            self.deactivate_flag("F")
763           
764        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_I" ).checkState() 
765        if (status == 2):
766            self.activate_flag("I")
767        else:
768            self.deactivate_flag("I")
769
770        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_k" ).checkState() 
771        if (status == 2):
772            self.activate_flag("k")
773        else:
774            self.deactivate_flag("k")
775
776        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_O" ).checkState() 
777        if (status == 2):
778            self.activate_flag("O")
779        else:
780            self.deactivate_flag("O")
781
782        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_x" ).checkState() 
783        if (status == 2):
784            self.activate_flag("x")
785        else:
786            self.deactivate_flag("x")
787       
788        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_Z" ).checkState() 
789        if (status == 2):
790            self.activate_flag("Z")
791        else:
792            self.deactivate_flag("Z")
793       
794    # changes flag to parameter
795    ##################################################################################   
796    def activate_flag(self, id_str):
797        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
798        palmrunline = str(commandline.text())
799        s = " -%s" % (id_str)
800        splitline = filter(None,palmrunline.split(s))
801       
802        if ( len(splitline) == 1):
803            splitline.append("")
804            s = " -%s" % (id_str)
805            newpalmrunline = s.join(splitline)
806            newpalmrunline = newpalmrunline.replace("  "," ")
807            commandline.setText(newpalmrunline)               
808       
809    # deletes flag in commandline
810    ####################################################################################   
811    def deactivate_flag(self, id_str):
812        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
813        palmrunline = str(commandline.text())
814        s = " -%s" % (id_str)
815        splitline = filter(None,palmrunline.split(s))
816 
817        newpalmrunline = "".join(splitline)
818        newpalmrunline = newpalmrunline.replace("  "," ")
819        commandline.setText(newpalmrunline)     
820
821    # Clears window
822    #################################################################################
823    def reset_window(self):
824        self.setupUi(self)
825        self.tabWidget.setCurrentIndex(0)
826        self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))   
827        self.recent_jobs(50)
828        self.load_jobs()
829       
830    # Safes current commandline and user Parameters to .sav file
831    #################################################################################
832    def save_to_file(self):
833        user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text()
834        cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()
835       
836        string_to_file = cmd_string
837        if (user_string != ""): 
838            string_to_file = "%s%s" % (string_to_file,user_string)
839           
840        #filename = QtGui.QInputDialog.getText(self, "Save File naming Dialog", "Insert filename", QtGui.QLineEdit.Normal)
841        filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save File","filename.sav"))
842        extension = ".sav"
843        filename = "%s%s" % (filename, "")
844        tmstamp = strftime("%Y/%m/%d %H:%M")
845       
846        file = open(filename,"w")
847        s = "%s %s" % (tmstamp, string_to_file)
848        file.write(s)
849        file.close()
850       
851    # Safes current commandline and user parameters to default file
852    ################################################################################
853    def save_default(self):
854        user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text()
855        cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()
856       
857        string_to_file = cmd_string
858        if (user_string != ""): 
859            string_to_file = "%s%s" % (string_to_file,user_string)
860       
861        filename ="%s/.palmrungui.default" % (palm_dir)
862        tmstamp = strftime("%Y/%m/%d %H:%M")
863       
864        file = open(filename,"w")
865        s = "%s %s" % (tmstamp, string_to_file)
866        file.write(s)
867        file.close()       
868
869       
870    # Executes command which starts watchdog (start palm_wd)
871    ########################################################
872    def start_watchdog(self):
873        subprocess.Popen(["nohup","palm_wd",">>","/dev/null", "2>&1","&"])
874
875    # Opens "help" dialog
876    #################################
877    def help(self):       
878        dialog = HelpDialog()
879        dialog.exec_()
880
881    # Opens "about" dialog
882    ##################################
883    def about_gui(self):
884        dialog = AboutDialog()
885        dialog.exec_()
886
887    # commandline to buttons etc
888    ##############################
889    def setup_gui(self, palmrun_str): 
890     
891        #self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))   
892     
893        #  Some initial settings
894        user = "" 
895        coupled_run = False 
896        ocean_run   = False 
897        nojob       = False 
898
899        #Split parameters in palmrunline
900        splitline = palmrun_str.split(" -")
901       
902        if ( splitline[0] != "palmrun"):
903            return 1
904
905        else:
906            self.group_execution.setEnabled(True) 
907
908        # Loop for all parameters in palmrunline
909        i = len(splitline)-1
910        while i >= 1:
911
912            # Determine parameter
913            splitparameter = splitline[i].split(" ")
914
915            parameter = splitparameter[0] 
916            splitparameter.pop(0)
917            options = " ".join(splitparameter) 
918            options = options.replace("\"","") 
919
920            # Check for suitable switch
921            if ( parameter == "r"):
922             
923                if ( options != ""):
924                    self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").setText(options) 
925                    nojob = False 
926               
927                else:                 
928                    nojob = True 
929               
930            elif ( parameter == "c"):
931                tmpindex = self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").findText(options,QtCore.Qt.MatchExactly)
932                if tmpindex != -1: 
933                   self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").setCurrentIndex(tmpindex)
934                else:
935                   self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").setCurrentIndex(0)
936            elif ( parameter == "q"):
937                self.group_execution.findChild(QtGui.QLineEdit,"line_q").setText(options) 
938             
939            elif ( parameter == "A"):
940                self.group_execution.findChild(QtGui.QLineEdit,"line_account").setText(options) 
941             
942            elif ( parameter == "X"):
943                self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(options) 
944             
945            elif ( parameter == "T"):
946                self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").setText(options) 
947             
948            elif ( parameter == "t"):
949                self.group_execution.findChild(QtGui.QLineEdit,"line_time").setText(options) 
950             
951            elif ( parameter == "B"):
952                self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files").setChecked(True) 
953             
954            elif ( parameter == "v"):
955                self.group_execution.findChild(QtGui.QCheckBox,"check_verbose").setChecked(True) 
956                         
957            elif ( parameter == "b"): 
958                self.group_advanced.findChild(QtGui.QCheckBox,"check_b").setChecked(True) 
959             
960            elif ( parameter == "F"):
961                self.group_advanced.findChild(QtGui.QCheckBox,"check_F").setChecked(True) 
962             
963            elif ( parameter == "I"):
964                self.group_advanced.findChild(QtGui.QCheckBox,"check_I").setChecked(True) 
965             
966            elif ( parameter == "k"):
967                self.group_advanced.findChild(QtGui.QCheckBox,"check_k").setChecked(True) 
968             
969            elif ( parameter == "O"): 
970                self.group_advanced.findChild(QtGui.QCheckBox,"check_O").setChecked(True) 
971             
972            elif ( parameter == "x"):             
973                self.group_advanced.findChild(QtGui.QCheckBox,"check_x").setChecked(True) 
974             
975            elif ( parameter == "Z"):
976                self.group_advanced.findChild(QtGui.QCheckBox,"check_Z").setChecked(True) 
977               
978            elif ( parameter == "m"):
979                self.group_advanced.findChild(QtGui.QLineEdit,"line_m").setText(options) 
980             
981            elif ( parameter == "M"):
982                self.group_advanced.findChild(QtGui.QLineEdit,"line_M").setText(options) 
983                         
984            elif ( parameter == "D"):
985                self.group_advanced.findChild(QtGui.QLineEdit,"line_D").setText(options) 
986             
987            elif ( parameter == "c"):
988                self.group_advanced.findChild(QtGui.QLineEdit,"line_c").setText(options) 
989                         
990            elif ( parameter == "s"):
991                self.group_advanced.findChild(QtGui.QLineEdit,"line_s").setText(options) 
992             
993            elif ( parameter == "w"):
994                self.group_advanced.findChild(QtGui.QLineEdit,"line_w").setText(options) 
995             
996
997            # Determine settings for coupled restart runs
998            elif ( parameter == "Y"):
999                optionssplit = options.split(" ") 
1000               
1001                group_coupled = self.group_execution.findChild(QtGui.QGroupBox,"group_coupled")
1002                group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(True) 
1003                group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(True) 
1004                group_coupled.findChild(QtGui.QLabel,"label_coupled1").setEnabled(True) 
1005                group_coupled.findChild(QtGui.QLabel,"label_coupled2").setEnabled(True) 
1006                group_coupled.findChild(QtGui.QLabel,"label_coupled3").setEnabled(True) 
1007                group_coupled.findChild(QtGui.QLabel,"label_coupling").setEnabled(True) 
1008
1009                if (optionssplit.count() == 2):
1010                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(optionssplit[0]) 
1011                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(optionssplit[1])
1012                 
1013                else:                 
1014                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setText("") 
1015                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setText("") 
1016 
1017                 
1018                coupled_run = True 
1019           
1020            elif ( parameter == "y"):             
1021                self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) 
1022             
1023
1024            # Determine settings for the run control list
1025            elif ( parameter == "a"):
1026             
1027                optionssplit = options.split(" ") 
1028
1029                options_2 = None
1030                options_all = None
1031               
1032                j = 0
1033                while j < len(optionssplit):
1034                 
1035                    options_all = optionssplit[j] 
1036                    options_2 = optionssplit[j][:2] 
1037                                             
1038                    if (options_2 == "d3"):     
1039                        if (options_all[:3][-1] == "#"):
1040                            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(0) 
1041                        elif (options_all[:3][-1] == "r"):
1042                            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(1) 
1043                       
1044                        elif (options_all[:3][-1] == "o"):
1045                            ocean_run = True 
1046                       
1047                    if (options_all == "restart"):
1048                        self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").setChecked(True) 
1049                        # Check if _pdf file is available, otherwise notice user
1050                        jobname = str(self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").text()) 
1051                       
1052                        restartfile = "%sJOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname)
1053                        if (os.path.exists(restartfile) == True):   
1054                            self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") 
1055                       
1056                        else:
1057                            self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file \found!</font>") 
1058                    j = j+1
1059
1060            # All unknown parameters are set as extra user parameters
1061            else: 
1062                print parameter
1063                user = "%s-%s \"%s\" " % (user,parameter,options)
1064                splitline.removeAt(i) 
1065
1066            i = i-1
1067        # Change drop box state in case of ocean precursor or coupled restart runs
1068        if ( ocean_run == True ):
1069            if ( coupled_run == True ):
1070                self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(4) 
1071           
1072            else:
1073                self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) 
1074
1075        if ( user != ""):
1076            self.group_advanced.findChild(QtGui.QLineEdit,"line_user").setText(user)
1077
1078        # Join palmrunline and post it to mainwindow
1079        palmrunline = " -".join(splitline) 
1080        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline)         
1081
1082        # Disable mainwindow if no job was found, otherwise enable
1083        if ( nojob == True ):
1084            self.group_execution.setEnabled(False) 
1085            self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) 
1086            self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False) 
1087            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setEnabled(False) 
1088            self.group_advanced.setEnabled(False) 
1089            self.check_advanced.setEnabled(False) 
1090            self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False)
1091         
1092        else:
1093            self.group_execution.setEnabled(True) 
1094            self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) 
1095            self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True)
1096            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setEnabled(True) 
1097            self.group_advanced.setEnabled(True) 
1098            self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
1099         
1100        self.tabWidget.setCurrentIndex(0)
1101         
1102    # open saved commandline
1103    ##################################
1104    def open_from_file(self):
1105       
1106        # Select filename and open it
1107        filename = QtGui.QFileDialog.getOpenFileName(self, "Open File","Save files (*.sav)") 
1108       
1109        if ( filename != ""):
1110            file = open(filename, "r")
1111         
1112            if ( file is not None ):
1113                # File opened successfully
1114                palmrunline = file.read()
1115                file.close() 
1116   
1117            # In case a palmrunline was found, load it to mainwindow
1118            if ( palmrunline != ""):
1119                palmrunline = palmrunline[17:] 
1120                self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) 
1121                self.setup_gui(palmrunline)
1122         
1123    # open saved commandline   
1124    ##################################
1125    def open_last(self): 
1126        # Select filename and open it
1127        filename = "%s/.palmrungui.history" % (palm_dir)
1128       
1129        if os.path.exists(filename):
1130            pass
1131        else:
1132            return
1133       
1134        file = open(filename, "r") 
1135        if ( file is not None ):
1136            # File opened successfully
1137            lines = file.readlines()
1138            palmrunline = lines[len(lines)-1]
1139            palmrunline = palmrunline[:len(palmrunline)-1]
1140            file.close() 
1141
1142        # In case a palmrunline was found, load it to mainwindow
1143        if ( palmrunline != ""):
1144            palmrunline = palmrunline[17:len(palmrunline)] 
1145            self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) 
1146            self.setup_gui(palmrunline)       
1147
1148 
1149   
1150    def update_all(self):
1151 
1152       self.setEnabled(False)
1153       self.list_input.clear() 
1154       self.list_user.clear()
1155       self.list_monitoring.clear()
1156       self.list_output.clear()
1157       self.load_jobs()
1158       self.setEnabled(True)
1159       self.update_input()
1160
1161    # Load jobs into list
1162    def load_jobs(self):
1163       
1164       selected_job = self.list_jobs.currentItem()
1165       
1166       if ( selected_job is not None ):
1167          jobname = selected_job.text()
1168       else:
1169          jobname = ""
1170
1171       self.list_jobs.clear() 
1172       self.push_copy.setEnabled(False)
1173       self.push_create_set.setEnabled(False)     
1174     
1175       self.line_path.setText(job_dir + "/")
1176       
1177       list_of_files = os.listdir(job_dir)
1178     
1179
1180       for i in range(0,len(list_of_files)):
1181          tmp_file = job_dir + "/" + list_of_files[i]
1182
1183          if ( os.path.isdir(tmp_file) ):
1184             self.list_jobs.addItem(str(list_of_files[i]))
1185       
1186
1187
1188       item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
1189       
1190       if ( item2int != [] ):
1191          self.list_jobs.setCurrentItem(item2int[0])
1192
1193
1194    # Update input and user code lists
1195    def update_input(self):
1196     
1197       self.list_input.clear() 
1198       self.list_user.clear()
1199       self.list_monitoring.clear()
1200       self.list_output.clear()
1201       self.push_copy.setEnabled(True)
1202       self.push_create_set.setEnabled(True)
1203     
1204       job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/INPUT"
1205
1206       if ( os.path.isdir(job_to_show) ):
1207
1208          list_of_files = os.listdir(job_to_show)
1209         
1210          for i in range(0,len(list_of_files)):
1211             tmp_file = job_to_show + "/" + list_of_files[i]
1212             
1213             if ( os.path.isfile(tmp_file) ):
1214                self.list_input.addItem(str(list_of_files[i]))
1215 
1216       job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/USER_CODE"
1217       
1218       if ( os.path.isdir(job_to_show) ):
1219         
1220          list_of_files = os.listdir(job_to_show)
1221         
1222          for i in range(0,len(list_of_files)):
1223             tmp_file = job_to_show + "/" + list_of_files[i]
1224
1225             if ( os.path.isfile(tmp_file) ):
1226                self.list_user.addItem(str(list_of_files[i]))
1227
1228       job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/MONITORING"
1229       
1230       if ( os.path.isdir(job_to_show) ):
1231         
1232          list_of_files = os.listdir(job_to_show)
1233         
1234          for i in range(0,len(list_of_files)):
1235             tmp_file = job_to_show + "/" + list_of_files[i]
1236
1237             if ( os.path.isfile(tmp_file) ):
1238                self.list_monitoring.addItem(str(list_of_files[i]))
1239
1240       job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/OUTPUT"
1241       
1242       if ( os.path.isdir(job_to_show) ):
1243         
1244          list_of_files = os.listdir(job_to_show)
1245         
1246          for i in range(0,len(list_of_files)):
1247             tmp_file = job_to_show + "/" + list_of_files[i]
1248
1249             if ( os.path.isfile(tmp_file) ):
1250                self.list_output.addItem(str(list_of_files[i]))
1251 
1252       self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").setText(self.list_jobs.currentItem().text())
1253       self.group_history.findChild(QtGui.QListWidget,"list_jobname").clearSelection()
1254
1255       # Change palmrunline accordingly
1256       self.change_commandline("r","")
1257       self.change_commandline("a","")
1258 
1259 
1260    # Make a copy of a job
1261    def copy_job(self):
1262 
1263       self.setEnabled(False)
1264       old_job_name = self.list_jobs.currentItem().text()
1265       
1266       text, ret = QtGui.QInputDialog.getText(self, "Copy job", "Enter new job name:", mode = QtGui.QLineEdit.Normal, text = old_job_name)
1267       
1268       if ( ret ):
1269          new_job_name = str(text)
1270       else:
1271           self.setEnabled(True)
1272           return
1273         
1274       new_input_dir  = job_dir + "/" + new_job_name + "/INPUT"
1275
1276#      check if a job exists with the new job name 
1277       if ( os.path.isdir(new_input_dir) ):
1278           notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1279           self.setEnabled(True)
1280           return
1281       else:
1282           os.makedirs(new_input_dir)
1283
1284#      copy and rename input files (if present)       
1285       job_to_copy = job_dir + "/" + old_job_name + "/INPUT"
1286
1287       if ( os.path.isdir(job_to_copy) ):
1288
1289          list_of_files = os.listdir(job_to_copy)
1290         
1291          for i in range(0,len(list_of_files)):
1292
1293             tmp_file = job_to_copy + "/" + list_of_files[i]         
1294             new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name)
1295             shutil.copy(tmp_file, new_file)
1296
1297
1298
1299
1300       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1301       
1302#      check if user code exists in the new job directory
1303       if ( os.path.isdir(new_user_dir) ):
1304           notify = QtGui.QMessageBox.warning(self,'Create new user code directory',"Error. Could not create user code directory. A user code directiory with the new name already exists.")
1305           self.setEnabled(True)
1306           return
1307       else:
1308           os.makedirs(new_user_dir)
1309
1310
1311#      copy user code files (if present)       
1312       user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE"
1313
1314       if ( os.path.isdir(user_to_copy) ):
1315
1316          list_of_files = os.listdir(user_to_copy)
1317         
1318          for i in range(0,len(list_of_files)):
1319
1320             tmp_file = user_to_copy + "/" + list_of_files[i]         
1321             new_file = new_user_dir + "/" + list_of_files[i]
1322             shutil.copy(tmp_file, new_file)
1323
1324       self.load_jobs()
1325       self.list_input.clear() 
1326       self.list_user.clear()
1327       self.list_monitoring.clear()
1328       self.list_output.clear()
1329       self.setEnabled(True)
1330
1331
1332    # Create a whole set of jobs
1333    def create_set(self):
1334 
1335       global set_list
1336#      disable mainwindow 
1337       self.setEnabled(False)
1338     
1339#      show Options Dialog     
1340       opt = CreateSetBox()
1341       opt.exec_()
1342
1343       old_job_name = self.list_jobs.currentItem().text()
1344
1345       for j in range(0,len(set_list)):
1346
1347          if ( set_list[j] != "" ):
1348             new_job_name   = str(set_list[j])
1349             new_input_dir  = job_dir + "/" + str(set_list[j]) + "/INPUT"
1350          else:
1351             continue
1352
1353#         check if a job exists with the new job name 
1354          if ( os.path.isdir(new_input_dir) ):
1355             notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1356             self.setEnabled(True)
1357             return
1358          else:
1359             os.makedirs(new_input_dir)
1360
1361#         copy and rename input files (if present)       
1362          job_to_copy = job_dir + "/" + old_job_name + "/INPUT"
1363
1364          if ( os.path.isdir(job_to_copy) ):
1365
1366             list_of_files = os.listdir(job_to_copy)
1367         
1368             for i in range(0,len(list_of_files)):
1369
1370                tmp_file = job_to_copy + "/" + list_of_files[i]         
1371                new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name)
1372                shutil.copy(tmp_file, new_file)
1373
1374
1375          new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1376       
1377#         check if user code exists in the new job directory
1378          if ( os.path.isdir(new_user_dir) ):
1379              notify = QtGui.QMessageBox.warning(self,'Create new user code directory',"Error. Could not create user code directory. A user code directiory with the new name already exists.")
1380              self.setEnabled(True)
1381              return
1382          else:
1383              os.makedirs(new_user_dir)
1384
1385
1386#         copy user code files (if present)       
1387          user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE"
1388
1389          if ( os.path.isdir(user_to_copy) ):
1390
1391             list_of_files = os.listdir(user_to_copy)
1392         
1393             for i in range(0,len(list_of_files)):
1394
1395                tmp_file = user_to_copy + "/" + list_of_files[i]         
1396                new_file = new_user_dir + "/" + list_of_files[i]
1397                shutil.copy(tmp_file, new_file)
1398
1399          self.load_jobs()
1400          self.list_input.clear() 
1401          self.list_user.clear()
1402          self.list_monitoring.clear()
1403          self.list_output.clear()
1404
1405       self.setEnabled(True) 
1406       set_list = []
1407   
1408 # Add a custom context menu
1409    def openmenuinput(self, position):
1410
1411        menu = QtGui.QMenu()
1412
1413        selection = self.list_input.selectedItems()
1414       
1415        if ( len(selection) != 0 ):
1416
1417           openAction = menu.addAction('Open selected files')     
1418           openAction.setStatusTip('Open file(s) in your favorite editor')
1419           openAction.triggered.connect(self.OpenFilesInput)
1420           action = menu.exec_(self.list_input.mapToGlobal(position))
1421
1422 # Add a custom context menu
1423    def openmenuuser(self, position):
1424
1425        menu = QtGui.QMenu()
1426
1427        selection = self.list_user.selectedItems()
1428       
1429        if ( len(selection) != 0 ):
1430
1431           openAction = menu.addAction('Open selected files')     
1432           openAction.setStatusTip('Open file(s) in your favorite editor')
1433           openAction.triggered.connect(self.OpenFilesUser)
1434           action = menu.exec_(self.list_user.mapToGlobal(position))
1435
1436 # Add a custom context menu
1437    def openmenuoutput(self, position):
1438
1439        menu = QtGui.QMenu()
1440
1441        selection = self.list_output.selectedItems()
1442       
1443        if ( len(selection) != 0 ):
1444
1445           openAction = menu.addAction('Open selected files')     
1446           openAction.setStatusTip('Open file(s) in your favorite editor')
1447           openAction.triggered.connect(self.OpenFilesOutput)
1448           action = menu.exec_(self.list_output.mapToGlobal(position))
1449
1450 # Add a custom context menu
1451    def openmenumonitoring(self, position):
1452
1453        menu = QtGui.QMenu()
1454
1455        selection = self.list_monitoring.selectedItems()
1456       
1457        if ( len(selection) != 0 ):
1458
1459           openAction = menu.addAction('Open selected files')     
1460           openAction.setStatusTip('Open file(s) in your favorite editor')
1461           openAction.triggered.connect(self.OpenFilesMonitoring)
1462           action = menu.exec_(self.list_monitoring.mapToGlobal(position))
1463
1464    def OpenFilesInput(self):
1465   
1466       sel_job = self.list_jobs.currentItem().text()
1467       sel_files = self.list_input.selectedItems()
1468       
1469       input_dir = job_dir + "/" + sel_job + "/INPUT/"
1470       
1471       open_files = ""
1472       for i in range(0,len(sel_files)):
1473          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1474
1475       os.system(str(open_files))
1476
1477    def OpenFilesUser(self):
1478   
1479       sel_job = self.list_jobs.currentItem().text()
1480       sel_files = self.list_user.selectedItems()
1481       
1482       input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
1483       
1484       open_files = ""
1485       for i in range(0,len(sel_files)):
1486          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1487
1488       os.system(str(open_files)) 
1489       selection = self.list_jobs.selectedItems()
1490 
1491    def OpenFilesMonitoring(self):
1492   
1493       sel_job = self.list_jobs.currentItem().text()
1494       sel_files = self.list_monitoring.selectedItems()
1495       
1496       input_dir = job_dir + "/" + sel_job + "/MONITORING/"
1497       
1498       open_files = ""
1499       for i in range(0,len(sel_files)):
1500          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1501
1502       os.system(str(open_files)) 
1503       selection = self.list_jobs.selectedItems()
1504 
1505    def OpenFilesOutput(self):
1506   
1507       sel_job = self.list_jobs.currentItem().text()
1508       sel_files = self.list_output.selectedItems()
1509       
1510       input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
1511       
1512       open_files = ""
1513       for i in range(0,len(sel_files)):
1514          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1515
1516       os.system(str(open_files)) 
1517       selection = self.list_jobs.selectedItems()
1518 
1519# Message box for showing RUN_CONTROL output
1520class CreateSetBox(QtGui.QDialog):
1521    def __init__(self):
1522     
1523        super(CreateSetBox, self).__init__()
1524       
1525        uic.loadUi(palm_bin + '/palmrungui_files/create_set.ui', self)
1526       
1527        self.show()
1528       
1529        return
1530
1531#   Cancel button
1532    def rejected(self):
1533     
1534       self.close()
1535     
1536       return
1537 
1538
1539#   OK button
1540    def accept(self):
1541     
1542       global set_list
1543       
1544       text = self.list.toPlainText() 
1545       set_list = text.split('\n')
1546       self.close()
1547     
1548       return
1549
1550
1551       
1552
1553if __name__ == "__main__":
1554    app = QtGui.QApplication(sys.argv)
1555    window = Mainwindow()
1556    window.show()
1557    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.