Ignore:
Timestamp:
Apr 1, 2020 1:17:50 PM (4 years ago)
Author:
maronga
Message:

added functionality to create new jobs and delete multiple files in palmrungui

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SCRIPTS/palmrungui

    r4481 r4482  
    2525# -----------------
    2626# $Id$
     27# Added possibility to delete all files in a directory and option to create
     28# blank new jobs
     29#
     30# 4481 2020-03-31 18:55:54Z maronga
    2731# Bugfixes: - reading history lines discard button caused error message
    2832#           - deleting of USER_CODE files did not work
     
    12631267       self.change_commandline("a","") 
    12641268
     1269    # Create a new (empty) job
     1270    def create_new_job(self):
     1271
     1272       self.setEnabled(False)
     1273
     1274       text, ret = QtGui.QInputDialog.getText(self, "Create new job", "Enter new job name:", mode = QtGui.QLineEdit.Normal, text = '')
     1275
     1276       if ( ret ):
     1277          new_job_name = str(text)
     1278       else:
     1279          self.setEnabled(True)
     1280          return
     1281
     1282       new_input_dir  = job_dir + "/" + new_job_name + "/INPUT"
     1283
     1284#      check if a job exists with the new job name. If not, the new job is created and an empty _p3d file is created.
     1285       if ( os.path.isdir(new_input_dir) ):
     1286          notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
     1287          self.setEnabled(True)
     1288          return
     1289       else:
     1290          os.makedirs(new_input_dir)
     1291          os.mknod(new_input_dir + '/' + new_job_name + '_p3d')
     1292
     1293#      write default namelists into _p3d file
     1294       filename = open(new_input_dir + '/' + new_job_name + '_p3d', "w")
     1295       filename.write('&initialization_parameters\n    nx = 39,\n    ny = 39,\n    nz = 40,\n    dx = 50.0,\n    dy = 50.0,\n    dz = 50.0,\n/\n\n')
     1296       filename.write('&runtime_parameters\n    end_time = 3600.0,\n/\n')
     1297       filename.close()
     1298
     1299
     1300#      create empty USER_CODE folder for convenience
     1301       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
     1302       os.makedirs(new_user_dir)
     1303
     1304
     1305       self.load_jobs()
     1306       self.list_input.clear()
     1307       self.list_user.clear()
     1308       self.list_monitoring.clear()
     1309       self.list_output.clear()
     1310       self.setEnabled(True)
     1311
     1312
    12651313    # Make a copy of a job
    12661314    def copy_job(self):
     
    12931341
    12941342          list_of_files = os.listdir(job_to_copy)
    1295          
     1343
    12961344          for i in range(0,len(list_of_files)):
    12971345
     
    13041352
    13051353       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
    1306        
     1354
    13071355#      check if user code exists in the new job directory
    13081356       if ( os.path.isdir(new_user_dir) ):
     
    14171465        menu = QtGui.QMenu()
    14181466
     1467
     1468        newAction = QtGui.QAction('Create new job', self)
     1469        newAction.triggered.connect(self.create_new_job)
     1470        menu.addAction(newAction)
    14191471        selection = self.list_jobs.selectedItems()
    14201472
    14211473        if ( len(selection) != 0 ):
     1474
    14221475
    14231476           copyAction = QtGui.QAction('Copy job', self)
     
    14321485           menu.addAction(delAction)
    14331486
    1434            action = menu.exec_(self.list_jobs.mapToGlobal(position))
    1435        
    1436        
     1487        action = menu.exec_(self.list_jobs.mapToGlobal(position))
     1488
    14371489 # Add a custom context menu
    14381490    def openmenuinput(self, position):
     
    14501502
    14511503
    1452            delAction = QtGui.QAction('Delete file(s)', self)
     1504           delAction = QtGui.QAction('Delete selected file(s)', self)
    14531505           delAction.triggered.connect(self.DeleteFilesInput)
    14541506
     
    14561508           menu.addAction(delAction)
    14571509
    1458            action = menu.exec_(self.list_input.mapToGlobal(position))
     1510        delallAction = QtGui.QAction('Delete all files', self)
     1511        delallAction.triggered.connect(self.DeleteAllFilesInput)
     1512        menu.addAction(delallAction)
     1513
     1514        action = menu.exec_(self.list_input.mapToGlobal(position))
    14591515
    14601516 # Add a custom context menu
     
    14771533           menu.addAction(openAction)
    14781534           menu.addAction(delAction)
    1479            action = menu.exec_(self.list_user.mapToGlobal(position))
     1535
     1536        delallAction = QtGui.QAction('Delete all files', self)
     1537        delallAction.triggered.connect(self.DeleteAllFilesUser)
     1538        menu.addAction(delallAction)
     1539
     1540        action = menu.exec_(self.list_user.mapToGlobal(position))
    14801541
    14811542 # Add a custom context menu
     
    14851546
    14861547        selection = self.list_output.selectedItems()
    1487        
     1548
    14881549        if ( len(selection) != 0 ):
    14891550
     
    14921553           openAction.triggered.connect(self.OpenFilesOutput)
    14931554
    1494 
    14951555           delAction = QtGui.QAction('Delete file(s)', self)
    14961556           delAction.triggered.connect(self.DeleteFilesOutput)
    14971557
     1558
     1559
    14981560           menu.addAction(openAction)
    14991561           menu.addAction(delAction)
    1500            action = menu.exec_(self.list_output.mapToGlobal(position))
     1562
     1563        delallAction = QtGui.QAction('Delete all files', self)
     1564        delallAction.triggered.connect(self.DeleteAllFilesOutput)
     1565        menu.addAction(delallAction)
     1566
     1567        action = menu.exec_(self.list_output.mapToGlobal(position))
    15011568
    15021569 # Add a custom context menu
     
    15131580           openAction.triggered.connect(self.OpenFilesMonitoring)
    15141581
    1515 
    15161582           delAction = QtGui.QAction('Delete file(s)', self)
    15171583           delAction.triggered.connect(self.DeleteFilesMonitoring)
    15181584
     1585
     1586
    15191587           menu.addAction(openAction)
    15201588           menu.addAction(delAction)
    1521            action = menu.exec_(self.list_monitoring.mapToGlobal(position))
     1589
     1590        delallAction = QtGui.QAction('Delete all files', self)
     1591        delallAction.triggered.connect(self.DeleteAllFilesMonitoring)
     1592        menu.addAction(delallAction)
     1593
     1594        action = menu.exec_(self.list_monitoring.mapToGlobal(position))
    15221595
    15231596    def OpenConfig(self):
     
    16551728          self.update_all()
    16561729
     1730
     1731    def DeleteAllFilesInput(self):
     1732
     1733       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
     1734
     1735       if status == QtGui.QMessageBox.Yes:
     1736
     1737          check = self.list_jobs.currentItem()
     1738          if ( check ):
     1739             sel_job = self.list_jobs.currentItem().text()
     1740             sel_files = self.list_input.selectedItems()
     1741
     1742             input_dir = job_dir + "/" + sel_job + "/INPUT/"
     1743
     1744             if os.path.exists(str(input_dir)):
     1745                shutil.rmtree(str(input_dir))
     1746                os.makedirs(str(input_dir))
     1747
     1748                self.update_all()
     1749
     1750
     1751    def DeleteAllFilesUser(self):
     1752
     1753       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
     1754
     1755       if status == QtGui.QMessageBox.Yes:
     1756
     1757          check = self.list_jobs.currentItem()
     1758          if ( check ):
     1759             sel_job = self.list_jobs.currentItem().text()
     1760             sel_files = self.list_input.selectedItems()
     1761
     1762             input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
     1763
     1764             if os.path.exists(str(input_dir)):
     1765                shutil.rmtree(str(input_dir))
     1766                os.makedirs(str(input_dir))
     1767
     1768                self.update_all()
     1769
     1770
     1771
     1772    def DeleteAllFilesOutput(self):
     1773
     1774       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
     1775
     1776       if status == QtGui.QMessageBox.Yes:
     1777
     1778          check = self.list_jobs.currentItem()
     1779          if ( check ):
     1780             sel_job = self.list_jobs.currentItem().text()
     1781             sel_files = self.list_input.selectedItems()
     1782
     1783             input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
     1784
     1785             if os.path.exists(str(input_dir)):
     1786                shutil.rmtree(str(input_dir))
     1787                os.makedirs(str(input_dir))
     1788
     1789                self.update_all()
     1790
     1791
     1792
     1793    def DeleteAllFilesMonitoring(self):
     1794
     1795       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
     1796
     1797       if status == QtGui.QMessageBox.Yes:
     1798
     1799          check = self.list_jobs.currentItem()
     1800          if ( check ):
     1801             sel_job = self.list_jobs.currentItem().text()
     1802             sel_files = self.list_input.selectedItems()
     1803
     1804             input_dir = job_dir + "/" + sel_job + "/MONITORING/"
     1805
     1806             if os.path.exists(str(input_dir)):
     1807                shutil.rmtree(str(input_dir))
     1808                os.makedirs(str(input_dir))
     1809
     1810                self.update_all()
     1811
     1812
     1813
    16571814    def DeleteJob(self):
    16581815
Note: See TracChangeset for help on using the changeset viewer.