Merge branch 'fix/folder' into feature/0611
Showing
1 changed file
with
21 additions
and
10 deletions
| ... | @@ -290,20 +290,26 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -290,20 +290,26 @@ class Command(BaseCommand, LoggerMixin): |
| 290 | os.makedirs(pdf_output_dir, exist_ok=True) | 290 | os.makedirs(pdf_output_dir, exist_ok=True) |
| 291 | os.makedirs(tiff_output_dir, exist_ok=True) | 291 | os.makedirs(tiff_output_dir, exist_ok=True) |
| 292 | os.makedirs(failed_output_dir, exist_ok=True) | 292 | os.makedirs(failed_output_dir, exist_ok=True) |
| 293 | os_error_filename_set = set() | ||
| 293 | while self.switch: | 294 | while self.switch: |
| 294 | if not os.path.isdir(input_dir): | 295 | # if not os.path.isdir(input_dir): |
| 295 | self.folder_log.info('{0} [input dir is not dir] [input_dir={1}]'.format(self.log_base, input_dir)) | 296 | # self.folder_log.info('{0} [input dir is not dir] [input_dir={1}]'.format(self.log_base, input_dir)) |
| 296 | time.sleep(self.sleep_time) | 297 | # time.sleep(self.sleep_time) |
| 297 | continue | 298 | # continue |
| 298 | # 1. 从input dir获取pdf or image | 299 | # 1. 从input dir获取pdf or image |
| 299 | list_dir = os.listdir(input_dir) | 300 | list_dir = os.listdir(input_dir) |
| 300 | if not list_dir: | 301 | if not list_dir and len(os_error_filename_set) == 0: |
| 301 | self.folder_log.info('{0} [input dir empty] [input_dir={1}]'.format(self.log_base, input_dir)) | 302 | self.folder_log.info('{0} [input dir empty] [input_dir={1}]'.format(self.log_base, input_dir)) |
| 302 | time.sleep(self.sleep_time) | 303 | time.sleep(self.sleep_time) |
| 303 | continue | 304 | continue |
| 304 | for name in list_dir: | 305 | all_file_set = set(list_dir) |
| 306 | true_file_set = all_file_set - os_error_filename_set | ||
| 307 | if len(true_file_set) == 0 and len(os_error_filename_set) > 0: | ||
| 308 | true_file_set.add(os_error_filename_set.pop()) | ||
| 309 | for name in true_file_set: | ||
| 310 | path = os.path.join(input_dir, name) | ||
| 311 | |||
| 305 | try: | 312 | try: |
| 306 | path = os.path.join(input_dir, name) | ||
| 307 | if os.path.isfile(path): | 313 | if os.path.isfile(path): |
| 308 | self.folder_log.info('{0} [file start] [path={1}]'.format(self.log_base, path)) | 314 | self.folder_log.info('{0} [file start] [path={1}]'.format(self.log_base, path)) |
| 309 | if name.endswith('.pdf'): | 315 | if name.endswith('.pdf'): |
| ... | @@ -317,18 +323,23 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -317,18 +323,23 @@ class Command(BaseCommand, LoggerMixin): |
| 317 | self.folder_log.info('{0} [path is dir] [path={1}]'.format(self.log_base, input_dir)) | 323 | self.folder_log.info('{0} [path is dir] [path={1}]'.format(self.log_base, input_dir)) |
| 318 | failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name)) | 324 | failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name)) |
| 319 | shutil.move(path, failed_path) | 325 | shutil.move(path, failed_path) |
| 326 | except OSError: | ||
| 327 | os_error_filename_set.add(name) | ||
| 328 | self.folder_log.error('{0} [os error] [path={1}] [error={2}]'.format( | ||
| 329 | self.log_base, path, traceback.format_exc())) | ||
| 320 | except Exception as e: | 330 | except Exception as e: |
| 321 | try: | 331 | try: |
| 322 | path = os.path.join(input_dir, name) | ||
| 323 | self.folder_log.error('{0} [file error] [path={1}] [error={2}]'.format(self.log_base, path, | 332 | self.folder_log.error('{0} [file error] [path={1}] [error={2}]'.format(self.log_base, path, |
| 324 | traceback.format_exc())) | 333 | traceback.format_exc())) |
| 325 | failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name)) | 334 | failed_path = os.path.join(failed_output_dir, '{0}_{1}'.format(time.time(), name)) |
| 326 | shutil.move(path, failed_path) | 335 | shutil.move(path, failed_path) |
| 327 | continue | 336 | except PermissionError: |
| 337 | os_error_filename_set.add(name) | ||
| 338 | self.folder_log.error('{0} [permission error] [path={1}] [error={2}]'.format( | ||
| 339 | self.log_base, path, traceback.format_exc())) | ||
| 328 | except Exception as e: | 340 | except Exception as e: |
| 329 | self.folder_log.error('{0} [file error] [error={1}]'.format( | 341 | self.folder_log.error('{0} [file error] [error={1}]'.format( |
| 330 | self.log_base, traceback.format_exc())) | 342 | self.log_base, traceback.format_exc())) |
| 331 | continue | ||
| 332 | 343 | ||
| 333 | def handle(self, *args, **kwargs): | 344 | def handle(self, *args, **kwargs): |
| 334 | process_list = [] | 345 | process_list = [] | ... | ... |
-
Please register or sign in to post a comment