示例#1
0
                evn_path
            ) + "/pythonextensions/site-packages/PySide/QtWebKit4.dll"
    if t_workspace_des_path == False or t_QtWebKit4_sou_path == False or t_QtWebKit4_des_path == False:
        return False

    if not os.path.exists(os.path.dirname(t_workspace_des_path)):
        try:
            os.makedirs(os.path.dirname(t_workspace_des_path))
        except Exception, e:
            print e

    if not os.path.exists(t_workspace_des_path):
        try:
            #===============骁颖==2018.06.15=====================
            #shutil.copy2(t_workspace_sou_path, t_workspace_des_path)
            ct.file().copy_file(t_workspace_sou_path, t_workspace_des_path)
            #===============骁颖==2018.06.15=====================
        except Exception, e:
            print e

    if os.path.exists(
            t_QtWebKit4_sou_path) and not os.path.exists(t_QtWebKit4_des_path):
        try:
            #===============骁颖==2018.06.15=====================
            #shutil.copy2(t_QtWebKit4_sou_path, t_QtWebKit4_des_path)
            ct.file().copy_file(t_QtWebKit4_sou_path, t_QtWebKit4_des_path)
            #===============骁颖==2018.06.15=====================
        except Exception, e:
            print e

示例#2
0
def filebox_bulk_upload_to_online():
    try:
        t_tw = tw()
        t_module = t_tw.sys().get_sys_module()
        t_module_type = t_tw.sys().get_sys_module_type()
        t_db = t_tw.sys().get_sys_database()
        task_id_list = t_tw.sys().get_sys_id()
        t_filebox_id = t_tw.sys()._get_sys_key("filebox_id")
        t_is_all = t_tw.sys()._get_sys_key("is_all")

        res = t_tw.con._send(
            "c_media_file", "get_filebox_bulk_upload_data", {
                "db": t_db,
                "module": t_module,
                "module_type": t_module_type,
                "os": ct.com().get_os(),
                "filebox_id": t_filebox_id,
                "task_id_array": task_id_list
            })
        if isinstance(res, dict) and res.has_key("is_submit") and res.has_key(
                "upload_to_server_action") and res.has_key(
                    "show_type") and res.has_key("filebox_data_list"):
            t_action = 'upload'
            t_is_submit = unicode(res["is_submit"]).lower()
            t_show_type = unicode(res["show_type"]).lower()
            t_filebox_data_list = res["filebox_data_list"]
            temp_act = res["upload_to_server_action"]
            if unicode("," + temp_act +
                       ",").find(",convert_before_upload,") != -1:
                t_action = "convert_movie_to_mp4"

            if unicode("," + temp_act +
                       ",").find(",convert_image_before_upload,") != -1:
                t_action = "convert_image_to_image"

            if unicode("," + temp_act +
                       ",").find(",sequence_output_video,") != -1:
                t_action = "convert_seq_image_to_mov"

            #开始处理
            if isinstance(t_filebox_data_list, list):
                for t_dict_data in t_filebox_data_list:
                    if isinstance(
                            t_dict_data, dict
                    ) and t_dict_data.has_key("path") and t_dict_data.has_key(
                            "server"
                    ) and t_dict_data.has_key("rule") and t_dict_data.has_key(
                            "task_id") and t_dict_data.has_key("title"):
                        t_rule_list = t_dict_data["rule"]
                        t_path = t_dict_data["path"]
                        t_server = t_dict_data["server"]
                        t_task_id = t_dict_data["task_id"]
                        t_title = t_dict_data["title"]

                        t_version_id = ct.com().uuid()  #随机生成的ID
                        re_list = change_to_regexp_list(t_rule_list)

                        #遍历本地文件排除histroy
                        if os.path.exists(t_path):
                            t_list = ct.file().get_path_list(t_path, re_list)
                            t_new_list = []
                            for i in t_list:
                                if os.path.isdir(unicode(i)) and unicode(
                                        os.path.basename(
                                            i)).lower() == "history":
                                    continue
                                i = unicode(i).replace("\\", "/")
                                t_new_list.append(i)

                            if len(t_new_list) == 0:
                                continue

                            if isinstance(t_is_all,
                                          (str, unicode)) and unicode(
                                              t_is_all).strip().lower() != "y":
                                t_new_list = __sorted(t_new_list, True)
                                t_new_list = [t_new_list[0]]

                            t_first = False
                            for i in t_new_list:
                                t_upload_list = [{
                                    "sou":
                                    i,
                                    "des":
                                    unicode(i).replace(t_server, "/")
                                }]
                                if unicode(t_is_submit).strip().lower() == "y":

                                    if t_first == False:
                                        #上传verison
                                        if upload_version({
                                                "db": t_db,
                                                "module": t_module,
                                                "module_type": t_module_type,
                                                "task_id": t_task_id,
                                                "des_file_list": t_list,
                                                "title": t_title,
                                                "version_id": t_version_id,
                                                "server": t_server,
                                                "tw": t_tw
                                        }) != True:
                                            message().error(u"创建Version失败")
                                            return
                                        #修改task表中的version_ID
                                        res = t_tw.con._send(
                                            "c_orm", "update_version_id", {
                                                "id": t_task_id,
                                                "db": t_db,
                                                "module": t_module,
                                                "module_type": t_module_type,
                                                "version_id": t_version_id
                                            })
                                        if res != True:
                                            return
                                        t_first = True

                                file_name = os.path.basename(
                                    t_upload_list[0]["sou"])
                                t_dic = {
                                    'name':
                                    file_name,
                                    'task': [{
                                        "action": t_action,
                                        "is_contine": True,
                                        "data_list": t_upload_list,
                                        "db": t_db,
                                        "module": t_module,
                                        "module_type": t_module_type,
                                        "task_id": t_task_id,
                                        "version_id": t_version_id
                                    }]
                                }
                                #print t_dic["name"] +u' --> send to queue'
                                t_tw.local_con._send("queue_widget",
                                                     "add_task",
                                                     {"task_data": t_dic},
                                                     "send")

    except Exception, e:
        ct.log().add(traceback.format_exc(), __file__)
        message().error(u"(bulk_upload_to_online)上传失败:\n" + e.message)
