20afb1b5 by 周伟奇

Merge branch 'fix/folder' into feature/0611

2 parents c9e6a6f5 23d6a73c
......@@ -290,20 +290,26 @@ class Command(BaseCommand, LoggerMixin):
os.makedirs(pdf_output_dir, exist_ok=True)
os.makedirs(tiff_output_dir, exist_ok=True)
os.makedirs(failed_output_dir, exist_ok=True)
os_error_filename_set = set()
while self.switch:
if not os.path.isdir(input_dir):
self.folder_log.info('{0} [input dir is not dir] [input_dir={1}]'.format(self.log_base, input_dir))
time.sleep(self.sleep_time)
continue
# if not os.path.isdir(input_dir):
# self.folder_log.info('{0} [input dir is not dir] [input_dir={1}]'.format(self.log_base, input_dir))
# time.sleep(self.sleep_time)
# continue
# 1. 从input dir获取pdf or image
list_dir = os.listdir(input_dir)
if not list_dir:
if not list_dir and len(os_error_filename_set) == 0:
self.folder_log.info('{0} [input dir empty] [input_dir={1}]'.format(self.log_base, input_dir))
time.sleep(self.sleep_time)
continue
for name in list_dir:
all_file_set = set(list_dir)
true_file_set = all_file_set - os_error_filename_set
if len(true_file_set) == 0 and len(os_error_filename_set) > 0:
true_file_set.add(os_error_filename_set.pop())
for name in true_file_set:
path = os.path.join(input_dir, name)
try:
path = os.path.join(input_dir, name)
if os.path.isfile(path):
self.folder_log.info('{0} [file start] [path={1}]'.format(self.log_base, path))
if name.endswith('.pdf'):
......@@ -317,18 +323,23 @@ class Command(BaseCommand, LoggerMixin):
self.folder_log.info('{0} [path is dir] [path={1}]'.format(self.log_base, input_dir))
failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name))
shutil.move(path, failed_path)
except OSError:
os_error_filename_set.add(name)
self.folder_log.error('{0} [os error] [path={1}] [error={2}]'.format(
self.log_base, path, traceback.format_exc()))
except Exception as e:
try:
path = os.path.join(input_dir, name)
self.folder_log.error('{0} [file error] [path={1}] [error={2}]'.format(self.log_base, path,
traceback.format_exc()))
failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name))
shutil.move(path, failed_path)
continue
except PermissionError:
os_error_filename_set.add(name)
self.folder_log.error('{0} [permission error] [path={1}] [error={2}]'.format(
self.log_base, path, traceback.format_exc()))
except Exception as e:
self.folder_log.error('{0} [file error] [error={1}]'.format(
self.log_base, traceback.format_exc()))
continue
def handle(self, *args, **kwargs):
process_list = []
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!