23d6a73c by 周伟奇

fix folder bug

1 parent 23c4a341
...@@ -310,20 +310,26 @@ class Command(BaseCommand, LoggerMixin): ...@@ -310,20 +310,26 @@ class Command(BaseCommand, LoggerMixin):
310 os.makedirs(pdf_output_dir, exist_ok=True) 310 os.makedirs(pdf_output_dir, exist_ok=True)
311 os.makedirs(tiff_output_dir, exist_ok=True) 311 os.makedirs(tiff_output_dir, exist_ok=True)
312 os.makedirs(failed_output_dir, exist_ok=True) 312 os.makedirs(failed_output_dir, exist_ok=True)
313 os_error_filename_set = set()
313 while self.switch: 314 while self.switch:
314 if not os.path.isdir(input_dir): 315 # if not os.path.isdir(input_dir):
315 self.folder_log.info('{0} [input dir is not dir] [input_dir={1}]'.format(self.log_base, input_dir)) 316 # self.folder_log.info('{0} [input dir is not dir] [input_dir={1}]'.format(self.log_base, input_dir))
316 time.sleep(self.sleep_time) 317 # time.sleep(self.sleep_time)
317 continue 318 # continue
318 # 1. 从input dir获取pdf or image 319 # 1. 从input dir获取pdf or image
319 list_dir = os.listdir(input_dir) 320 list_dir = os.listdir(input_dir)
320 if not list_dir: 321 if not list_dir and len(os_error_filename_set) == 0:
321 self.folder_log.info('{0} [input dir empty] [input_dir={1}]'.format(self.log_base, input_dir)) 322 self.folder_log.info('{0} [input dir empty] [input_dir={1}]'.format(self.log_base, input_dir))
322 time.sleep(self.sleep_time) 323 time.sleep(self.sleep_time)
323 continue 324 continue
324 for name in list_dir: 325 all_file_set = set(list_dir)
326 true_file_set = all_file_set - os_error_filename_set
327 if len(true_file_set) == 0 and len(os_error_filename_set) > 0:
328 true_file_set.add(os_error_filename_set.pop())
329 for name in true_file_set:
330 path = os.path.join(input_dir, name)
331
325 try: 332 try:
326 path = os.path.join(input_dir, name)
327 if os.path.isfile(path): 333 if os.path.isfile(path):
328 self.folder_log.info('{0} [file start] [path={1}]'.format(self.log_base, path)) 334 self.folder_log.info('{0} [file start] [path={1}]'.format(self.log_base, path))
329 if name.endswith('.pdf'): 335 if name.endswith('.pdf'):
...@@ -337,18 +343,23 @@ class Command(BaseCommand, LoggerMixin): ...@@ -337,18 +343,23 @@ class Command(BaseCommand, LoggerMixin):
337 self.folder_log.info('{0} [path is dir] [path={1}]'.format(self.log_base, input_dir)) 343 self.folder_log.info('{0} [path is dir] [path={1}]'.format(self.log_base, input_dir))
338 failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name)) 344 failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name))
339 shutil.move(path, failed_path) 345 shutil.move(path, failed_path)
346 except OSError:
347 os_error_filename_set.add(name)
348 self.folder_log.error('{0} [os error] [path={1}] [error={2}]'.format(
349 self.log_base, path, traceback.format_exc()))
340 except Exception as e: 350 except Exception as e:
341 try: 351 try:
342 path = os.path.join(input_dir, name)
343 self.folder_log.error('{0} [file error] [path={1}] [error={2}]'.format(self.log_base, path, 352 self.folder_log.error('{0} [file error] [path={1}] [error={2}]'.format(self.log_base, path,
344 traceback.format_exc())) 353 traceback.format_exc()))
345 failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name)) 354 failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name))
346 shutil.move(path, failed_path) 355 shutil.move(path, failed_path)
347 continue 356 except PermissionError:
357 os_error_filename_set.add(name)
358 self.folder_log.error('{0} [permission error] [path={1}] [error={2}]'.format(
359 self.log_base, path, traceback.format_exc()))
348 except Exception as e: 360 except Exception as e:
349 self.folder_log.error('{0} [file error] [error={1}]'.format( 361 self.folder_log.error('{0} [file error] [error={1}]'.format(
350 self.log_base, traceback.format_exc())) 362 self.log_base, traceback.format_exc()))
351 continue
352 363
353 def handle(self, *args, **kwargs): 364 def handle(self, *args, **kwargs):
354 process_list = [] 365 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!