示例#1
0
def init_gen_dir(name: str, style_file: str) -> None:
    """
    Creates the `gen` directory with all necessary files.
    """
    safe_create_directory(name)
    stylesheet_file: str = "/" + style_file
    favicon_file: str = "favicon.ico"
    copy_file(constants.IN_DIR + stylesheet_file, name + stylesheet_file)
    copy_file(favicon_file, name + "/" + favicon_file)
示例#2
0
 def set_current(self, version):
     # 设置当前文件,将当前放入版本库,并将被设置文件设为当前
     # move self.path to self.hist_dir
     self.add_to_version()
     # clear current path
     self._clear_current()
     # copy file to current
     file_src_path = self.__get_version_file_path(version)
     json_src_path = self.__get_file_json_path(version)
     json_tar_path = self.__get_file_json_path(None)
     copy_file(file_src_path, self.path)
     copy_file(json_src_path, json_tar_path)
     # set version to None
     self.set_version_info(set_dict={"version": None})
     logging.info(
         "set version {version} to current ".format(version=version))
示例#3
0
def bach_move_file():
    # input dst_dir
    dst_dir = r"D:\Ben\Python\TDClass\lesson4\new_ic"  # FIXME
    if not os.path.exists(dst_dir):
        os.mkdir(dst_dir)
    # 找出贴图文件节点
    all_file_nodes = pm.ls(type='file')
    # 循环提取加修改
    for file_node in all_file_nodes:
        # 在节点里提取文件路径
        file_path = file_node.fileTextureName.get()
        # 把文件路径分解为 路径:"scr_dir" 文件名:“scr_name"
        scr_dir, scr_name = os.path.split(file_path)
        # 调用 copy_file 拷贝文件
        cf.copy_file(scr_dir, scr_name, dst_dir)
        # set path to destination directory
        file_node.fileTextureName.set(dst_dir + os.sep + scr_name)
示例#4
0
    def drop_in(self, file_path, message="no description..."):
        # 新增文件,将当前放入版本库,并将新文件设为当前

        if self.__has_current_file():
            if not self.__has_json_file():
                self.__make_json_file(self.path)
            if not self.__has_history():
                # create self.hist_dir
                os.makedirs(self.hist_dir)
            # move self.path to self.hist_dir
            self.add_to_version()
            # clear current path
            self._clear_current()
        # make json file
        self.__make_json_file(file_path=file_path, message=message)
        # copy file to path
        copy_file(file_path, self.path)
示例#5
0
 def add_to_version(self):
     # 将文件放入版本库中
     src_file_dict = self.get_version_info()
     src_file_hash = src_file_dict["file_MD5"]
     version_list = self.list_versions()
     for version in version_list:
         version_dict = self.get_version_info(version)
         version_hash = version_dict["file_MD5"]
         if src_file_hash == version_hash:
             logging.debug("this file already exists in the folder...")
             return
     # get version num
     new_version = self.get_last_version()+1
     # update json file
     if self.set_version_info(set_dict={"version": new_version}):
         file_tar_path = self.__get_version_file_path(new_version)
         json_src_path = self.__get_file_json_path(None)
         json_tar_path = self.__get_file_json_path(new_version)
         # move file into history folder
         copy_file(self.path, file_tar_path)
         copy_file(json_src_path, json_tar_path)
         logging.debug("copy {file_path} and {josn_path} into {hist_path}".format(
             file_path=self.path, josn_path=json_src_path, hist_path=self.hist_dir))
