Commit 70cb5c71 by yangpengflag

update

parent 06e58ee7
import os
import shutil
import logging
from loggerutils.logger_utils import set_log_config
......@@ -9,8 +10,10 @@ import logging
'''
定义一个函数,接受两个参数,第一个参数是原始图片文件,第二个参数是复制到的路径
'''
def copy_image(source_file,target_path):
if not os.path.exists(target_path):
os.makedirs(target_path)
......
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹10052319018336adb0689bdeac.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹2015081801.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹20202042-1-EX7.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹222063.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹333.txt
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹386315.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹5024b3f1c2aa7.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹ceQCzVIZ1vhs.bmp
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹test11
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹1111.png
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹wechaticon.png
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹毛宝宝封面.jpg
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:29:43 - INFO - 开始读取文件夹珠宝展示网站用视频新版_x264.mp4
2019/01/28 15:29:43 - DEBUG - debug ******
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹10052319018336adb0689bdeac.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹2015081801.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹20202042-1-EX7.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹222063.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹333.txt
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹386315.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹5024b3f1c2aa7.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹ceQCzVIZ1vhs.bmp
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹test11
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹1111.png
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹wechaticon.png
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹毛宝宝封面.jpg
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:30:16 - INFO - 开始读取文件夹珠宝展示网站用视频新版_x264.mp4
2019/01/28 15:30:16 - DEBUG - debug ******
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹10052319018336adb0689bdeac.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹2015081801.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹20202042-1-EX7.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹222063.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹333.txt
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹386315.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹5024b3f1c2aa7.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹ceQCzVIZ1vhs.bmp
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹test11
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹1111.png
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹wechaticon.png
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹毛宝宝封面.jpg
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:34:45 - INFO - 开始读取文件夹珠宝展示网站用视频新版_x264.mp4
2019/01/28 15:34:45 - DEBUG - debug ******
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹10052319018336adb0689bdeac.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹2015081801.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹20202042-1-EX7.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹222063.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹333.txt
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹386315.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹5024b3f1c2aa7.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹ceQCzVIZ1vhs.bmp
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹test11
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹1111.png
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹wechaticon.png
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹毛宝宝封面.jpg
2019/01/28 15:35:07 - DEBUG - debug ******
2019/01/28 15:35:07 - INFO - 开始读取文件夹珠宝展示网站用视频新版_x264.mp4
2019/01/28 15:35:07 - DEBUG - debug ******
import os
import shutil
import logging
from log_config.logger_utils import set_log_config
# 实现图片文件的复制
'''
定义一个函数,接受两个参数,第一个参数是原始图片文件,第二个参数是复制到的路径
'''
def copy_image(source_file,target_path):
if not os.path.exists(target_path):
os.makedirs(target_path)
if os.path.exists(source_file):
# shutil.copy(r'要复制的文件路径(路径+文件)',r'复制到的路径') bits模式
shutil.copy(source_file, target_path)
# shutil.copyfileobj(open(source_file, 'rb'), open(target_path, 'wb'))
print(source_file)
print(target_path)
"""
这里要考虑,给定的参数file_path是文件还是文件夹,如果是文件则直接列出来文件名称就可以
如果是文件夹,那么要列出这个文件夹下所有的文件名称,同时要考虑,文件夹下是否还有文件夹
直到保证此文件夹下再不包含文件夹,列出所有的文件名称即可
# 每当读取一个文件夹时,打一个info级别的log,标记开始读取哪个文件夹
"""
def get_files(file_path):
set_log_config()
if not os.path.exists(file_path):
logging.warning("地址不存在,请检查")
if os.path.isfile(file_path):
print(file_path[0:file_path.find("\\|/")])
return file_path
if os.path.isdir(file_path):
print("%s---该地址是文件夹" %(file_path))
files = os.listdir(file_path)
for i in range(len(files)):
logging.info("开始读取文件夹%s" %files[i])
# print("开始读取文件夹%s" %files[i])
filelist = os.path.join(file_path,files[i])
if len(filelist) > 0:
get_files(os.path.abspath(filelist))
print("文件读取完毕")
'''
从一个目录将全部文件(包含子目录)copy到另外一个目录,只copy文件,不操作文件夹
'''
def copy_dir_2_dir(source_path,target_path):
if not os.path.exists(target_path):
os.makedirs(target_path)
if os.path.exists(source_path):
# root 所指的是当前正在遍历的这个文件夹的本身的地址
# dirs 是一个 list,内容是该文件夹中所有的目录的名字(不包括子目录)
# files 同样是 list, 内容是该文件夹中所有的文件(不包括子目录,只copy子目录中的文件,目录结构不copy)
for root, dirs, files in os.walk(source_path):
print("root:%s" % root)
print("dirs:%s" % dirs)
print("files:%s" % files)
for file in files:
src_file = os.path.join(root, file)
shutil.copy(src_file, target_path)
print(src_file)
print('copy files finished!')
# copy图片
# copy_image("D:/wechaticon.png","D:/test1/")
#
# # copy视频
# copy_image("D:/珠宝展示网站用视频新版_x264.mp4","D:/test1/")
# get_files("D:\\wechaticon.png")
get_files("D:\\test1")
# copy_dir_2_dir("D:\\壁纸","D:\\test1")
\ No newline at end of file
# 指定日志输出目标文件的文件名,指定该设置项后日志信心就不会被输出到控制台了
filename = aitest.log
# 指定日志器的日志级别
level = DEBUG
# 指定日志格式字符串,即指定日志输出时所包含的字段信息以及它们的顺序
format = %(asctime)s - %(levelname)s - %(message)s
# 指定日期/时间格式。需要注意的是,该选项要在format中包含时间字段%(asctime)s时才有效
datefmt = %Y/%m/%d %H:%M:%S
\ No newline at end of file
from log_config.properties_utils import Properties
import logging
def set_log_config():
log_config = Properties('log.properties').get_properties()
logging.basicConfig(**log_config)
logging.debug("debug ******")
def set_log_config_diy():
pro = Properties('log.properties').get_properties()
log_config = {
"filename": pro["filename"],
"level": pro["level"]
}
logging.basicConfig(**log_config)
logging.debug("debug ******")
\ No newline at end of file
class Properties():
def __init__(self, file_name):
self.properties_file_name = file_name
self.properties={}
def get_properties(self) -> dict:
with open(self.properties_file_name, 'r', encoding="UTF-8") as pro_file:
for line in pro_file.readlines():
# 去掉两端的空格和\n符号
line = line.strip().replace("\n", "")
# 如果发现 # 符号,代表这一行或后边是注释内容
if line.find("#") != -1:
line = line[0:line.find("#")]
# 如果包含了等号,我们就要进行字典类型的转换处理
if line.find("=") > 0: # 这是我的注释
# 我们就用等号进行切分,形成新的字符串类型的list
strs = line.split("=")
# 获取字典
self.__get_dict(strs[0].strip(),self.properties,strs[1].strip())
return self.properties
def __get_dict(self, key_name, result_dict, value):
# 检查key中是否包含. ,包含的话我们切分,不包含的话就直接设置值就可以了
if (key_name.find(".") > 0): # 这里用.进行了包含判断 www.greedyai.com
k = key_name.split(".")[0] #用.进行切分,我拿第一个 www 作为一个key
result_dict.setdefault(k, {}) # 把结果字典设置成 {www:{greedyai : {com: value}}
return self.__get_dict(key_name[len(k) + 1:],result_dict[k],value)
else:
result_dict[key_name] = value
import loggerutils
__all__ = ['logger_utils','logger_properties']
class Properties():
def __init__(self,filename):
self.properties_file_name = filename
......
from loggerutils.logger_properties import Properties
import loggerutils
import logging
def set_log_config():
log_config = Properties('log.properties').get_properties()
logging.basicConfig(**log_config)
logging.debug("debug ******")
\ No newline at end of file
logging.debug("debug ******")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment