From 19ed550ee36ec1a21ecb8f4d8cf5a32eaaf58e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 10 Oct 2013 13:41:22 +0200 Subject: [PATCH] add possibility to store file locally --- ocrloader.ini | 4 ++++ ocrloader.py | 36 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/ocrloader.ini b/ocrloader.ini index 4f865c4..c253da4 100644 --- a/ocrloader.ini +++ b/ocrloader.ini @@ -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 diff --git a/ocrloader.py b/ocrloader.py index 2120e94..3c6f7cb 100644 --- a/ocrloader.py +++ b/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: