| Total Complexity | 7 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | """Command object |
||
| 20 | class Command(object): |
||
| 21 | """Main command object |
||
| 22 | """ |
||
| 23 | |||
| 24 | def __init__(self, filename, logger, app_config): |
||
| 25 | self.logger = logger |
||
| 26 | |||
| 27 | ip = app_config["machines"]["master"][0].split('@') |
||
| 28 | master_ip = ip[-1:][0] |
||
| 29 | master_queue_port = app_config["redis"]["port"] |
||
| 30 | self.fman = FileManager(master_ip, master_queue_port) |
||
| 31 | |||
| 32 | self.filename = filename |
||
| 33 | self.unzipped = None |
||
| 34 | self.config = app_config |
||
| 35 | |||
| 36 | def get_file(self): |
||
| 37 | """Retrieve file from redis and unzip it to the local filesystem |
||
| 38 | """ |
||
| 39 | # Get hash from redis |
||
| 40 | self.logger.debug("Retrieving "+self.filename+"...") |
||
| 41 | self.fman.retrieve_file(self.filename) |
||
| 42 | |||
| 43 | # Write it in the tmp folder |
||
| 44 | self._unzip_file() |
||
| 45 | |||
| 46 | def store_file(self): |
||
| 47 | """Zip file on the local filesystem and store it to redis |
||
| 48 | """ |
||
| 49 | self._zip_file() |
||
| 50 | |||
| 51 | # Store it in redis |
||
| 52 | self.fman.store_file(self.filename) |
||
| 53 | |||
| 54 | def _zip_file(self): |
||
| 55 | """Check if the file can be zipped and zip it |
||
| 56 | """ |
||
| 57 | if self.unzipped is None: |
||
| 58 | self.logger.error("Zipped directory has not been unzipped") |
||
| 59 | return |
||
| 60 | |||
| 61 | zip_directory(self.unzipped) |
||
| 62 | self.unzipped = None |
||
| 63 | |||
| 64 | def _unzip_file(self): |
||
| 65 | """Check if the file can be unzipped and unzip it |
||
| 66 | """ |
||
| 67 | if self.unzipped is not None: |
||
| 68 | self.logger.error("Archive already unzipped") |
||
| 69 | return |
||
| 70 | |||
| 71 | self.unzipped = unzip_directory(self.filename) |
||
| 72 |