示例#3
0
    def image_stitching(self, a_argv, a_tw):
        # 仕煌
        '''
        多张图片拼接成新图片,#图片拼接,并生成一个新的图片,不复制原先的图片
        0.  action : image_stitching  (必填)
        '''
        t_argv = a_argv
        t_sou_list = t_argv.get_sys_file()  # 取固定的系统数据
        t_folder = t_argv.get_sys_folder()  # 取文件框对应的目录.
        if t_folder == False or str(t_folder) == "":
            return self.ct_false(u"取目录失败")
        if os.path.exists(t_folder) == False:
            return self.ct_false(u"目录(" + t_folder + u")未创建")

        if isinstance(t_sou_list, list) == False:
            return self.ct_false(u"提交文件类型错误")
        if len(t_sou_list) <= 0:
            return self.ct_false(u"没有找到提交文件")

        try:
            des_file_path = ""
            total = ""
            t_uuid_file_list = []
            t_sou_list.sort()
            for i in t_sou_list:
                if des_file_path == "":
                    des_file_path = t_folder + "/" + os.path.basename(i)
                if ct.com().exist_chinese(i):  # 是否存在中文命名
                    temp_file = ct.com().get_tmp_path() + "/" + str(
                        ct.com().uuid()) + "." + os.path.splitext(i)[1]
                    if os.path.exists(temp_file):
                        os.remove(temp_file)
                    #===============骁颖==2018.06.15=====================
                    #shutil.copyfile(i, temp_file)
                    ct.file().copy_file(i, temp_file)
                    #===============骁颖==2018.06.15=====================

                    t_uuid_file_list.append(temp_file)
                    total = total + ' ' + '"' + temp_file + '"'
                else:
                    total = total + ' ' + '"' + i + '"'
            res = self.__convert_image_stitching(
                total,
                os.path.splitext(des_file_path)[1])
            if res == False:
                return self.ct_false(u"调用转换命令,拼接失败")
            else:
                if os.path.exists(des_file_path):
                    os.remove(des_file_path)

                #===============骁颖==2018.06.15=====================
                #shutil.copyfile(res, des_file_path)
                ct.file().copy_file(res, des_file_path)
                #===============骁颖==2018.06.15=====================
            for i in t_uuid_file_list:
                os.remove(i)

            # 停止后续的插件/或者动作
            return self.ct_stop_next()
        except Exception, e:
            return self.ct_false(u"拼接图片失败")
