Skip to content

Commit 34067b7

Browse files
Merge pull request #1 from timurgen/feature/guid
Different improvements
2 parents 491d0c6 + 59ab0bc commit 34067b7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

service/proarc.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import os
66
import logging
7+
import uuid
78
from flask import Flask, request, Response
89
import urllib3
910
import requests
@@ -126,7 +127,9 @@ def fromproarc(path):
126127
file_id = request.args.get('file_id')
127128
filename = request.args.get('filename')
128129

129-
entity = {
130+
LOG.info(f'serving request for file_rno {file_id} and name {filename}')
131+
132+
soap_entity = {
130133
"_soapheaders": {},
131134
"files": {
132135
"ListItems": {
@@ -140,19 +143,25 @@ def fromproarc(path):
140143
"id": os.environ.get('proarc_user')
141144
}
142145

143-
# Continuing on the soap call
144146
if os.environ.get('transit_decode', 'false').lower() == "true":
145-
LOG.info("transit_decode is set to True.")
146-
entity = typetransformer.transit_decode(entity)
147+
LOG.debug("transit_decode is set to True.")
148+
soap_entity = typetransformer.transit_decode(soap_entity)
147149

148-
LOG.info(f"Finished creating request: {str(entity)}")
150+
LOG.debug(f"Finished creating request: {str(soap_entity)}")
151+
152+
with SOAP_CLIENT.settings(raw_response=True):
153+
proarc_response = do_soap(soap_entity, SOAP_CLIENT, path)
154+
155+
proarc_response.raise_for_status()
156+
157+
LOG.debug(f"SOAPResponse : \n{str(proarc_response)}\n----End-Response----")
149158

150-
response = do_soap(entity, SOAP_CLIENT, path)
151-
LOG.info(f"SOAPResponse : \n{str(response)}\n----End-Response----")
152159
try:
153160
if FILE_DOWNLOADER_URL:
161+
LOG.debug(f"trying to download file {filename} from {FILE_DOWNLOADER_URL}")
154162
local_file_name = read_file_from_url(filename)
155163
file_stream = read_local_file(local_file_name)
164+
os.remove(local_file_name)
156165
else:
157166
file_stream = read_file(filename)
158167
except IOError as exc:
@@ -225,8 +234,11 @@ def read_local_file(filename):
225234

226235
def read_file_from_url(file_name):
227236
# NOTE the stream=True parameter below
228-
with requests.get(f'{FILE_DOWNLOADER_URL}/get/{PROARC_SHARE_NAME}/{PROARC_SHARE_PATH}', stream=True) as r:
237+
file_url = f'{FILE_DOWNLOADER_URL}/get/{PROARC_SHARE_NAME}/{PROARC_SHARE_PATH}/{file_name}'
238+
with requests.get(file_url, stream=True) as r:
229239
r.raise_for_status()
240+
# if we have to requests fetching the same file we need to be able to not mix them
241+
file_name += f"__{str(uuid.uuid4())}"
230242
with open(file_name, 'wb') as f:
231243
for chunk in r.iter_content(chunk_size=8192):
232244
if chunk: # filter out keep-alive new chunks

0 commit comments

Comments
 (0)