Completed
Push — master ( d9d5a0...c9ec26 )
by Philippe
28s
created

FileManager.store_file()   A

Complexity

Conditions 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
1
"""Package defining Redis file manager
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
import base64
17
from os import remove
18
import redis
19
20
21
class FileManager(object):
22
    """Redis file manager
23
    """
24
25
    # def __init__(self, host="127.0.0.1", port=6379, db=0):
26
    #     self.server = redis.StrictRedis(host, port, db)
27
    #     self.hashmap_name = "fman"
28
    def __init__(self, app_config):
29
        self.hashmap = {}  # Stores fileid -> filepath
30
        self.config = app_config
31
32
    # def retrieve_file(self, filename):
33
    #     """Retrieve from redis hashmap
34
    #
35
    #     Args
36
    #         filename (str): Filename to retrieve
37
    #     """
38
    #     b64_hash = self.server.hget(self.hashmap_name, filename)
39
    #     data = base64.b64decode(b64_hash)
40
    #
41
    #     with open(filename, 'wb') as zip_file:
42
    #         zip_file.write(data)
43
    #
44
    # def store_file(self, filename):
45
    #     """Store file to redis hashmap
46
    #
47
    #     Args
48
    #         filename (str): Filename to store
49
    #     """
50
    #     with open(filename, 'rb') as zip_file:
51
    #         b64_hash = base64.b64encode(zip_file.read())
52
    #
53
    #     self.server.hset(self.hashmap_name, filename, b64_hash)
54
    #     remove(filename)
55
56
    def delete_file(self, filename):
57
        """Delete file from redis hashmap
58
59
        Args
60
            filename (str): Filename to delete
61
        """
62
        # self.server.hdel(self.hashmap_name, filename)
63
        if filename not in self.hashmap:
64
            raise KeyError("FileManager: filename is not present in hashmap")
65
66
        del self.hashmap[filename]
67