示例#1
0
 def on_lstFiles_itemClicked(self, current):
     globaldefines.other_trace()
     file_path = current.text()[0:current.text().find('-')]
     self.ui.lstInfo.clear()
     infos = self.time_seq.get_info(file_path)
     for info in infos:
         self.ui.lstInfo.addItem(str(info))
示例#2
0
 def _convert_to_bytes(self, tasks, errs):
     byte_temp = bytes()
     if len(errs) == 0:
         for task in tasks:
             try:
                 one_task_byte = bytes()
                 one_task_byte += struct.pack(
                     "8s", task[ProjectFile.DESCRIPTION_CMD].encode(
                         encoding='utf-8'))
                 one_task_byte += struct.pack(
                     "<H", int(task[ProjectFile.DESCRIPTION_INDEX]))
                 one_task_byte += struct.pack(
                     "<H", int(task[ProjectFile.DESCRIPTION_STARTTIME]))
                 one_task_byte += struct.pack(
                     "<H", int(task[ProjectFile.DESCRIPTION_ENDTIME]))
                 one_task_byte += struct.pack(
                     "<h", int(task[ProjectFile.DESCRIPTION_PARAM1]))
                 one_task_byte += struct.pack(
                     "<h", int(task[ProjectFile.DESCRIPTION_PARAM2]))
                 one_task_byte += struct.pack(
                     "<h", int(task[ProjectFile.DESCRIPTION_PARAM3]))
                 one_task_byte += struct.pack(
                     "<h", int(task[ProjectFile.DESCRIPTION_PARAM4]))
                 checksum = 0
                 for byte in one_task_byte:
                     checksum += byte
                 one_task_byte += struct.pack("<H", int(checksum))
                 byte_temp += one_task_byte
             except Exception as e:
                 globaldefines.other_trace("Except: %s" % str(e))
                 errs.append(task)
                 errs.append(str(e))
                 byte_temp = bytes()
                 break
     return byte_temp
示例#3
0
 def slot_timeseq_changed(self, file_path):
     globaldefines.other_trace()
     find_items = self.ui.lstFiles.findItems(file_path, Qt.MatchStartsWith)
     if len(find_items) != 1:
         globaldefines.other_trace("%s not found or too much")
     find_items[0].setText(file_path + '-' +
                           self.time_seq.get_status(file_path))
示例#4
0
    def __init__(self,
                 file_path,
                 translate_rules,
                 check_rules,
                 thread,
                 parent=None):
        super(BaseTime, self).__init__(parent)
        self._file_path = file_path
        self._items = []
        self._errs = []
        self._item_bytes = bytes()
        self._all_translate_rules = translate_rules
        self._all_check_rules = check_rules
        self._mutex = QMutex(QMutex.Recursive)
        print(thread)
        if thread == None:
            globaldefines.other_trace('new')
            self._thread = QThread(parent)
            self._thread.start()
        else:
            globaldefines.other_trace('use old')
            self._thread = thread

        self.moveToThread(self._thread)
        self.sig_start.connect(self.slot_start)
示例#5
0
 def slot_start(self):
     globaldefines.other_trace()
     self.sig_init.emit(self._file_path)
     items, errs, item_bytes = self._phase()
     globaldefines.other_trace('\nitems:%s\nerrs:%s\nitemBytes:%d' %
                               (str(items), str(errs), len(item_bytes)))
     with QMutexLocker(self._mutex):
         self.items = items
         self.errs = errs
         self.item_bytes = item_bytes
         self.sig_changed.emit(self._file_path)
示例#6
0
 def _check(self):
     globaldefines.other_trace('1')
     for basetime in self._bases.values():
         if len(basetime.errs) != 0 or len(basetime.items) == 0:
             globaldefines.other_trace('2')
             return False
     globaldefines.other_trace('3')
     return True
示例#7
0
    def _process_tasks(self, tasks, errs):
        globaldefines.other_trace("_process_tasks 0")
        # do some filtration
        tasks[:] = list(filter(self._task_filter, tasks))
        globaldefines.other_trace("_process_tasks 1")

        # do some tranlation
        tasks[:] = list(map(self._task_translate, tasks))
        globaldefines.other_trace("_process_tasks 2")

        # sort and index
        tasks[:] = sorted(tasks, key=self._task_sort)
        globaldefines.other_trace("_process_tasks 3")

        # check
        if len(tasks) == 0:
            errs.append('empty')

        for task in tasks:
            if not self._task_check(task):
                errs.append(task)

        globaldefines.other_trace("_process_tasks 4")
        return tasks
示例#8
0
    def _write(self):
        globaldefines.other_trace()
        try:
            with open(self._object_name, 'wb') as file:
                # write version 4 Byte
                version = struct.pack('<BBBB', *globaldefines.output_version)
                file.write(version)

                # write file head 2 Byte
                file_head = struct.pack('<H', len(self._bases))
                file.write(file_head)

                # write list head
                list_head = bytes()
                content_addr = 6 + 10 * len(self._bases)
                for file_name, base_time in self._bases.items():
                    file_index = int(file_name[0:3])
                    list_head += struct.pack('<HII', file_index, content_addr,
                                             len(base_time.item_bytes))
                    content_addr += len(base_time.item_bytes)
                file.write(list_head)

                # write content
                for file_name, base_time in self._bases.items():
                    file.write(base_time.item_bytes)

            self.sig_write_done.emit('done')
        except FileNotFoundError:
            globaldefines.useroptrace("Except: File %s is not found." %
                                      self.ASSIST_FILE_NAME)
        except PermissionError:
            globaldefines.useroptrace(
                "Except: You don't have permission to access the file %s." %
                self.ASSIST_FILE_NAME)
        except Exception as e:
            globaldefines.useroptrace("Except: %s" % str(e))
