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