|
1
|
|
|
"""Command object |
|
2
|
|
|
|
|
3
|
|
|
.. Authors: |
|
4
|
|
|
Philippe Dessauw |
|
5
|
|
|
[email protected] |
|
6
|
|
|
|
|
7
|
|
|
.. Sponsor: |
|
8
|
|
|
Alden Dima |
|
9
|
|
|
[email protected] |
|
10
|
|
|
Information Systems Group |
|
11
|
|
|
Software and Systems Division |
|
12
|
|
|
Information Technology Laboratory |
|
13
|
|
|
National Institute of Standards and Technology |
|
14
|
|
|
http://www.nist.gov/itl/ssd/is |
|
15
|
|
|
""" |
|
16
|
|
|
from apputils.fileop import zip_directory, unzip_directory |
|
17
|
|
|
from pipeline.files import FileManager |
|
18
|
|
|
|
|
19
|
|
|
|
|
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.unzipped = filename |
|
35
|
|
|
self.config = app_config |
|
36
|
|
|
|
|
37
|
|
|
self.logger.debug("File to be processed: %s" % str(self.unzipped)) |
|
38
|
|
|
|
|
39
|
|
|
# def get_file(self): |
|
40
|
|
|
# """Retrieve file from redis and unzip it to the local filesystem |
|
41
|
|
|
# """ |
|
42
|
|
|
# # Get hash from redis |
|
43
|
|
|
# self.logger.debug("Retrieving "+self.filename+"...") |
|
44
|
|
|
# self.fman.retrieve_file(self.filename) |
|
45
|
|
|
# |
|
46
|
|
|
# # Write it in the tmp folder |
|
47
|
|
|
# self._unzip_file() |
|
48
|
|
|
|
|
49
|
|
|
# def store_file(self): |
|
50
|
|
|
# """Zip file on the local filesystem and store it to redis |
|
51
|
|
|
# """ |
|
52
|
|
|
# self._zip_file() |
|
53
|
|
|
# |
|
54
|
|
|
# # Store it in redis |
|
55
|
|
|
# self.fman.store_file(self.filename) |
|
56
|
|
|
|
|
57
|
|
|
# def _zip_file(self): |
|
58
|
|
|
# """Check if the file can be zipped and zip it |
|
59
|
|
|
# """ |
|
60
|
|
|
# if self.unzipped is None: |
|
61
|
|
|
# self.logger.error("Zipped directory has not been unzipped") |
|
62
|
|
|
# return |
|
63
|
|
|
# |
|
64
|
|
|
# zip_directory(self.unzipped) |
|
65
|
|
|
# self.unzipped = None |
|
66
|
|
|
|
|
67
|
|
|
# def _unzip_file(self): |
|
68
|
|
|
# """Check if the file can be unzipped and unzip it |
|
69
|
|
|
# """ |
|
70
|
|
|
# if self.unzipped is not None: |
|
71
|
|
|
# self.logger.error("Archive already unzipped") |
|
72
|
|
|
# return |
|
73
|
|
|
# |
|
74
|
|
|
# self.unzipped = unzip_directory(self.filename) |
|
75
|
|
|
|