summaryrefslogtreecommitdiffstats
path: root/ocrloader.py
diff options
context:
space:
mode:
Diffstat (limited to 'ocrloader.py')
-rw-r--r--ocrloader.py36
1 files changed, 21 insertions, 15 deletions
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: