@@ -63,10 +63,13 @@ def _init_access(self):
63
63
project_id = self .project_id )
64
64
65
65
def _initialize_analyzer (self ):
66
- analyzer = self .analyzer
67
- logger .debug ("Project '%s': initialized analyzer: %s" ,
68
- self .project_id ,
69
- str (analyzer ))
66
+ try :
67
+ analyzer = self .analyzer
68
+ logger .debug ("Project '%s': initialized analyzer: %s" ,
69
+ self .project_id ,
70
+ str (analyzer ))
71
+ except AnnifException as err :
72
+ logger .warning (err .format_message ())
70
73
71
74
def _initialize_subjects (self ):
72
75
try :
@@ -88,10 +91,10 @@ def _initialize_vectorizer(self):
88
91
89
92
def _initialize_backend (self ):
90
93
logger .debug ("Project '%s': initializing backend" , self .project_id )
91
- if not self .backend :
92
- logger .debug ("Cannot initialize backend: does not exist" )
93
- return
94
94
try :
95
+ if not self .backend :
96
+ logger .debug ("Cannot initialize backend: does not exist" )
97
+ return
95
98
self .backend .initialize ()
96
99
except AnnifException as err :
97
100
logger .warning (err .format_message ())
@@ -121,13 +124,22 @@ def _suggest_with_backend(self, text, backend_params):
121
124
122
125
@property
123
126
def analyzer (self ):
124
- if self ._analyzer is None and self .analyzer_spec :
125
- self ._analyzer = annif .analyzer .get_analyzer (self .analyzer_spec )
127
+ if self ._analyzer is None :
128
+ if self .analyzer_spec :
129
+ self ._analyzer = annif .analyzer .get_analyzer (
130
+ self .analyzer_spec )
131
+ else :
132
+ raise ConfigurationException (
133
+ "analyzer setting is missing (and needed by the backend)" ,
134
+ project_id = self .project_id )
126
135
return self ._analyzer
127
136
128
137
@property
129
138
def backend (self ):
130
139
if self ._backend is None :
140
+ if 'backend' not in self .config :
141
+ raise ConfigurationException (
142
+ "backend setting is missing" , project_id = self .project_id )
131
143
backend_id = self .config ['backend' ]
132
144
try :
133
145
backend_class = annif .backend .get_backend (backend_id )
@@ -215,7 +227,7 @@ def dump(self):
215
227
return {'project_id' : self .project_id ,
216
228
'name' : self .name ,
217
229
'language' : self .language ,
218
- 'backend' : {'backend_id' : self .config [ 'backend' ] }
230
+ 'backend' : {'backend_id' : self .config . get ( 'backend' ) }
219
231
}
220
232
221
233
def remove_model_data (self ):
@@ -242,7 +254,11 @@ def _create_projects(projects_file, datadir, init_projects):
242
254
config = configparser .ConfigParser ()
243
255
config .optionxform = lambda option : option
244
256
with open (projects_file , encoding = 'utf-8' ) as projf :
245
- config .read_file (projf )
257
+ try :
258
+ config .read_file (projf )
259
+ except (configparser .DuplicateOptionError ,
260
+ configparser .DuplicateSectionError ) as err :
261
+ raise ConfigurationException (err )
246
262
247
263
# create AnnifProject objects from the configuration file
248
264
projects = collections .OrderedDict ()
0 commit comments