add possibility to store file locally

This commit is contained in:
Frédéric Péters 2013-10-10 13:41:22 +02:00
parent 112e100502
commit 19ed550ee3
2 changed files with 25 additions and 15 deletions

View File

@ -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

View File

@ -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: