Esempio n. 1
0
    def move_all_file_to_history(self, a_show_type, a_rule_view_list,
                                 a_is_in_history_add_datetime,
                                 a_is_in_history_add_version, a_path):
        #show_file_list为当前文件正在显示的文件列表
        t_show_file_list = []
        t_dir = QDir(a_path)
        if a_show_type == "files":
            #显示文件
            t_dir.setNameFilters(
                ct_lib.com().change_to_file_rule_list(a_rule_view_list))
            #rule_list的规则是原先带有###的规则,需转换为??
            #设置过滤器(目录,文件或非上级目录)
            t_dir.setFilter(QDir.Files | QDir.NoDotAndDotDot)
        else:
            a_rule_view_list.insert(0, "history")
            t_dir.setNameFilters(
                ct_lib.com().change_to_file_rule_list(a_rule_view_list))
            #rule_list的规则是原先带有###的规则,需转换为??
            #再过滤出文件,要规则过滤
            t_dir.setFilter(QDir.Dirs | QDir.Files | QDir.NoDotAndDotDot)

        info_list = t_dir.entryInfoList()
        for fileInfo in info_list:
            if ct_lib.com().is_match_regexp_list(a_rule_view_list,
                                                 fileInfo.fileName()):
                t_show_file_list.append(fileInfo.absoluteFilePath())

        if len(t_show_file_list) > 0:
            sou_list = []
            for temp in t_show_file_list:
                if unicode(
                        os.path.basename(temp)).strip().lower() != "history":
                    sou_list.append(temp)
            self.common_move(a_path, sou_list, a_is_in_history_add_datetime,
                             a_is_in_history_add_version)
Esempio n. 2
0
 def check_version_exist(self, a_rule):
     t_dir = QDir(self.m_path)
     t_dir.setNameFilters(ct_lib.com().change_to_file_rule_list([rule]))
     t_dir.setFilter(QDir.Files | QDir.NoDotAndDotDot)
     for fileInfo in t_dir.entryInfoList():
         if ct_lib.com().is_match_regexp_string(rule, fileInfo.fileName()):
             return True
     return False
Esempio n. 3
0
 def get_match_version_list(self, a_rule):
     filename_list = []
     t_dir = QDir(self.m_path)
     t_dir.setNameFilters(ct_lib.com().change_to_file_rule_list([a_rule]))
     t_dir.setFilter(QDir.Files | QDir.NoDotAndDotDot)
     for fileInfo in t_dir.entryInfoList():
         if ct_lib.com().is_match_regexp_string(a_rule,
                                                fileInfo.fileName()):
             filename_list.append(fileInfo.fileName())
     return filename_list
Esempio n. 4
0
    def set_combobox_data(self, a_combobox_widget):
        ver = -1
        rule = a_combobox_widget.currentText()
        t_dic = self.get_index_dict(rule)
        s_id = t_dic["s_id"]
        e_id = t_dic["e_id"]
        if e_id != -1:
            ver_size = e_id - s_id + 1
            #  "#"的个数
            char_string = self.get_char(ver_size)
            #"####"
            replace_b = rule[s_id:]  #比如"####.ma"
            match_filename_list = self.get_match_version_list(rule)
            match_filename_list.sort()
            if len(match_filename_list) == 0:
                ver = 1
            else:
                #取匹配到的最大的文件名的版本号
                max_ver = unicode(
                    match_filename_list[len(match_filename_list) -
                                        1])[s_id:s_id + ver_size]
                ver = int(max_ver) + 1

            temp_rule = rule  #重新赋值
            temp_b = replace_b  #重新赋值
            replace_f = temp_b.replace(char_string,
                                       ct_lib.com().start_add_zero(
                                           unicode(ver),
                                           ver_size))  #比如"0001.ma"
            new_rule = temp_rule.replace(replace_b, replace_f)

            #从combobox的windowtitle中取到这个源文件路径,用于后面替换suffix使用
            temp_sou_file = a_combobox_widget.windowTitle()
            a_combobox_widget.setCurrentText(
                self.replace_suffix(temp_sou_file, new_rule))