示例#4
0
    def __copy_files_sign(self, a_des_dir, a_sou_file_path, a_is_move_history,
                          a_replace_str):
        """
        复制移动文件或文件夹
        """

        t_sou_file_name = os.path.basename(a_sou_file_path)
        t_des_file_name = t_sou_file_name
        # ---a_replace_str 重命名
        try:
            if a_replace_str != False and a_replace_str.strip() != "":
                t_replace_list = a_replace_str.split("|")
                for i in t_replace_list:
                    replace_list = i.split(",")
                    if len(replace_list) == 2:
                        t_des_file_name = re.sub(
                            self.__re_rule(replace_list[0]), replace_list[1],
                            t_des_file_name)
        except:
            # print traceback.print_exc()
            return u"重命名文件异常 --> " + t_sou_file_name + "\n"

        t_des_file_path = unicode(a_des_dir + '/' + t_des_file_name).replace(
            "\\", "/")  #

        t_sou_path_list = []
        # --判断是否是文件夹'
        if os.path.isdir(a_sou_file_path):
            t_sou_path_list = ct.file().get_file_with_walk_folder(
                a_sou_file_path)
        else:
            t_sou_path_list = [a_sou_file_path]

        date = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        try:
            for i in t_sou_path_list:
                des_path = unicode(i).replace("\\", "/").replace(
                    a_sou_file_path, t_des_file_path)
                if os.path.exists(des_path) and unicode(
                        a_is_move_history).strip().lower() == "y":
                    t_history_file_path = unicode(des_path).replace(
                        a_des_dir + "/", a_des_dir + '/history/' + date + "/")
                    if not os.path.exists(
                            os.path.dirname(t_history_file_path)):
                        os.makedirs(
                            os.path.dirname(t_history_file_path))  # --创建历史文件夹
                    shutil.move(des_path, t_history_file_path)

                if not os.path.exists(os.path.dirname(des_path)):
                    os.makedirs(os.path.dirname(des_path))  # --创建历史文件夹

                # ------------------------骁颖-----------------------

                #===============骁颖==2018.06.15==================
                #shutil.copyfile(i, des_path)
                ct.file().copy_file(i, des_path)

                #try:
                #shutil.copystat(i, des_path)
                #except:
                #pass
                #===============骁颖==2018.06.15==================

                # shutil.copy2(i, des_path )
                # ------------------------骁颖-----------------------
        except Exception, e:
            # print traceback.print_exc()
            return u"复制失败 " + a_sou_file_path + " --> " + t_des_file_path + "\n"
