config_reader.py 3.92 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#
# Copyright (C) 2012 INRA
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os
19
import sys
Jerome Mariette's avatar
Jerome Mariette committed
20
21
22
import inspect

from ConfigParser import ConfigParser, NoOptionError
23
24
25

from jflow.utils import which

Jerome Mariette's avatar
Jerome Mariette committed
26
27
28
29
30

class JFlowConfigReader(object):
    """
    """
    
Jerome Mariette's avatar
Jerome Mariette committed
31
    CONFIG_FILE_PATH = "../../application.properties"
Jerome Mariette's avatar
Jerome Mariette committed
32
33
34
35
36
37
38
39
    
    def __init__(self):
        """ 
        """
        self.reader = ConfigParser()
        self.reader.read(os.path.join(os.path.dirname(inspect.getfile(self.__class__)), self.CONFIG_FILE_PATH))

    def get_tmp_directory(self):
Jerome Mariette's avatar
Jerome Mariette committed
40
41
        if not os.path.isdir(self.reader.get("storage", "tmp_directory")):
            os.makedirs(self.reader.get("storage", "tmp_directory"), 0751)
Jerome Mariette's avatar
Jerome Mariette committed
42
43
        return self.reader.get("storage", "tmp_directory")
        
Jerome Mariette's avatar
Jerome Mariette committed
44
45
    def get_work_directory(self):
        return self.reader.get("storage", "work_directory")
Jerome Mariette's avatar
Jerome Mariette committed
46
47
48
    
    def get_exec(self, software):
        try:
49
            return self.reader.get("softwares", software)
Jerome Mariette's avatar
Jerome Mariette committed
50
        except NoOptionError, e:
51
            return None
Jerome Mariette's avatar
Jerome Mariette committed
52

53
54
55
    def get_resource(self, resource):
        return self.reader.get("resources", resource)

Jerome Mariette's avatar
Jerome Mariette committed
56
57
58
59
60
61
62
63
64
65
66
67
    def get_log_file_path(self):
        """
        return the log file path
          @return: the path to the log file
        """
        try:
            return self.reader.get('storage', 'log_file')
        except :
            raise Error("Failed when parsing the config file, no section logging found!")
        
    def get_makeflow_path(self):
        try:
68
            exec_path = self.reader.get("global", "makeflow")
Jerome Mariette's avatar
Jerome Mariette committed
69
        except NoOptionError, e:
70
            exec_path = None
Jerome Mariette's avatar
Jerome Mariette committed
71
        if exec_path is None: exec_path = "makeflow"
72
        if which(exec_path) == None:
73
74
75
76
            sys.stderr.write("Error: 'makeflow' path connot be retrieved either in the PATH and in the application.properties file!\n")
            sys.exit(1)
        return exec_path
    
Jerome Mariette's avatar
Jerome Mariette committed
77
78
    def get_batch(self):
        try:
79
80
            type = self.reader.get("global", "batch_system_type")
            options = self.reader.get("global", "batch_options")
81
82
            limit_submission = self.reader.get("global", "limit_submission")
            return [type, options, limit_submission]
Jerome Mariette's avatar
Jerome Mariette committed
83
84
        except NoOptionError, e:
            return None
85
          
86
87
    def get_socket_options(self):
        try:
Jerome Mariette's avatar
Jerome Mariette committed
88
            return [self.reader.get("global", "server_socket_host"), int(self.reader.get("global", "server_socket_port"))]
89
        except:
Jerome Mariette's avatar
Jerome Mariette committed
90
            return ["127.0.0.1", 8080]
91
92
93
94
        
    def get_email_options(self):
        try: smtps = self.reader.get("email", "smtp_server")
        except: smtps = None
95
96
        try: smtpp = self.reader.get("email", "smtp_port")
        except: smtpp = None
97
98
        try: froma = self.reader.get("email", "from_address")
        except: froma = None
99
100
        try: fromp = self.reader.get("email", "from_password")
        except: fromp = None
101
102
103
104
105
106
        try: toa = self.reader.get("email", "to_address")
        except: toa = None
        try: subject = self.reader.get("email", "subject")
        except: subject = None
        try: message = self.reader.get("email", "message")
        except: message = None
107
        return [smtps, smtpp, froma, fromp, toa, subject, message]
108
    
109
110
111
112
113
    def get_component_batch_options(self, component_class):
        try:
            return self.reader.get("components", component_class+".batch_options")
        except:
            return ""
114