示例#9
0
    def _create(self):
        globaldefines.other_trace()

        translate_info = 'translate ok'
        try:
            with open(self._translate_name) as _translate_file:
                self._translate_rules = json.loads(_translate_file.read())
        except Exception as e:
            globaldefines.other_trace("Except: %s" % str(e))
            translate_info = 'translate err'
        else:
            if len(self._translate_rules) == 0:
                translate_info = 'translate empty'

        check_info = 'check ok'
        try:
            with open(self._check_name) as _check_file:
                self._check_rules = json.loads(_check_file.read())
        except Exception as e:
            globaldefines.other_trace("Except: %s" % str(e))
            check_info = 'check err'
        else:
            if len(self._check_rules) == 0:
                check_info = 'check empty'

        support_info = translate_info + ' ' + check_info
        self.sig_support_done.emit(support_info)

        for file_path in self._get_file_paths():
            basetime = BaseTime(file_path, self._translate_rules,
                                self._check_rules, self._thread)
            self._bases[file_path] = basetime
            basetime.sig_init.connect(self.sig_init)
            basetime.sig_uninit.connect(self.sig_uninit)
            basetime.sig_changed.connect(self.sig_changed)
            basetime.sig_changed.connect(self.write)
            basetime.start()
    def get(file_name):
        path = os.path.join(globaldefines.path, file_name)
        tasks = []
        errs = []
        try:
            state = State.Init
            pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
            state = State.CoInitialize
            globaldefines.other_trace('%s get state = %s' % (file_name, state))

            project_exe = win32com.client.DispatchEx("MSProject.Application")
            project_exe.Visible = False
            project_exe.DisplayAlerts = False
            state = State.DispatchEx
            globaldefines.other_trace('%s get state = %s' % (file_name, state))

            project_exe.FileOpenEx(Name=path, ReadOnly=True)
            count = project_exe.Projects.count
            project_tasks = project_exe.Projects.item(path).tasks
            state = State.FileOpenEx
            globaldefines.other_trace('%s get state = %s(%s)' %
                                      (file_name, state, str(count)))

            for project_task in project_tasks:
                task = {
                    ProjectFile.DESCRIPTION_INDEX:
                    str(project_task.ID),
                    ProjectFile.DESCRIPTION_CHAPTER:
                    str(project_task.WBS),
                    ProjectFile.DESCRIPTION_STARTTIME:
                    round(float('%.2f' % project_task.Number6) * 100),
                    ProjectFile.DESCRIPTION_ENDTIME:
                    round(float('%.2f' % project_task.Number7) * 100),
                    ProjectFile.DESCRIPTION_CMD:
                    str(project_task.Name).strip().upper(),
                    ProjectFile.DESCRIPTION_PARAM1:
                    int(project_task.Number1),
                    ProjectFile.DESCRIPTION_PARAM2:
                    int(project_task.Number2),
                    ProjectFile.DESCRIPTION_PARAM3:
                    int(project_task.Number3),
                    ProjectFile.DESCRIPTION_PARAM4:
                    int(project_task.Number4)
                }
                tasks.append(task)
            state = State.Done
            globaldefines.other_trace('%s get state = %s\n\t%s' %
                                      (file_name, state, str(tasks)))
        except Exception as e:
            globaldefines.other_trace("Except: other except %s" % str(e))
            if state >= State.FileOpenEx:
                errs.append('file read error')
            elif state >= State.DispatchEx:
                errs.append('project open error')
            elif state >= State.CoInitialize:
                errs.append('init com environment fail')
        except BaseException as e:
            globaldefines.other_trace("Except: other except %s" % str(e))
            raise e
        finally:
            globaldefines.other_trace("%s get finally state = %s" %
                                      (file_name, state))
            if state >= State.FileOpenEx:
                project_exe.FileCloseEx(Save=0)

            if state >= State.DispatchEx:
                project_exe.Quit(SaveChanges=0)

            if state >= State.CoInitialize:
                pythoncom.CoUninitialize()
        globaldefines.other_trace("%s get return" % file_name)
        return tasks, errs
示例#11
0
 def slot_timeseq_uninit(self, file_path):
     globaldefines.other_trace()
     find_items = self.ui.lstFiles.findItems(file_path, Qt.MatchStartsWith)
     for find_item in find_items:
         self.ui.lstFiles.removeItemWidget(find_item)
示例#12
0
 def slot_timeseq_init(self, file_path):
     globaldefines.other_trace()
     find_items = self.ui.lstFiles.findItems(file_path, Qt.MatchStartsWith)
     if len(find_items) != 0:
         globaldefines.other_trace("slot_timeseq_init but count incorrect")
     self.ui.lstFiles.addItem(file_path + '-init')
示例#13
0
    def _phase(self):
        globaldefines.other_trace("_phase")
        tasks, errs = ProjectFile.get(self._file_path)
        self._process_tasks(tasks, errs)

        return tasks, errs, self._convert_to_bytes(tasks, errs)
示例#14
0
 def write(self):
     globaldefines.other_trace('1')
     if self._check():
         self._write()
     globaldefines.other_trace('2')
示例#15
0
 def start(self):
     globaldefines.other_trace('1')
     self._clear()
     self._create()
     globaldefines.other_trace('2')