def __init__(self, input_new_path): super(CrwateNewFolder, self).__init__() self.new_path = input_new_path self.FRobot = FileRobot() self.new_main_path = self.FRobot.get_deep_folder_path( self.new_path, 'main') self.new_mini_path = self.FRobot.get_deep_folder_path( self.new_path, 'mini') if not os.path.exists(self.new_main_path): self.FRobot.creat_folder(self.new_path, 'main') if not os.path.exists(self.new_mini_path): self.FRobot.creat_folder(self.new_path, 'mini') self.database_path = self.FRobot.get_deep_folder_path( home_path, 'database') self.log_path = self.FRobot.get_deep_folder_path(home_path, 'LogFile') self.TLog = TaskLog(input_log_path=self.log_path, input_database_path=self.database_path)
#!/usr/bin/env python #-*-coding:utf-8-*- #处理任务log的类,可以获取新的task,改变制定行task的状态码,封装一个task数据包 # 这里是下载图像库的task,每一个task定义为全部下载一个3级view下的所有图片 #task数据包的格式,相对与database的路径;状态码;所属编号 from FileRobotClass import FileRobot import os, sys, codecs import re FRobot = FileRobot() line_num_store = 1 # database_path=FRobot.get_deep_folder_path(home_path,'database') # log_path=FRobot.get_deep_folder_path(home_path,'LogFile') num2text = {2: 'a植物', 3: 'b植物', 4: 'c植物', 5: 'd植物'} class TaskLog(): def __init__(self, input_log_path='', input_database_path=''): self.log_path = input_log_path self.database_path = input_database_path self.home_path = sys.path[0] #当前路径 pass # 读取总日志,注意调试时file_read用完一次要关闭,否则它会继续原来的地方读取 def read_plan_log(self, line_ind): file_read = codecs.open(self.log_path + '\PlanLog.txt', 'r', 'utf-8') log_line = file_read.readlines()[line_ind - 1] task_dic = {'URL': '', 'Text': ''} task_dic['statecode'] = int(log_line.split('statecode')[1])
#!/usr/bin/env python #-*-coding:utf-8-*- import socket import threading import time import os,sys from TCPClass import TCP from FileRobotClass import FileRobot from TaskLogClass import TaskLog # server1=TCP(2) # server1.server_start() home_path=sys.path[0] #当前路径 FRobot=FileRobot() database_path=FRobot.get_deep_folder_path(home_path,'database') log_path=FRobot.get_deep_folder_path(home_path,'LogFile') TLog=TaskLog(input_log_path=log_path,input_database_path=database_path) # 创建所有log文件 for i in range(1,85): i_log_name=TLog.get_logname_by_Index(i) FRobot.write_text(log_path,i_log_name,'',style_flag=1) # 遍历文件夹,每个task写入log p_list=['B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','W','X','Y','Z'] m_dic={'2': '苔藓植物','3': '蕨类植物','4': '裸子植物','5': '被子植物' } for m in m_dic: current_path_m = FRobot.get_deep_folder_path(database_path, m_dic[m]) for p in p_list: current_path_p=FRobot.get_deep_folder_path(current_path_m,p) log_name=m_dic[m]+'_'+p print(log_name)
client_inputIP_timeout = 3 #客户端没有与服务器建立相应的话,多久后重新输入IP server_conform_message = b'ConnectSuccess?' #连接建立后服务器发送的确认信息 client_conform_message = b'YesSuccess' #连接建立后客户端确认 client_ask_task_message = b'SendTaskPlease' #请求task client_send_task_result_message = b'TaskProcessOver' #发送一个task处理结果 task_none = b'NoTask' #没有task了 environment_flag = 1 #1本地 2打包后的地址 if environment_flag == 1: home_path = sys.path[0] #当前路径 else: now_path = sys.path[0] home_path = now_path.split('\dist')[0] FRobot = FileRobot() database_path = FRobot.get_deep_folder_path(home_path, 'database') log_path = FRobot.get_deep_folder_path(home_path, 'LogFile') TLog = TaskLog(input_log_path=log_path, input_database_path=database_path) class TCP(): def __init__(self, input_TCPtype, input_server_IP=server_IP): self.TCPtype = input_TCPtype #1客户端 2服务器 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.hostname = socket.gethostname() #主机名称 if self.TCPtype == 2: self.Local_IP = '172.17.228.44' # self.Local_IP = socket.gethostbyname(self.hostname) #自身IP,对于服务器端就是TCP网络的控制中心IP else:
class CrwateNewFolder(): def __init__(self, input_new_path): super(CrwateNewFolder, self).__init__() self.new_path = input_new_path self.FRobot = FileRobot() self.new_main_path = self.FRobot.get_deep_folder_path( self.new_path, 'main') self.new_mini_path = self.FRobot.get_deep_folder_path( self.new_path, 'mini') if not os.path.exists(self.new_main_path): self.FRobot.creat_folder(self.new_path, 'main') if not os.path.exists(self.new_mini_path): self.FRobot.creat_folder(self.new_path, 'mini') self.database_path = self.FRobot.get_deep_folder_path( home_path, 'database') self.log_path = self.FRobot.get_deep_folder_path(home_path, 'LogFile') self.TLog = TaskLog(input_log_path=self.log_path, input_database_path=self.database_path) def get_pic_num(self, input_path): filelist, dirslist = self.FRobot.get_folder_file_list(input_path) num = 0 for file in filelist: if '.jpg' in file: num += 1 return num def get_name(self, input_path): try: text = self.FRobot.read_message(input_path, 'index_message') return text.split('#')[1], text.split('#')[0] except: print('读取index_message失败') return 'en', 'cn' raise def move_pic(self, input_path): pic_num = self.get_pic_num(input_path) en_name, cn_name = self.get_name(input_path) main_num = math.ceil(pic_num * 0.75) mini_num = pic_num - main_num print(input_path + '有' + str(pic_num) + '副图片,英文名字为' + en_name + '中文名字为' + cn_name + ' main库里有' + str(main_num) + ' mini库里有' + str(mini_num)) pic_folder_name = en_name new_pic_main_path = self.FRobot.creat_folder(self.new_main_path, pic_folder_name) new_pic_mini_path = self.FRobot.creat_folder(self.new_mini_path, pic_folder_name) filelist, dirslist = self.FRobot.get_folder_file_list(input_path) main_count = 0 #计算有多少个被复制进了main direction_Path = new_pic_main_path for file in filelist: if '.jpg' in file: shutil.copyfile(input_path + '\\' + file, direction_Path + '\\' + file) if mini_num == 0: shutil.copyfile(input_path + '\\' + file, new_pic_mini_path + '\\' + file) main_count += 1 if main_count >= main_num: direction_Path = new_pic_mini_path pass pass pass pass def process(self, input_path): #遍历文件夹下所有路径 if self.TLog.is_LV3_with_pic(input_path): #是3级目录,而且有图片,处理 self.move_pic(input_path) pass else: filelist, dirslist = self.FRobot.get_folder_file_list(input_path) if len(dirslist) > 0: for dir in dirslist: dir_path = self.FRobot.get_deep_folder_path( input_path, dir) self.process(dir_path) pass