add possibility to store file locally
This commit is contained in:
parent
112e100502
commit
19ed550ee3
|
@ -17,3 +17,7 @@ password = xxxxxx
|
|||
default_type = dmsdocument
|
||||
default_directory = Members/gaetan
|
||||
user = gaetan
|
||||
|
||||
[xxxx-test2-gaetandeberdt@pfwb.be]
|
||||
password = xxxxxx
|
||||
store_path = /srv/ocr/DeberdtG
|
||||
|
|
36
ocrloader.py
36
ocrloader.py
|
@ -10,6 +10,7 @@ import requests
|
|||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import shutil
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -42,21 +43,26 @@ def process(cfg, filename, payload, enable_ocr=True):
|
|||
file('/tmp/' + filename, 'w').write(payload) # keep it for inspection
|
||||
return False
|
||||
|
||||
print ' uploading file'
|
||||
t = os.system('curl -v --insecure -X POST '\
|
||||
'--form "form.widgets.file=@%s;filename=%s;type=application/pdf" '\
|
||||
'-F "form.buttons.import=Import" '\
|
||||
'-F "form.widgets.portal_type=%s" '\
|
||||
'-F "form.widgets.location=%s" '\
|
||||
'-F "form.widgets.owner=%s" '\
|
||||
'-u admin:admin '\
|
||||
'%s/@@fileimport' % (
|
||||
ocr_filename, filename,
|
||||
cfg.get('default_type'),
|
||||
cfg.get('default_directory'),
|
||||
cfg.get('user'),
|
||||
cfg.get('ged_base_url')))
|
||||
return (t == 0)
|
||||
if cfg.get('store_path'):
|
||||
print ' storing file locally'
|
||||
shutil.copy(ocr_filename, os.path.join(cfg.get('store_path'), filename))
|
||||
return True
|
||||
else:
|
||||
print ' uploading file'
|
||||
t = os.system('curl -v --insecure -X POST '\
|
||||
'--form "form.widgets.file=@%s;filename=%s;type=application/pdf" '\
|
||||
'-F "form.buttons.import=Import" '\
|
||||
'-F "form.widgets.portal_type=%s" '\
|
||||
'-F "form.widgets.location=%s" '\
|
||||
'-F "form.widgets.owner=%s" '\
|
||||
'-u admin:admin '\
|
||||
'%s/@@fileimport' % (
|
||||
ocr_filename, filename,
|
||||
cfg.get('default_type'),
|
||||
cfg.get('default_directory'),
|
||||
cfg.get('user'),
|
||||
cfg.get('ged_base_url')))
|
||||
return (t == 0)
|
||||
|
||||
|
||||
# try:
|
||||
|
|
Reference in New Issue