示例#5
0
    def drag_image_get_thumbnail(self, a_argv, a_tw):
        """
        Author:    黄骁颖
        Purpose:   拖入图片生成缩略图
        Created:   2018-07-03

        文件筐插件,拖入图片/右键选择图片(可以选择/拖入文件夹):
        0.  action: drag_image_get_thumbnail  (必填)
        1:  allow_format,    允许格式           ex: .png|.tif   key可以不填写
        2:  ban_format,      禁止格式           ex: .jpg|.dpx   key可以不填写
        3:  image_sign,      生成缩略图字段标识  ex: shot.image  key可以不填写,默认为task.image
        4:  des_file_sign    拷贝到目标目录标识  ex: maya_work   key可以不填写
        5:  is_get_folder    是否查询目录内的图片ex: Y/N         key可以不填写
        """
        try:

            INFO_FIELD_SIGN = 1  # 信息模块标志
            TASK_FIELD_SIGN = 2  # 制作模块标志

            t_argv = a_argv
            t_tw = a_tw
            t_database = t_argv.get_sys_database()
            t_id_list = t_argv.get_sys_id()

            t_drag_file_list = t_argv.get_sys_file()
            t_module = t_argv.get_sys_module()
            t_module_type = t_argv.get_sys_module_type()

            k_allow_format = t_argv.get_argv_key("allow_format")  # 允许格式
            k_ban_format = t_argv.get_argv_key("ban_format")  # 禁止格式
            k_image_sign = t_argv.get_argv_key("image_sign")  # 生成缩略图字段标识
            k_des_file_sign = t_argv.get_argv_key("des_file_sign")  # 拷贝到目标目录标识
            k_is_get_folder = t_argv.get_argv_key(
                "is_get_folder")  # 是否要查询目录内的图片

            # ------配置缩略图字段标识处理
            t_image_sign_type = TASK_FIELD_SIGN
            t_image_sign = "task.image"  # 默认为制作的缩略图

            if k_image_sign != False and str(k_image_sign).strip() != "":
                if len(k_image_sign.split(".")) == 2:
                    if k_image_sign.split(".")[0] == "task":
                        t_image_sign_type = TASK_FIELD_SIGN
                        t_image_sign = k_image_sign
                    elif k_image_sign.split(".")[0] == t_module:
                        t_image_sign_type = INFO_FIELD_SIGN
                        t_image_sign = k_image_sign
                    else:
                        return self.ct_false(u"需要更新的缩略图字段标识错误!")
                else:
                    return self.ct_false(u"需要更新的缩略图字段标识错误!")

            if t_module_type == 'task':
                t_image_sign_type = TASK_FIELD_SIGN
            elif t_module_type == 'info':
                t_image_sign_type = INFO_FIELD_SIGN

            # ------允许格式处理
            t_allow_format = False
            if k_allow_format != False and str(k_allow_format).strip() != "":
                t_allow_format = k_allow_format.split("|")

            # ------禁止格式处理
            t_ban_format = False

            if k_ban_format != False and str(k_ban_format).strip() != "":
                t_ban_format = k_ban_format.split("|")

            # ------获取文件list处理

            if k_is_get_folder != False and unicode(
                    k_is_get_folder).strip().lower() == "y":
                t_new_list = []
                for i in t_drag_file_list:
                    if os.path.isdir(i):
                        lists = []
                        for i in ct.file().get_path_list(i):
                            if i.strip().lower().find(
                                    "thumbs.db") == -1 and i.strip().lower(
                                    ).find(".ini") == -1:
                                lists.append(i)
                        if len(lists) > 0:
                            t_new_list.append(lists[0])
                    else:
                        t_new_list.append(i)

            else:
                t_new_list = t_drag_file_list

            # ------处理需要生成的缩略图的文件格式
            t_image_list = []
            if t_allow_format != False:
                for temp in t_new_list:
                    if os.path.isfile(temp.replace(
                            "\\", "/")) and os.path.splitext(
                                temp.replace("\\", "/"))[-1] in t_allow_format:
                        t_image_list.append(temp.replace("\\", "/"))
            else:
                if t_ban_format != False:
                    for temp in t_new_list:
                        if os.path.isfile(temp.replace(
                                "\\", "/")) and not os.path.splitext(
                                    temp.replace("\\",
                                                 "/"))[-1] in t_ban_format:
                            t_image_list.append(temp.replace("\\", "/"))
                else:
                    t_image_list = t_new_list

            # -----开始生成缩略图

            if t_image_sign_type == TASK_FIELD_SIGN:
                try:
                    t_tw.task_module(t_database, t_module,
                                     t_id_list).set_image(
                                         t_image_sign, t_image_list)
                except Exception, e:
                    return self.ct_false(u"生成缩略图失败%s" % str(unicode(e)))

            elif t_image_sign_type == INFO_FIELD_SIGN:
                try:
                    t_info_id = t_tw.info_module(
                        t_database, t_module,
                        t_id_list).get([t_module + ".id"])[0][t_module + ".id"]
                    t_tw.info_module(t_database, t_module,
                                     [t_info_id]).set_image(
                                         t_image_sign, t_image_list)

                except Exception, e:
                    return self.ct_false(u"生成缩略图失败")
