lpf
lpf
管理员
管理员
  • UID1
  • 最后登录2025-09-09
  • 关注4
  • 发帖数27
  • 铜币150枚
  • 社区居民
  • 忠实会员
阅读:502回复:0

hahaha

楼主#
更多 发布于:2025-09-08 23:28
import os
import sys
import argparse
import csv
from datetime import datetime

sys.dont_write_bytecode = True

#---------------------------------
def GetArgs():
parser = argparse.ArgumentParser()
parser.add_argument("--input",help="the input",default="./")
parser.add_argument("--output_dir",help="the output dir",default="./output_lsfr")
parser.add_argument("-c","--clear",action='store_true',help="clear the output dir")
return parser.parse_args()

def GetNameExt(arg_file,ext_chk=0,arg_ext=".csv"):
file = os.path.basename(arg_file)
#file_name,file_ext = os.path.splitext(file)
if not os.path.exists(arg_file):
print(f"ERROR: the input file {arg_file} doesn't exist!!!")
sys.exit(1)
elif os.path.isfile(arg_file):
if ext_chk and file_ext != "."+arg_ext:
print(f"ERROR: the input file {arg_file} doesn't .{arg_ext} type!!!")
sys.exit(1)
else:
file_name,file_ext = os.path.splitext(file)
return [file_name,file_ext]
else:
print(f"ERROR: the input {arg_file} doesn't correct!!!")
sys.exit(1)

def GetFileOrDirOfInput(args_input):
if not os.path.exists(args_input):
print(f"ERROR: the input {args_input} doesn't exist!!!")
sys.exit(1)
elif os.path.isfile(args_input):
abs_path_file = os.path.abspath(args_input)
abs_path_dir = os.path.dirname(abs_path_file)
file_name,file_ext = GetNameExt(abs_path_file)
file_flag = 1
return [file_flag,abs_path_dir,file_name,file_ext]
elif os.path.isdir(args_input):
abs_path_dir = os.path.abspath(args_input)
print(f"isdir abs_dir={abs_path_dir}")
file_flag=0
file_name=0
file_ext=0
return [file_flag,abs_path_dir,file_name,file_ext]
else:
print(f"ERROR: the input {args_input} doesn't correct!!!")
sys.exit(1)

def GetDirOfOutput(args_output,args_clear=False):
if not os.path.exists(args_output):
os.system(f"mkdir {args_output}")
elif not os.path.isdir(args_output):
print(f"ERROR: the input {args_output} exist and not directory !!!")
sys.exit(1)
elif not any(os.scandir(args_output)): # empty
#print(f"INFO: the input {args_output} .") #debug
pass
else:
if args_clear :
os.system(f"rm -rf {args_output}/*")



#---------------------------------------

def main():
args = GetArgs()
print(f"args.input = {args.input}")
print(f"args.output_dir = {args.output_dir}")
[file_flag,abs_path_dir,file_name,file_ext] = GetFileOrDirOfInput(args.input)
#GetDirOfOutput(args.output_dir)
GetDirOfOutput(args.output_dir,args.clear)





if __name__ == "__main__":
main()
sys.exit(0)
游客

返回顶部