root / snf-pithos-backend / pithos / backends / lib / hashfiler / mapper.py @ c30635bf
History | View | Annotate | Download (2.7 kB)
1 | 2e662088 | Antony Chazapis | # Copyright 2011-2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | a9b3f29d | Antony Chazapis | #
|
3 | a9b3f29d | Antony Chazapis | # Redistribution and use in source and binary forms, with or
|
4 | a9b3f29d | Antony Chazapis | # without modification, are permitted provided that the following
|
5 | a9b3f29d | Antony Chazapis | # conditions are met:
|
6 | a9b3f29d | Antony Chazapis | #
|
7 | a9b3f29d | Antony Chazapis | # 1. Redistributions of source code must retain the above
|
8 | a9b3f29d | Antony Chazapis | # copyright notice, this list of conditions and the following
|
9 | a9b3f29d | Antony Chazapis | # disclaimer.
|
10 | a9b3f29d | Antony Chazapis | #
|
11 | a9b3f29d | Antony Chazapis | # 2. Redistributions in binary form must reproduce the above
|
12 | a9b3f29d | Antony Chazapis | # copyright notice, this list of conditions and the following
|
13 | a9b3f29d | Antony Chazapis | # disclaimer in the documentation and/or other materials
|
14 | a9b3f29d | Antony Chazapis | # provided with the distribution.
|
15 | a9b3f29d | Antony Chazapis | #
|
16 | a9b3f29d | Antony Chazapis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | a9b3f29d | Antony Chazapis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | a9b3f29d | Antony Chazapis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | a9b3f29d | Antony Chazapis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | a9b3f29d | Antony Chazapis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | a9b3f29d | Antony Chazapis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | a9b3f29d | Antony Chazapis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | a9b3f29d | Antony Chazapis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | a9b3f29d | Antony Chazapis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | a9b3f29d | Antony Chazapis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | a9b3f29d | Antony Chazapis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | a9b3f29d | Antony Chazapis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | a9b3f29d | Antony Chazapis | #
|
29 | a9b3f29d | Antony Chazapis | # The views and conclusions contained in the software and
|
30 | a9b3f29d | Antony Chazapis | # documentation are those of the authors and should not be
|
31 | a9b3f29d | Antony Chazapis | # interpreted as representing official policies, either expressed
|
32 | a9b3f29d | Antony Chazapis | # or implied, of GRNET S.A.
|
33 | a9b3f29d | Antony Chazapis | |
34 | 1c2fc0ff | Antony Chazapis | from binascii import hexlify |
35 | a9b3f29d | Antony Chazapis | |
36 | c30635bf | Filippos Giannakos | from radosmapper import RadosMapper |
37 | c30635bf | Filippos Giannakos | from filemapper import FileMapper |
38 | a9b3f29d | Antony Chazapis | |
39 | a9b3f29d | Antony Chazapis | class Mapper(object): |
40 | a9b3f29d | Antony Chazapis | """Mapper.
|
41 | c30635bf | Filippos Giannakos | Required constructor parameters: mappath, namelen, mappool.
|
42 | a9b3f29d | Antony Chazapis | """
|
43 | a9b3f29d | Antony Chazapis | |
44 | a9b3f29d | Antony Chazapis | def __init__(self, **params): |
45 | c30635bf | Filippos Giannakos | params['mappool'] = 'maps' |
46 | c30635bf | Filippos Giannakos | self.rmap = RadosMapper(**params)
|
47 | c30635bf | Filippos Giannakos | self.fmap = FileMapper(**params)
|
48 | a9b3f29d | Antony Chazapis | |
49 | c30635bf | Filippos Giannakos | # def _get_rear_map(self, maphash, create=0):
|
50 | c30635bf | Filippos Giannakos | # return self.fmap._get_rear_map(maphash, create)
|
51 | a9b3f29d | Antony Chazapis | |
52 | c30635bf | Filippos Giannakos | # def _check_rear_map(self, maphash):
|
53 | c30635bf | Filippos Giannakos | # return self.rmap._check_rear_map(maphash)
|
54 | c30635bf | Filippos Giannakos | # return self.rmap._check_rear_map(maphash) and
|
55 | c30635bf | Filippos Giannakos | # self.fmap._check_rear_map(maphash)
|
56 | a9b3f29d | Antony Chazapis | |
57 | 1c2fc0ff | Antony Chazapis | def map_retr(self, maphash, blkoff=0, nr=100000000000000): |
58 | a9b3f29d | Antony Chazapis | """Return as a list, part of the hashes map of an object
|
59 | a9b3f29d | Antony Chazapis | at the given block offset.
|
60 | a9b3f29d | Antony Chazapis | By default, return the whole hashes map.
|
61 | a9b3f29d | Antony Chazapis | """
|
62 | c30635bf | Filippos Giannakos | return self.fmap.map_retr(maphash, blkoff, nr) |
63 | a9b3f29d | Antony Chazapis | |
64 | 1c2fc0ff | Antony Chazapis | def map_stor(self, maphash, hashes=(), blkoff=0, create=1): |
65 | 1c2fc0ff | Antony Chazapis | """Store hashes in the given hashes map."""
|
66 | c30635bf | Filippos Giannakos | self.rmap.map_stor(maphash, hashes, blkoff, create)
|
67 | c30635bf | Filippos Giannakos | self.fmap.map_stor(maphash, hashes, blkoff, create) |