示例#6
0
    def drag_mov_get_thumbnail(self, a_argv, a_tw):
        """
        Author:  黄骁颖
        Purpose: 拖入mov生成缩略图并检查帧数
        Created: 2018-07-03

        文件筐插件,拖入mov/右键mov(可以选择/拖入文件夹):
        0.  action: drag_mov_get_thumbnail  (必填)
        1:  is_get_thumbnail, 是否更新缩略图      ex: Y/N           key可以不填写
        2:  is_update_frame,  是否更新帧数         ex: Y/N          key可以不填写
        3:  is_check_frame,   是否检查帧数         ex: Y/N          key可以不填写
        4:  is_get_folder,    是否查询目录里的文件         ex: Y/N   key可以不填写
        5:  image_sign,       生成缩略图字段标识   ex: shot.image    key可以不填写
        6:  des_file_sign,    拷贝到目标目录标识   ex: maya_work     key可以不填写
        7: frame_rate,       帧率               ex:24            key可以不填写
        8:  width             宽                                  key可以不填写
        9:  height            高                                  key可以不填写
        """
        try:
            t_tw = a_tw
            t_argv = a_argv
            k_is_get_thumanil = t_argv.get_argv_key("is_get_thumbnail")
            k_is_update_frame = t_argv.get_argv_key("is_update_frame")
            k_is_check_frame = t_argv.get_argv_key("is_check_frame")
            k_is_get_folder = t_argv.get_argv_key("is_get_folder")
            k_image_sign = t_argv.get_argv_key("image_sign")
            k_des_file_sign = t_argv.get_argv_key("des_file_sign")
            k_frame_rate = t_argv.get_argv_key("frame_rate")
            k_width = t_argv.get_argv_key("width")
            k_height = t_argv.get_argv_key("height")
            t_database = t_argv.get_sys_database()
            t_id_list = t_argv.get_sys_id()
            t_module = t_argv.get_sys_module()
            t_module_type = t_argv.get_sys_module_type()
            t_sou_list = t_argv.get_sys_file()  # 取固定的系统数据

            INFO_FIELD_SIGN = 1  # 信息模块标识
            TASK_FIELD_SIGN = 2  # 制作模块标识

            #t_fail_list = []

            # 获取文件list处理
            if k_is_get_folder != False and unicode(
                    k_is_get_folder).strip().lower() == "y":
                t_new_list = []
                for i in t_sou_list:
                    if os.path.isdir(i):
                        t_new_list = t_new_list + ct.file().get_path_list(i)
                    else:
                        t_new_list.append(i)
            else:
                t_new_list = t_sou_list

            for i in t_new_list:
                if os.path.isfile(i):
                    t_fileUrl = i.replace("\\", "/")
                    # 获取视频信息及缩略图------------------------------------
                    try:
                        t_avi_info = ct.mov().get_avi_info(i)
                        t_fate = t_avi_info["FrameRate"]
                        t_frame = t_avi_info["FrameCount"]
                        t_avi_thumanil = ct.com().get_tmp_path(
                        ) + "/" + ct.com().uuid() + ".png"
                        ct.mov().get_mov_thumbnail(
                            i, t_avi_thumanil.replace("\\", "/"))
                        t_thumanil = t_avi_thumanil.replace("\\", "/")
                        t_avi_info_dict = t_avi_info
                    except Exception, e:
                        return self.ct_false(t_fileUrl + u": 获取视频信息失败")
                        #t_fail_list.append(t_fileUrl + u": 获取视频信息失败")
                        #continue
                    # 检查宽高-----------------------------------------------
                    try:
                        if str(k_width).strip() != "" and k_width != False:
                            if t_avi_info_dict != False and t_avi_info_dict.has_key(
                                    "Width"):
                                if int(k_width) != int(
                                        t_avi_info_dict["Width"]):
                                    return self.ct_false(
                                        t_fileUrl +
                                        u": 宽度不正确:-----系统宽度-----mov宽度\n" +
                                        u"-----" + str(int(k_width)) +
                                        u"-----" +
                                        str(int(t_avi_info_dict["Width"])))
                                    #t_fail_list.append(t_fileUrl + u": 宽度不正确:-----系统宽度-----mov宽度\n" + u"-----" + str(int(k_width)) + u"-----" + str(int(t_avi_info_dict["Width"])))
                                    #continue
                            else:
                                return self.ct_false(t_fileUrl +
                                                     u": 读取mov分辨率出错")
                                #t_fail_list.append(t_fileUrl + u": 读取mov分辨率出错")
                                #continue

                        if str(k_height).strip() != "" and k_height != False:
                            if t_avi_info_dict != False and t_avi_info_dict.has_key(
                                    "Heigh"):
                                if int(k_height) != int(
                                        t_avi_info_dict["Heigh"]):
                                    return self.ct_false(
                                        t_fileUrl +
                                        u": 高度不正确:-----系统高度-----mov高度\n" +
                                        u"-----" + str(int(k_height)) +
                                        u"-----" +
                                        str(int(t_avi_info_dict["Heigh"])))
                                    #t_fail_list.append(t_fileUrl + u": 高度不正确:-----系统高度-----mov高度\n" + u"-----" + str(int(k_height)) + u"-----" + str(int(t_avi_info_dict["Heigh"])))
                                    #continue
                            else:
                                return self.ct_false(t_fileUrl +
                                                     u": 读取mov分辨率出错")
                                #t_fail_list.append(t_fileUrl + u": 读取mov分辨率出错")
                                #continue
                    except Exception, e:
                        return self.ct_false(t_fileUrl + u": 检查分辨率发生未知错误!")
                        #t_fail_list.append(t_fileUrl + u": 检查分辨率发生未知错误!")
                        #continue

                    # 检查帧率----------------------------------------------
                    try:
                        if str(k_frame_rate).strip(
                        ) != "" and k_frame_rate != False:
                            if int(float(k_frame_rate)) != int(float(t_fate)):
                                return self.ct_false(
                                    t_fileUrl +
                                    u": 帧率不正确:-----系统帧率-----mov帧率\n" +
                                    u"-----" + str(int(float(k_frame_rate))) +
                                    u"-----" + str(int(float(t_fate))))
                                #t_fail_list.append(t_fileUrl + u": 帧率不正确:-----系统帧率-----mov帧率\n" + u"-----" + str(
                                #int(float(k_frame_rate))) + u"-----" + str(int(float(t_fate))))
                                #continue
                    except Exception, e:
                        return self.ct_false(t_fileUrl + u": 检查帧率发生未知错误!")
                        #t_fail_list.append(t_fileUrl + u": 检查帧率发生未知错误!")
                        #continue

                    # 检查帧数----------------------------------------------
                    if str(k_is_check_frame).strip().lower() == "y":
                        try:
                            t_info_id = t_tw.task_module(
                                t_database, t_module,
                                t_id_list).get([t_module + ".id"
                                                ])[0][t_module + ".id"]
                            t_frmaes = t_tw.info_module(
                                t_database, "shot",
                                [t_info_id]).get(["shot.frame"
                                                  ])[0]["shot.frame"]
                            if t_frmaes == "None" or t_frmaes == False or t_frmaes == "" or t_frmaes == None:
                                t_frmaes = 0
                            if int(t_frame) != int(t_frmaes):
                                return self.ct_false(
                                    t_fileUrl +
                                    u": 帧数不正确:-----系统帧数-----mov帧数\n" +
                                    u"-----" + str(int(t_frmaes)) + u"-----" +
                                    str(int(t_frame)))
                                #t_fail_list.append(t_fileUrl + u": 帧数不正确:-----系统帧数-----mov帧数\n" + u"-----" + str(
                                #int(t_frmaes)) + u"-----" + str(int(t_frame)))
                                #continue
                        except Exception, e:
                            return self.ct_false(t_fileUrl +
                                                 u": 检查/更新帧数,发生未知错误!")
