Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
20afb1b5
authored
2021-07-07 14:55:31 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'fix/folder' into feature/0611
2 parents
c9e6a6f5
23d6a73c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
src/apps/doc/management/commands/folder_ocr_process.py
src/apps/doc/management/commands/folder_ocr_process.py
View file @
20afb1b
...
...
@@ -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
=
[]
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment