def ok_return(self):
        # print "Now printing the state......."
        # for key in self.media_dict.keys():
        #     print key, str(self.media_dict[key])

        # now check and add the tapes to the database
        for media in self.media_list:
            if self.media_dict[str(media.media_label + " : " +
                                   media.reel_no)] == True:
                # check if this entry already exists in db
                if media.shipment_no is None:
                    print "Now creating association for deliverable: " + self.deliverable.name + " set no: " + str(
                        self.set_no) + " media : " + media.media_label
                    self.create_new_association(media.t_id)
                else:
                    print "This media already belongs to a deliverable, press y to set the last one to bad and the current one to good"
                    status = get_item_through_dialogue(
                        self,
                        "This media already belongs to a deliverable, press y to set the last one to bad and the current one to good press y to continue"
                    )
                    if status == 'y':
                        self.change_and_create_association(
                            media.t_id, media.media_label)
                    else:
                        pass

        self.close()
Exemple #2
0
 def get_user_name(self):
     username = get_item_through_dialogue(self.parent.parent,
                                          'Type username or exit to exit')
     if len(username) == 0:
         message = "Plese enter a valid username!"
         self.pop_up_message_box = pop_up_message_box(message=message,
                                                      type="Critical")
         self.pop_up_message_box.closed.connect(self.get_user_name)
         self.pop_up_message_box.show()
     else:
         return username
 def get_verified_tape_drive(self, GUI_object):
     top_message = 'Tape drive'
     message = 'Please enter the tape drive name'
     typed_tape_drive = get_item_through_dialogue(GUI_object, top_message)
     if typed_tape_drive is not None:
         if typed_tape_drive in self.tape_service.available_dst:
             self.set_tape_drive(typed_tape_drive)
             return True
         else:
             logger.warning("The specified tape drive does not exist")
             self.get_verified_tape_drive(GUI_object)
 def get_verified_set(self, GUI_object):
     top_message = "Set number"
     message = "Please enter the set number"
     typed_set_number = get_item_through_dialogue(GUI_object, top_message)
     if typed_set_number is not None:
         if int(typed_set_number) in range(1,
                                           int(self.deliverable.copies) +
                                           1):
             self.set_working_set(typed_set_number)
             return True
         else:
             logger.warning("The entered set number is not in range")
             self.get_verified_set(GUI_object)
 def set_attribute(self, attribute, caller, ops):
     if ops == 'SEGD_QC_report':
         if caller == 'Deliverable':
             self.deliverable = self.disp_name_dict[attribute]
             self.no_of_sets = self.deliverable.copies
             self.file_name = str(self.deliverable.id) + "_" + str(
                 datetime.datetime.now().strftime(
                     "%Y%m%d")) + "_SEGD_QC_report.xlsx"
             self.file_path = os.path.join(os.getcwd(), Report_dir,
                                           self.file_name)
             if os.path.exists(self.file_path):
                 print "A file with the same name exists, do you want to overwrite it ? type y to continue .."
                 message = "Type y to continue "
                 choice = get_item_through_dialogue(self, message)
                 if choice == 'y':
                     os.remove(self.file_path)
                     self.print_report_to_file('survey-wide')
             else:
                 self.print_report_to_file('survey-wide')
     elif ops == 'SEGD_tape_log':
         if caller == 'Deliverable':
             self.deliverable = self.disp_name_dict[attribute]
             self.no_of_sets = self.deliverable.copies
             self.file_name = str(self.deliverable.id) + "_" + str(
                 datetime.datetime.now().strftime(
                     "%Y%m%d")) + "_SEGD_Tape_log.xlsx"
             self.file_path = os.path.join(os.getcwd(), Report_dir,
                                           self.file_name)
             if os.path.exists(self.file_path):
                 print "A file with the same name exists, do you want to overwrite it ? type y to continue .."
                 message = "Type y to continue "
                 choice = get_item_through_dialogue(self, message)
                 if choice == 'y':
                     os.remove(self.file_path)
                     self.print_tape_log_to_file('survey-wide')
             else:
                 self.print_tape_log_to_file('survey-wide')
 def check_and_create_media_list_entry(self):
     # How to decide the deliverable and set no + reel no
     segy_qc_obj = self.db_connection_obj.sess.query(
         self.db_connection_obj.SEGY_QC_on_disk).filter(
             self.db_connection_obj.SEGY_QC_on_disk.id_seq_segy_qc ==
             self.tape_write_obj_to_change.id_segy_qc).first()
     reel_no = segy_qc_obj.sgyt_reel_no
     #1st check if the particular entry exists in media list
     db_obj_list = self.db_connection_obj.sess.query(
         self.db_connection_obj.Media_list).filter(
             self.db_connection_obj.Media_list.deliverable_id ==
             self.deliverable.id).filter(
                 self.db_connection_obj.Media_list.set_no == self.set_no
             ).filter(self.db_connection_obj.Media_list.reel_no ==
                      reel_no).all()
     if len(
             db_obj_list
     ) == 0:  # No previous entry exists in DB, simply create a new one
         new_media_list_obj = self.db_connection_obj.Media_list()
         new_media_list_obj.deliverable_id = self.deliverable.id
         new_media_list_obj.set_no = self.set_no
         new_media_list_obj.media_label = reel_no
         new_media_list_obj.use_tag = True
         new_media_list_obj.reel_no = reel_no
         self.db_connection_obj.sess.add(new_media_list_obj)
         self.db_connection_obj.sess.commit()
     else:
         for obj in db_obj_list:
             if obj.use_tag == True:
                 message = str(
                     "Media list entry exists before, press y to set the last entry as False and the new one as True"
                 )
                 status = get_item_through_dialogue(self, message)
                 if status == 'y':
                     obj.use_tag = False
         new_media_list_obj = self.db_connection_obj.Media_list()
         new_media_list_obj.deliverable_id = self.deliverable.id
         new_media_list_obj.set_no = self.set_no
         new_media_list_obj.media_label = reel_no
         new_media_list_obj.use_tag = True
         new_media_list_obj.reel_no = reel_no
         self.db_connection_obj.sess.add(new_media_list_obj)
         self.db_connection_obj.sess.commit()
    def save_deliverable(self):
        print "Now converting the GUI object to DAO....",
        new_deliverable = self.adaptar_gui_to_object()

        print "Done .....now saving it........"
        #---------------------------------------------------------------
        #------------use of DIR service
        #---------------------------------------------------------------
        name = new_deliverable.name
        add_deliverable(self.db_connection_obj, new_deliverable)
        print "done .... "
        self.dir_service.set_deliverable(new_deliverable)
        self.dir_service.create_all_paths()
        self.dir_service.add_all_paths_to_db()
        if new_deliverable.media == 'USB':
            status = get_item_through_dialogue(
                self,
                "The media is USB, do you want to associate the deliverable directories with another deliverable, press y to continue"
            )
            if status == 'y':
                self.usb_deliverable = new_deliverable
                self.choose_deliverable("change_deliverable_dir")
        #---------------------------------------------------------------
        self.parent.set_deliverables_window()