Esempio n. 5
0
    def init_info(self):
        #显示规则
        self.label.setText(
            self.tr("File Rule('#':number '?':letter '*':Any character)") +
            "\n")

        pixmap = QPixmap(15, 15)
        t_current_row = -1
        self.tableWidget.clear()
        self.set_header()
        self.tableWidget.setRowCount(0)
        is_all_char = False
        is_match_suffix = False
        if unicode("*") in self.m_rule_list:
            #表示里面有*,规则就不默认为第一个
            is_all_char = True

        for temp_sou_file in self.m_sou_file_list:
            t_current_row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(t_current_row)
            info = QFileInfo(temp_sou_file)
            item = QTableWidgetItem()
            if not ct_lib.com().is_match_regexp_list(self.m_rule_list,
                                                     info.fileName()):
                pixmap.fill(Qt.red)
            else:
                pixmap.fill(QColor(56, 56, 56))

            item.setData(Qt.DescendingOrder, pixmap)
            item.setData(Qt.UserRole, temp_sou_file)
            self.tableWidget.setItem(t_current_row, self.COL_DES_NAME, item)

            com = QComboBox(self.tableWidget)
            #将源路径也藏一个到combobox的windowtitle中,用于后面替换suffix使用
            com.setWindowTitle(temp_sou_file)

            com.currentIndexChanged.connect(self.slt_combobox_change)
            com.setView(QListView(self))
            com.setEditable(True)
            com.addItems(self.m_rule_list)
            com.setCurrentText(info.fileName())
            if len(self.m_rule_list) > 0 and not is_all_char:
                #匹配后缀名是一样的
                is_match_suffix = False
                for temp_rule in self.m_rule_list:
                    rule_info = QFileInfo(temp_rule)
                    if unicode(rule_info.suffix()).lower() == unicode(
                            info.suffix()).lower():
                        com.setCurrentText(temp_rule)
                        is_match_suffix = True
                        break

                if not is_match_suffix:
                    com.setCurrentText(
                        self.replace_suffix(temp_sou_file,
                                            self.m_rule_list[0]))

            self.tableWidget.setCellWidget(t_current_row, self.COL_DES_NAME,
                                           com)
Esempio n. 6
0
    def is_exist_error(self):
        is_error = False
        user_data = ""
        pixmap = QPixmap(15, 15)
        rule_error = ""
        filename_extension_error = ""
        for i in range(self.tableWidget.rowCount()):
            comboBox = self.tableWidget.cellWidget(i, self.COL_DES_NAME)
            user_data = self.tableWidget.item(i, self.COL_DES_NAME).data(
                Qt.UserRole)

            if not comboBox is None:
                text = comboBox.currentText()
                if not ct_lib.com().is_match_regexp_list(
                        self.m_rule_list, text):
                    pixmap.fill(Qt.red)
                    is_error = True
                    rule_error = rule_error + text + "\n"
                else:
                    pixmap.fill(QColor(56, 56, 56))

                #检查后缀
                sou_info = QFileInfo(user_data)
                des_info = QFileInfo(text)
                if sou_info.suffix() != des_info.suffix():
                    filename_extension_error = filename_extension_error + text + " <--> " + sou_info.fileName(
                    ) + "\n"
                    is_error = True
                    pixmap.fill(Qt.red)
                else:
                    pixmap.fill(QColor(56, 56, 56))

                self.tableWidget.item(i, self.COL_DES_NAME).setData(
                    Qt.DescendingOrder, pixmap)

        if is_error:
            error = ""
            if unicode(rule_error).strip() != "":
                error = self.tr("File rule error:") + "\n" + rule_error

            if unicode(filename_extension_error).strip() != "":
                if error != "":
                    error = error + "\n" + self.tr(
                        "Filename extension error:"
                    ) + "\n" + filename_extension_error
                else:
                    error = self.tr("Filename extension error:"
                                    ) + "\n" + filename_extension_error

            ct_ui.message().error(error)
        return is_error
