| Total Complexity | 3 |
| Total Lines | 19 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import os |
||
| 12 | class UploadFileAction(BaseAction): |
||
| 13 | api_type = 'storage' |
||
| 14 | |||
| 15 | def run(self, credentials, file_path, container_name, object_name=None): |
||
| 16 | driver = self._get_driver_for_credentials(credentials=credentials) |
||
| 17 | |||
| 18 | try: |
||
| 19 | container = driver.get_container(container_name=container_name) |
||
| 20 | except ContainerDoesNotExistError: |
||
| 21 | self.logger.debug('Container "%s" doesn\'t exist, creating it...' % |
||
| 22 | (container_name)) |
||
| 23 | container = driver.create_container(container_name=container_name) |
||
| 24 | |||
| 25 | object_name = object_name if object_name else os.path.basename(file_path) |
||
| 26 | obj = driver.upload_object(file_path=file_path, container=container, |
||
| 27 | object_name=object_name) |
||
| 28 | |||
| 29 | self.logger.info('Object successfully uploaded: %s' % (obj)) |
||
| 30 | return obj |
||
| 31 |