Exemple #8
0
 def create_SEGY_3D_sgyt(self):
     result = self.db_connection_obj.sess.query(
         self.db_connection_obj.SEGY_QC_on_disk).filter(
             self.db_connection_obj.SEGY_QC_on_disk.deliverable_id ==
             self.Deliverable.id).first(
             )  # This time we do not need a sequence in the filter mocde
     if result is None:
         sgyt_file_name = create_3D_sgyt(self.Deliverable, self.IL_range,
                                         self.XL_range, int(self.reel))
         user_file_name = "user_" + sgyt_file_name
         # SFTP the template to the DUG workstation
         # 1. check if the file already exists on the DUG workstation
         self.dir_service.set_deliverable(self.Deliverable)
         dir_for_checking = self.dir_service.data_dir_path_dict['masters']
         local_path = os.path.join(os.getcwd(), 'temp', sgyt_file_name)
         remote_path = posixpath.join(dir_for_checking, sgyt_file_name)
         status = check_generic_path(self.DUG_connection_obj, remote_path)
         logger.info(
             "Now attempting to transfer the file to the DUG workstation..."
         )
         if status == 'True':
             action = get_item_through_dialogue(
                 self.parent,
                 'Now attempting to transfer the file to the DUG workstation... type y to continue, n to exit'
             )
             if action == 'y':
                 SFTP_generic_file(self.DUG_connection_obj, local_path,
                                   remote_path)
             else:
                 logger.warning('Aborting the file transfer!!!!')
         else:
             SFTP_generic_file(self.DUG_connection_obj, local_path,
                               remote_path)
         # now create a new DAO object
         new_obj = self.db_connection_obj.SEGY_QC_on_disk()
         new_obj.line_name = '3D deliverable'
         new_obj.deliverable_id = self.Deliverable.id
         new_obj.sgyt_status = True
         new_obj.sgyt_reel_no = self.Deliverable.reel_prefix + str(
             self.reel)
         new_obj.sgyt_min_il = self.IL_range[0]
         new_obj.sgyt_max_il = self.IL_range[1]
         new_obj.sgyt_min_xl = self.XL_range[0]
         new_obj.sgyt_max_xl = self.XL_range[1]
         new_obj.sgyt_fgsp = None
         new_obj.sgyt_lgsp = None
         new_obj.sgyt_min_ffid = None
         new_obj.sgyt_max_ffid = None
         new_obj.sgyt_user_path = posixpath.join(dir_for_checking,
                                                 user_file_name)
         new_obj.sgyt_unix_path = remote_path
         new_obj.sgyt_exp_uname = self.username
         new_obj.sgyt_time_stamp = datetime.datetime.now().strftime(
             "%I:%M%p on %B %d, %Y")
         self.db_connection_obj.sess.add(new_obj)
         self.db_connection_obj.sess.commit()
         logger.info(
             "The new object for SEGY on disk QC SEGY template export is now added to the database..."
         )
     else:
         message = str("The SGYT file for deliverable_id : " +
                       str(self.Deliverable.id) + ": name : " +
                       self.Deliverable.name + " was exported by : " +
                       result.sgyt_exp_uname + ' on : ' +
                       result.sgyt_time_stamp +
                       " Enter reason to re-export: ")
         perform = change_log_creation(gui=self.parent,
                                       conn_obj=self.db_connection_obj,
                                       message=message,
                                       type_entry="change",
                                       location='sgyt')
         if perform:
             sgyt_file_name = create_3D_sgyt(self.Deliverable,
                                             self.IL_range, self.XL_range,
                                             self.reel)
             user_file_name = "user_" + sgyt_file_name
             # SFTP the template to the DUG workstation
             # 1. check if the file already exists on the DUG workstation
             self.dir_service.set_deliverable(self.Deliverable)
             dir_for_checking = self.dir_service.data_dir_path_dict[
                 'masters']
             local_path = os.path.join(os.getcwd(), 'temp', sgyt_file_name)
             remote_path = posixpath.join(dir_for_checking, sgyt_file_name)
             status = check_generic_path(self.DUG_connection_obj,
                                         remote_path)
             logger.info(
                 "Now attempting to transfer the file to the DUG workstation..."
             )
             if status == 'True':
                 message = "File already exists on DUG system, type y to continue, n to exit"
                 action = get_item_through_dialogue(self.parent, message)
                 if action == 'y':
                     SFTP_generic_file(self.DUG_connection_obj, local_path,
                                       remote_path)
                 else:
                     logger.warning('Aborting the file transfer!!!!')
             else:
                 SFTP_generic_file(self.DUG_connection_obj, local_path,
                                   remote_path)
                 print "File transfer complete .. "
             # now create a new DAO object
             result.sgyt_reel_no = self.Deliverable.reel_prefix + str(
                 self.reel)
             result.sgyt_fgsp = None
             result.sgyt_lgsp = None
             result.sgyt_min_ffid = None
             result.sgyt_max_ffid = None
             result.sgyt_min_il = self.IL_range[0]
             result.sgyt_max_il = self.IL_range[1]
             result.sgyt_min_xl = self.XL_range[0]
             result.sgyt_max_xl = self.XL_range[1]
             result.sgyt_user_path = posixpath.join(dir_for_checking,
                                                    user_file_name)
             result.sgyt_unix_path = remote_path
             result.sgyt_exp_uname = self.username
             result.sgyt_time_stamp = datetime.datetime.now().strftime(
                 "%I:%M%p on %B %d, %Y")
             if result.sgyt_approval_status is not None:
                 # this step clears the previous status flag as this is a new file and should be checked again
                 result.sgyt_approval_status = None
                 result.sgyt_approver_name = None
                 result.sgyt_approval_time = None
             self.db_connection_obj.sess.commit()