示例#7
0
            if k_des_file_sign != False and str(k_des_file_sign).strip() != "":
                try:
                    t_des_path = t_tw.task_module(t_database, t_module,
                                                  t_id_list).get_dir([
                                                      k_des_file_sign
                                                  ])[0][k_des_file_sign]
                except Exception, e:
                    return self.ct_false(u"读取目标目录失败!")
                # -------------------------
                try:
                    for i in t_drag_file_list:
                        t_des_file_path = t_des_path + "/" + os.path.basename(
                            i)
                        #===============骁颖==2018.06.15=====================
                        #shutil.copy(i, t_des_file_path)
                        ct.file().copy_file(i, t_des_file_path)
                        #===============骁颖==2018.06.15=====================
                        if os.path.exists(t_des_file_path) == False:

                            return self.ct_false(u'拷贝失败:\n')
                except Exception, e:
                    return self.ct_false(u'没有权限或目录标志不存在:\n')
                # -------------------------
            return self.ct_true()  # 正确返回true,如果要给后面的插件传递值的话。在这边加上
        except Exception, e:
            # print traceback.format_exc()
            return self.ct_false(u'插件执行失败:\n%s' % str(unicode(e)))

    def drag_mov_get_thumbnail(self, a_argv, a_tw):
        """
        Author:  黄骁颖
示例#8
0
def com_copy(a_sou_argv, a_des_argv, a_time=False, a_add_str=False, a_replace_str=False, a_work_log_signal=False, a_work_log_function=False, a_fail_str=False, a_keep_structure=False, a_is_folder_son=False, a_is_cover=False, a_is_copy_all='Y'):
    #-----------源---------目标----------时间-------改名追加字符串------改名替换字符串-----------工作日志信号-------------工作日志类-----------------失败字符串------是否保存目录架构--------源的目录是否是目录的子层--是否覆盖----------是否拷贝全部文件('N'为拷贝最大版本)
    #-------->时间
    if a_time==False:
        t_time = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
    else:
        t_time = a_time

        
    #--------源与目标处理
    t_sou_list      = []
    t_des_list      = []
    t_history_list  = []

    if not isinstance(a_sou_argv, list) and not isinstance(a_des_argv, list):
        #-------->str,str(字符串->字符串),这时源,目标为同一类型!不考虑保持目录结构!
        a_sou_argv = com_replace_path( a_sou_argv )
        a_des_argv = com_replace_path( a_des_argv )
        if os.path.exists(a_sou_argv.replace("\\","/")):
            temp_sou = a_sou_argv.replace("\\","/")
            temp_des = a_des_argv.replace("\\","/")
            if os.path.isfile( temp_sou ):
                temp_history = os.path.join(os.path.dirname(temp_des), "history")
            else:
                temp_history = os.path.join(temp_des, "history")
                if a_is_folder_son:
                    temp_des = os.path.join(a_des_argv.replace("\\","/"), os.path.basename(temp_sou))
            t_sou_list.append(         temp_sou.replace("\\", "/") )
            t_des_list.append(         temp_des.replace("\\", "/") )
            t_history_list.append( temp_history.replace("\\", "/") )

    if isinstance(a_sou_argv, list) and not isinstance(a_des_argv, list):

        #-------->list,str(列表->字符串),这时源做判断,目标为文件夹!考虑保持目录结构!
        a_des_argv = com_replace_path( a_des_argv )
        for temp in a_sou_argv:

            temp = com_replace_path( temp )
            if os.path.exists(temp):

                if a_keep_structure:

                    temp_sou     = temp
                    if os.path.splitdrive(unicode(temp_sou))[0]=="":#mac
                        temp_des = a_des_argv.replace("\\","/") + "/" + temp_sou
                    else:#win
                        temp_des = temp_sou.replace( os.path.splitdrive(unicode(temp_sou))[0] , a_des_argv.replace("\\","/") )
                    temp_history = os.path.join(a_des_argv.replace("\\","/"), "history")
                    t_sou_list.append(         temp_sou.replace("\\", "/") )
                    t_des_list.append(         temp_des.replace("\\", "/") )
                    t_history_list.append( temp_history.replace("\\", "/") )
                else:
   
                    temp_sou     = temp
                    if os.path.isfile(temp_sou):
                        temp_des     = os.path.join(a_des_argv.replace("\\","/"), os.path.basename(temp_sou))
                    else:
                        temp_des     = a_des_argv.replace("\\","/")
                    temp_history = os.path.join(a_des_argv.replace("\\","/"), "history")
                    if a_is_folder_son and os.path.isdir( temp_sou ):
                        temp_des = os.path.join(a_des_argv.replace("\\","/"), os.path.basename(temp_sou))
                    t_sou_list.append(         temp_sou.replace("\\", "/") )
                    t_des_list.append(         temp_des.replace("\\", "/") )
                    t_history_list.append( temp_history.replace("\\", "/") )

    if isinstance(a_sou_argv, list) and isinstance(a_des_argv, list):

        #-------->list,list(列表->列表)这时源,目标为同一类型!不考虑保持目录结构!
        for i in range(len(a_sou_argv)):
            if os.path.exists(a_sou_argv[i]):
                temp_sou = com_replace_path( a_sou_argv[i].replace("\\","/") )
                temp_des = com_replace_path( a_des_argv[i].replace("\\","/") )
                if os.path.isfile( temp_sou ):
                    temp_history = os.path.join(os.path.dirname(temp_des), "history")
                else:
                    temp_history = os.path.join(temp_des, "history")
                    if a_is_folder_son:
                        temp_des = os.path.join(temp_des, os.path.basename(temp_sou))
                t_sou_list.append(         temp_sou.replace("\\", "/") )
                t_des_list.append(         temp_des.replace("\\", "/") )
                t_history_list.append( temp_history.replace("\\", "/") )
 
#---------------------------------------------------------------------------骁颖------------------------------------------------------------------------ 
    for s in range(len(t_sou_list)):

        t_sou_file     = t_sou_list[s]
        t_des_file     = t_des_list[s]
        t_history_path = t_history_list[s]
        
        t_sou_file     = com_replace_path( t_sou_file )
        t_des_file     = com_replace_path( t_des_file )   
        t_history_path = com_replace_path( t_history_path )        


        if os.path.isfile( t_sou_file ):#file   -> file
            t_sou_file_list = [t_sou_file.replace("\\","/")]
            t_des_file_list = [t_des_file.replace("\\","/")]
            t_history_lists = [t_history_path.replace("\\","/")]
        else:                  #folder -> folder

            t_sou_file_list = []
            t_des_file_list = []
            t_history_lists = []
            t_choose_max_file = []
            if unicode(a_is_copy_all).strip().lower()!="y":  #最大版本
                for i in os.listdir(t_sou_file): #---过滤Thumbs 和 历史文件夹 
                    if i == 'Thumbs.db':
                        continue
                    if i == u'history' and os.path.isdir(os.path.join(t_sou_file,i).replace('\\','/')):
                        continue
                    try:
                        t_choose_max_file.append( os.path.join(t_sou_file,i).decode("gbk").replace("\\","/") )
                    except Exception,e:
                        t_choose_max_file.append( os.path.join(t_sou_file,i).replace("\\","/") )   

                if len(t_choose_max_file)>0:
                    t_max_file_version = __sorted(t_choose_max_file, True)[0] #排序取最大版本
    
                    if os.path.isdir(t_max_file_version):
                       #----若最大版本是文件夹
                        for i in ct.file().get_file_with_walk_folder(t_max_file_version):
                            try:
                                t_sou_file_list.append( i.decode("gbk").replace("\\","/") )
                                t_des_file_list.append( i.decode("gbk").replace("\\","/").replace(t_sou_file,t_des_file) )
                                t_history_lists.append(  t_history_path.replace("\\","/")  )
                            except Exception,e:
                                t_sou_file_list.append( i.replace("\\","/") )
                                t_des_file_list.append( i.replace("\\","/").replace(t_sou_file,t_des_file) )
                                t_history_lists.append(  t_history_path.replace("\\","/")  ) 
                                
                    else:  #---最大版本不是文件夹
                        try:
                            t_sou_file_list.append( t_max_file_version.decode("gbk").replace("\\","/") )
                            t_des_file_list.append( t_max_file_version.decode("gbk").replace("\\","/").replace(t_sou_file,t_des_file) )
                            t_history_lists.append(  t_history_path.replace("\\","/")  )
                        except Exception,e:
                            t_sou_file_list.append( t_max_file_version.replace("\\","/") )
                            t_des_file_list.append( t_max_file_version.replace("\\","/").replace(t_sou_file,t_des_file) )
                            t_history_lists.append(  t_history_path.replace("\\","/")  )                    
示例#9
0
                    else:  #---最大版本不是文件夹
                        try:
                            t_sou_file_list.append( t_max_file_version.decode("gbk").replace("\\","/") )
                            t_des_file_list.append( t_max_file_version.decode("gbk").replace("\\","/").replace(t_sou_file,t_des_file) )
                            t_history_lists.append(  t_history_path.replace("\\","/")  )
                        except Exception,e:
                            t_sou_file_list.append( t_max_file_version.replace("\\","/") )
                            t_des_file_list.append( t_max_file_version.replace("\\","/").replace(t_sou_file,t_des_file) )
                            t_history_lists.append(  t_history_path.replace("\\","/")  )                    
                


                
            else:   #所有文件   

                for i in ct.file().get_file_with_walk_folder( t_sou_file ):

                    if os.path.basename(i) == u'Thumbs.db':
                        continue
                
                    if u'/history' in os.path.dirname(i):
                        continue
                    try:
                        t_sou_file_list.append( i.decode("gbk").replace("\\","/") )
                        t_des_file_list.append( i.decode("gbk").replace("\\","/").replace(t_sou_file,t_des_file) )
                        t_history_lists.append(  t_history_path.replace("\\","/")  )
                    except Exception,e:
                        print unicode(e)
                        t_sou_file_list.append( i.replace("\\","/") )
                        t_des_file_list.append( i.replace("\\","/").replace(t_sou_file,t_des_file) )
                        t_history_lists.append(  t_history_path.replace("\\","/")  )