util.py 967 字节
Newer Older
HypoX64's avatar
preview  
HypoX64 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import os

def Traversal(filedir):
    file_list=[]
    for root,dirs,files in os.walk(filedir): 
        for file in files:
            file_list.append(os.path.join(root,file)) 
        for dir in dirs:
            Traversal(dir)
    return file_list

def is_img(path):
    ext = os.path.splitext(path)[1]
    ext = ext.lower()
    if ext in ['.jpg','.png','.jpeg','.bmp']:
        return True
    else:
        return False

def is_video(path):
    ext = os.path.splitext(path)[1]
    ext = ext.lower()
    if ext in ['.mp4','.flv','.avi','.mov','.mkv','.wmv','.rmvb']:
        return True
    else:
        return False

def  writelog(path,log):
    f = open(path,'a+')
    f.write(log+'\n')

def clean_tempfiles():
    if os.path.isdir('./tmp'):   
        os.system('rm -rf ./tmp')
    os.makedirs('./tmp')
    os.makedirs('./tmp/video2image')
    os.makedirs('./tmp/addmosaic_image')
    os.makedirs('./tmp/mosaic_crop')
    os.makedirs('./tmp/replace_mosaic')