Exemple #9
0
 def set_attribute(self, attribute, caller, ops):
     if ops == 'SGYT':
         if caller == 'Deliverable':
             self.Deliverable = self.disp_name_dict[attribute]
             #Check if the deliverable is of the type sequence wise
             if self.Deliverable.type in sequence_wise_SEGY:
                 #Now check if DUG SGYT master is defined for the deliverable
                 if self.Deliverable.sgyt_master_status:
                     #print self.Deliverable.sgyt.decode('base64')
                     if self.Deliverable.media in multiple_per_tape_list:
                         self.choose_sequences(ops)
                     else:
                         self.choose_sequence(ops)
                 else:
                     logger.warning(
                         "No SGYT found for the deliverable in the database !!!"
                     )
             elif self.Deliverable.type in SEGY_3D:
                 if self.Deliverable.sgyt_master_status:
                     mnIL = get_item_through_dialogue(
                         self.parent, 'Minimum IL')
                     mxIL = get_item_through_dialogue(
                         self.parent, 'Maximum IL')
                     mnXL = get_item_through_dialogue(
                         self.parent, 'Minimum XL')
                     mxXL = get_item_through_dialogue(
                         self.parent, 'Maximum XL')
                     reel = get_item_through_dialogue(
                         self.parent, 'Tape number excluding prefix')
                     self.reel = str('{0:04d}'.format(int(reel)))
                     self.IL_range = [mnIL, mxIL]
                     self.XL_range = [mnXL, mxXL]
                     username = self.get_user_name()
                     if username == 'exit':
                         pass
                     else:
                         if len(username) != 0:
                             self.username = username
                             self.create_SEGY_3D_sgyt()
                         else:
                             self.get_user_name()
                 else:
                     logger.warning(
                         "No SGYT found for the deliverable in the database !!!"
                     )
         elif caller == 'Sequence':
             #self.sequence = self.disp_seq_dict[attribute]
             self.sequence_list = [attribute]
             # get min max IL and XL ranges
             # mnIL = get_item_through_dialogue(self.parent,'Minimum IL')
             # mxIL = get_item_through_dialogue(self.parent,'Maximum IL')
             # mnXL = get_item_through_dialogue(self.parent, 'Minimum XL')
             # mxXL = get_item_through_dialogue(self.parent, 'Maximum XL')
             reel = get_item_through_dialogue(
                 self.parent, 'Tape number excluding prefix')
             self.reel = str('{0:04d}'.format(int(reel)))
             self.IL_range = [
                 0, 0
             ]  # these need to be updated through PQ Man i the future
             self.XL_range = [
                 0, 0
             ]  # These need to be updated through PQ MAn in the future
             username = self.get_user_name()
             if username == 'exit':
                 pass
             else:
                 if len(username) != 0:
                     self.username = username
                     self.create_sequence_wise_sgyt()
                 else:
                     self.get_user_name()
         elif caller == 'Sequences':
             #self.sequence = self.disp_seq_dict[attribute]
             self.sequence_list = attribute
             # get min max IL and XL ranges
             # mnIL = get_item_through_dialogue(self.parent,'Minimum IL')
             # mxIL = get_item_through_dialogue(self.parent,'Maximum IL')
             # mnXL = get_item_through_dialogue(self.parent, 'Minimum XL')
             # mxXL = get_item_through_dialogue(self.parent, 'Maximum XL')
             reel = get_item_through_dialogue(
                 self.parent, 'Tape number excluding prefix')
             self.reel = str('{0:04d}'.format(int(reel)))
             self.IL_range = [
                 0, 0
             ]  # these need to be updated through PQ Man i the future
             self.XL_range = [
                 0, 0
             ]  # These need to be updated through PQ MAn in the future
             username = self.get_user_name()
             if username == 'exit':
                 pass
             else:
                 if len(username) != 0:
                     self.username = username
                     self.create_sequence_wise_sgyt()
                 else:
                     self.get_user_name()
     elif ops == 'per_QC':
         if caller == 'Deliverable':
             self.Deliverable = self.disp_name_dict[attribute]
             #Now check if the bin def and trc def file exists for the deliverable
             if self.Deliverable.bin_def_status and self.Deliverable.trc_def_status:
                 # now the deliverable is set, time to set the dir service to the deliverable
                 self.dir_service.set_deliverable(self.Deliverable)
                 # return the list of SEGY files for the deliverable in the large files+ deliverable dir
                 self.choose_sgy_file_for_QC(ops)
             else:
                 logger.warning(
                     "The bin.def and trc.def files for the deliberable are not defined in the database!!!"
                 )
         if caller == 'file_sgy':
             #fetch the bin def and trc def files from the database and create files in temp dir and SFTP them to the DUG WS
             (bin_def_path, trc_def_path) = self.create_def_files_and_sFTP()
             file_path = posixpath.join(
                 self.dir_service.data_dir_path_dict['data'], attribute)
             logger.info("Now running Qc script on: " + file_path)
             log_name = str(
                 self.Deliverable.id
             ) + "_" + self.Deliverable.name + "_" + attribute + '.headerlog'
             log_dir = self.dir_service.data_dir_path_dict['headers']
             log_path = posixpath.join(log_dir, log_name)
             self.qc_log_path = log_path
             # if log exists before delete it and than redo it
             status = check_generic_path(self.DUG_connection_obj, log_path)
             script_name = self.DUG_connection_obj.DUG_project_name + "_segy-hcm"
             script_path = posixpath.join("/d/home/share/bin", script_name)
             cmd = str(
                 "nohup " + script_path + " " + file_path + " -bd " +
                 bin_def_path + " -td " + trc_def_path + " -l " + log_path +
                 "  > /dev/null 2>&1 &"
             )  # change this line to modify the command and the python package needs to be changed as well
             if status == 'True':
                 message = "The log already exists either the QC is running or you are trying to run it again. Please check if the job is still running or if finished press ok to remove old file and create a new one !!"
                 self.pop_up_message_box = pop_up_message_box(
                     message, 'Warning')
                 self.pop_up_message_box.closed.connect(
                     lambda: self.run_segy_qc(cmd, True))
                 self.pop_up_message_box.show()
                 # modify the existing Db entry
                 db_entry = self.db_connection_obj.sess.query(
                     self.db_connection_obj.SEGY_QC_on_disk).filter(
                         self.db_connection_obj.SEGY_QC_on_disk.
                         segy_on_disk_qc_log_path == log_path).first()
                 db_entry.segy_on_disk_qc_run_status = True
                 db_entry.segy_on_disk_qc_status = None
                 db_entry.segy_on_disk_qc_approver_name = None
                 db_entry.segy_on_disk_qc_approval_time = None
                 self.db_connection_obj.sess.commit()
             else:
                 # execute the command on the DUG workstation
                 self.run_segy_qc(cmd, False)
                 db_entry = self.db_connection_obj.sess.query(
                     self.db_connection_obj.SEGY_QC_on_disk).filter(
                         self.db_connection_obj.SEGY_QC_on_disk.
                         segy_on_disk_file_path == file_path).first()
                 db_entry.segy_on_disk_qc_run_status = True
                 db_entry.segy_on_disk_qc_log_path = log_path
                 self.db_connection_obj.sess.commit()
 def get_confirmation_for_tape_label(self, GUI_object):
     top_message = "Please enter the tape label manually for check"
     typed_label = get_item_through_dialogue(GUI_object, top_message)
     return typed_label