示例#6
0
def indicated_date():
    arr = []
    ek_book = 0
    date_of = 0
    plot = 0
    decision = 0
    service = 0
    i = 0

    wdFormatDOCX = 16

    copyfile = copy_file(ind_date())
    input_dir = copyfile[0]
    output_dir = copyfile[1]
    date_result = copyfile[2]
    print("Создание временных файлов")
    print(
        "----------------------------------------------------------------------"
    )
    for subdir, dirs, files in os.walk(input_dir):
        for file in files:
            if file == "newfile.txt":
                continue
            in_file = os.path.join(subdir, file)
            output_file = file.split('.')[0]
            out_file = output_dir + output_file + ".docx"
            word = comtypes.client.CreateObject('Word.Application')
            # word = win32com.client.Dispatch('Word.Application')
            doc = word.Documents.Open(in_file)
            doc.SaveAs(out_file, FileFormat=wdFormatDOCX)
            print("Преобразование файла: " + output_file)
            doc.Close()
            word.Quit()
        break

    # directory_open = "./test/"  # Linux
    directory_open = copyfile[1]  # windows open file
    filename = os.listdir(directory_open)
    f = open(copyfile[0] + 'newfile.txt', 'w+')
    f.write("Файлы за: " + date_result + "\n")
    print(
        "----------------------------------------------------------------------"
    )
    print("Анализ файлов")
    print(
        "----------------------------------------------------------------------"
    )
    for fn in filename:
        row_first = 0
        print("Анализ: " + fn)
        doc_open_name = copyfile[1] + fn  # windows open file
        # doc_open_name = "./test/" + fn  # Linux
        wordDoc = Document(doc_open_name)
        len_par = len(wordDoc.paragraphs)
        temp_name = check_name_file(len_par, f, wordDoc)
        for table in wordDoc.tables:
            for row in table.rows:
                for cell in row.cells:
                    dubtext = cell.text.lower()
                    dubtext = dubtext.replace('\n', ' ').split()
                    dubtext = ' '.join(dubtext)
                    arr.append(dubtext)
                if row_first == 0:
                    for value in arr:
                        if re.findall(r"\bслово", value) or re.findall(
                                r"\bслово.", value) or re.findall(
                                    r"\bслово", value) or re.findall(
                                        r"\bслово", value) or re.findall(
                                            r"\bслово", value):
                            if temp_name == 'Слово':
                                ek_book = 0
                            else:
                                ek_book = arr.index(value)
                        elif re.findall(r"\bслово", value.replace(
                                " ", "")) or re.findall(
                                    r"слово слово", value.replace(" ", " ")):
                            plot = arr.index(value)
                        elif re.findall(r"\bслово", value):
                            decision = arr.index(value)
                        elif re.findall(r"\bслово", value):
                            service = arr.index(value)
                    row_first = 1
                    arr.clear()
                else:
                    arr[service] = ''
                    for value in arr:
                        for string in other_word:
                            regul = re.findall(string, value)
                            if regul:
                                f.write(str(temp_name))
                                while True:
                                    i += 1
                                    final_text = "№" + str(i) + "  |" + arr[ek_book] + " | " + arr[plot] + " | " \
                                                 + arr[decision] + "| "
                                    if len(final_text) < 110:
                                        f.write("{:<}".format(
                                            final_text[:110]))
                                        f.write("\n")
                                    else:
                                        while len(final_text) > 110:
                                            f.write(final_text[:110])
                                            f.write("\n")
                                            final_text = final_text[110:]
                                        f.write(final_text[:110])
                                        f.write("\n")
                                    break
                                break
                    arr.clear()
    text_ = ind(copyfile)
    f.write("\n" + 'Колличество' + " " + str(i) + '\n')
    for text in text_:
        if len(text) < 110:
            f.write('\n' + "{:<}".format(text[:110]))
        else:
            while len(text) > 110:
                f.write('\n' + text[:110])
                text = text[110:]
            f.write("\n")
            f.write(text[:110])
            f.write("\n")
    f.close()
    print(
        "----------------------------------------------------------------------"
    )
    print("Удаление временных файлов")
    print(
        "----------------------------------------------------------------------"
    )
    del_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                            copyfile[1])
    shutil.rmtree(del_path)
    open_result_file = copyfile[0] + 'newfile.txt'
    os.system(open_result_file)