126 local_dir = os.path.join(self.output_dir, measurement_id, subdir) |
131 local_dir = os.path.join(self.output_dir, measurement_id, subdir) |
127 if not os.path.exists(local_dir): |
132 if not os.path.exists(local_dir): |
128 os.makedirs(local_dir) |
133 os.makedirs(local_dir) |
129 |
134 |
130 # Save the file by chunk, needed if the file is big. |
135 # Save the file by chunk, needed if the file is big. |
131 memory_file = StringIO.StringIO() |
136 memory_file = StringIO() |
132 |
137 |
133 for chunk in request.iter_content(chunk_size=1024): |
138 for chunk in request.iter_content(chunk_size=1024): |
134 if chunk: # filter out keep-alive new chunks |
139 if chunk: # filter out keep-alive new chunks |
135 memory_file.write(chunk) |
140 memory_file.write(chunk) |
136 memory_file.flush() |
141 memory_file.flush() |
364 raise ValueError('No available measurement id found.') |
369 raise ValueError('No available measurement id found.') |
365 |
370 |
366 return measurement_id |
371 return measurement_id |
367 |
372 |
368 |
373 |
369 class ApiObject: |
374 class ApiObject(object): |
370 """ A generic class object. """ |
375 """ A generic class object. """ |
371 |
376 |
372 def __init__(self, base_url, dict_response): |
377 def __init__(self, base_url, dict_response): |
373 self.base_url = base_url |
378 self.base_url = base_url |
374 |
379 |
375 if dict_response: |
380 if dict_response: |
376 # Add the dictionary key value pairs as object properties |
381 # Add the dictionary key value pairs as object properties |
377 for key, value in dict_response.items(): |
382 for key, value in dict_response.items(): |
378 setattr(self, key, value) |
383 # logger.debug('Setting key {0} to value {1}'.format(key, value)) |
|
384 try: |
|
385 setattr(self, key, value) |
|
386 except: |
|
387 logger.warning('Could not set attribute {0} to value {1}'.format(key, value)) |
379 self.exists = True |
388 self.exists = True |
380 else: |
389 else: |
381 self.exists = False |
390 self.exists = False |
382 |
391 |
383 |
392 |