Esempio n. 7
0
    def common_move(self,
                    a_current_path,
                    a_sou_list,
                    a_is_in_history_add_datetime,
                    a_is_in_history_add_version,
                    a_is_force_cover_no_message=False):
        #current_path指的是当前文件框的路径
        des_path = ""
        new_des_list = []
        new_sou_list = []
        if len(a_sou_list) > 0:
            for sou_file in a_sou_list:
                #判断文件是否存在
                if not os.path.exists(sou_file):
                    continue
                new_sou_list.append(sou_file)
                temp_sou_file = sou_file
                if ct.com().get_os() == "mac" and os.path.isdir(sou_file):
                    temp_sou_file = unicode(sou_file).rstrip("\\").rstrip("/")

                if a_is_in_history_add_datetime == "y":
                    des_path = a_current_path + "/history/" + ct.com().now(
                        '%Y-%m-%d-%H-%M-%S') + "/" + os.path.basename(
                            temp_sou_file)
                else:
                    des_path = a_current_path + "/history/" + os.path.basename(
                        temp_sou_file)

                temp_des_file = des_path

                if a_is_in_history_add_version == "y":
                    temp_des_file = ct_lib.com().auto_add_version(des_path)

                if ct.com().get_os() == "mac" and os.path.isdir(sou_file):
                    temp_des_file = temp_des_file + "/"
                new_des_list.append(temp_des_file)

            if len(new_sou_list) > 0 and len(new_sou_list) == len(
                    new_des_list):
                self.copy = ct_ui.copy_widget(new_sou_list, new_des_list, None,
                                              False, True,
                                              a_is_force_cover_no_message)
                if self.copy.exec_() == QDialog.Accepted:
                    return True
                else:
                    return False
        return True
Esempio n. 8
0
    def run(self, a_dict_data):
        t_argv = ct_plu.argv(a_dict_data)
        t_db = t_argv.get_sys_database()
        t_module = t_argv.get_sys_module()
        t_module_type = t_argv.get_sys_module_type()
        t_id_list = t_argv.get_sys_id()
        t_filebox_id = t_argv.get_sys_filebox_id()
        t_drop_file_list = t_argv.get_sys_file()  #拖入进来的源文件
        try:
            t_tw = tw()
            #取命名规则和路径
            filebox_info = self.get_filebox_info(t_tw, t_db, t_module,
                                                 t_module_type, t_id_list[0],
                                                 t_filebox_id)
            if filebox_info == False or not filebox_info.has_key(
                    "rule") or not filebox_info.has_key("path"):
                return self.ct_false("Get filebox info error")
            t_rule_list = filebox_info["rule"]
            t_path = filebox_info["path"]
            if not isinstance(t_rule_list, list):
                return self.ct_false("Get filebox rule error")

            #取出目录规则,用于提示
            message_folder_rule = ""
            for temp_rule in t_rule_list:
                if unicode(temp_rule).find(".") == -1:
                    message_folder_rule = message_folder_rule + "\n" + temp_rule

            #-----------------------------组成新的-----------------------
            sou_file_list = []
            des_file_list = []
            sou_dir_list = []
            des_dir_list = []
            total_sou_list = []
            total_des_list = []
            is_exist_error_filename = False
            #过滤出符合命名规则的文件 //文件是否存在命名规则错误
            for temp_path in t_drop_file_list:
                t_filename = os.path.basename(temp_path)
                if os.path.isfile(temp_path):
                    if not ct_lib.com().is_match_regexp_list(
                            t_rule_list, t_filename):
                        is_exist_error_filename = True
                    sou_file_list.append(temp_path)
                    des_file_list.append(t_path + "/" + t_filename)
                else:
                    #检查文件夹
                    if not ct_lib.com().is_match_regexp_list(
                            t_rule_list, t_filename):
                        #目录规则错误
                        return self.ct_false("Folder rule is error \n" +
                                             message_folder_rule)

                    sou_dir_list.append(temp_path)
                    #不是遍历的,里面存储的就是文件夹的路径。。
                    des_dir_list.append(t_path + "/" + t_filename)

            #存在命名规则错误,进行更改
            if is_exist_error_filename:
                #修改文件名,并返回目标文件列表
                res = modify_filename(t_path, t_rule_list, sou_file_list).run()
                if res == []:
                    return self.ct_false("Fail to modify the rules")  #修改规则失败
                des_file_list = res

            #把文件和文件夹的都放到新的列表中----
            total_sou_list = total_sou_list + sou_file_list
            total_sou_list = total_sou_list + sou_dir_list
            total_des_list = total_des_list + des_file_list
            total_des_list = total_des_list + des_dir_list
            return self.ct_true({
                "sou_list": total_sou_list,
                "des_list": total_des_list
            })
        except Exception, e:
            #print traceback.format_exc()
            return self.ct_false(traceback.format_exc())