result0.py 1.37 KB
Newer Older
Wei Shoulin's avatar
Wei Shoulin committed
1

Wei Shoulin's avatar
Wei Shoulin committed
2
3
from ..common.delegate import Delegate

Wei Shoulin's avatar
Wei Shoulin committed
4
class Result0Api(object):
Wei Shoulin's avatar
Wei Shoulin committed
5
6
7
8
    """
    Level 0 Operation Class of IFS
    """
    def __init__(self, sub_system="ifs"):
Wei Shoulin's avatar
Wei Shoulin committed
9
        self.sub_system = sub_system
Wei Shoulin's avatar
Wei Shoulin committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        self.module = Delegate().load(sub_module = "ifs")
        self.stub = getattr(self.module, "Result0Api")()
        self.file_prefix = self.stub.root_dir

    def find(self, **kwargs):
        '''
        parameter kwargs:
            raw_id = [int],
            file_name = [str],
            proc_type = [str]

        return list of level 0 record
        '''
        return self.stub.find(**kwargs)

    def get(self, **kwargs):
        '''  query database, return a record as dict

        parameter kwargs:
            fits_id = [int] 

        return dict or None
        '''
        return self.stub.get(**kwargs)

    def read(self, **kwargs):
        ''' yield bytes of fits file

        parameter kwargs:
            fits_id = [int],
            file_path = [str], 
            chunk_size = [int] default 20480

        yield bytes of fits file
        '''
        return self.stub.read(**kwargs)

    def write(self, **kwargs):
        ''' copy a local level 0 file to file storage, and insert a record into database

        parameter kwargs:
            raw_id = [int],
            file_path = [str],
            proc_type = [str]
        '''  
        yield self.stub.write(**kwargs)