1919from common .lib .helpers import get_software_commit , remove_nuls , send_email
2020from common .lib .exceptions import (WorkerInterruptedException , ProcessorInterruptedException , ProcessorException ,
2121 DataSetException , MapItemException )
22- from common .config_manager import config , ConfigWrapper
22+ from common .config_manager import ConfigWrapper
2323from common .lib .user import User
2424
2525
@@ -37,14 +37,14 @@ class BasicProcessor(FourcatModule, BasicWorker, metaclass=abc.ABCMeta):
3737 useful is another question).
3838
3939 To determine whether a processor can process a given dataset, you can
40- define a `is_compatible_with(FourcatModule module=None, str user =None):) -> bool` class
40+ define a `is_compatible_with(FourcatModule module=None, config =None):) -> bool` class
4141 method which takes a dataset as argument and returns a bool that determines
4242 if this processor is considered compatible with that dataset. For example:
4343
4444 .. code-block:: python
4545
4646 @classmethod
47- def is_compatible_with(cls, module=None, user =None):
47+ def is_compatible_with(cls, module=None, config =None):
4848 return module.type == "linguistic-features"
4949
5050
@@ -109,11 +109,10 @@ def work(self):
109109 self .job .finish ()
110110 return
111111
112- # set up config reader using the worker's DB connection and the dataset
113- # creator. This ensures that if a value has been overriden for the owner,
114- # the overridden value is used instead.
115- config .with_db (self .db )
116- self .config = ConfigWrapper (config = config , user = User .get_by_name (self .db , self .owner ))
112+ # set up config reader wrapping the worker's config manager, which is
113+ # in turn the one passed to it by the WorkerManager, which is the one
114+ # originally loaded in bootstrap
115+ self .config = ConfigWrapper (config = self .config , user = User .get_by_name (self .db , self .owner ))
117116
118117 if self .dataset .data .get ("key_parent" , None ):
119118 # search workers never have parents (for now), so we don't need to
@@ -170,7 +169,7 @@ def work(self):
170169 # get parameters
171170 # if possible, fill defaults where parameters are not provided
172171 given_parameters = self .dataset .parameters .copy ()
173- all_parameters = self .get_options (self .dataset )
172+ all_parameters = self .get_options (self .dataset , config = self . config )
174173 self .parameters = {
175174 param : given_parameters .get (param , all_parameters .get (param , {}).get ("default" ))
176175 for param in [* all_parameters .keys (), * given_parameters .keys ()]
@@ -179,7 +178,7 @@ def work(self):
179178 # now the parameters have been loaded into memory, clear any sensitive
180179 # ones. This has a side-effect that a processor may not run again
181180 # without starting from scratch, but this is the price of progress
182- options = self .get_options (self .dataset .get_parent ())
181+ options = self .get_options (self .dataset .get_parent (), config = self . config )
183182 for option , option_settings in options .items ():
184183 if option_settings .get ("sensitive" ):
185184 self .dataset .delete_parameter (option )
@@ -241,7 +240,7 @@ def after_process(self):
241240 next_parameters = next .get ("parameters" , {})
242241 next_type = next .get ("type" , "" )
243242 try :
244- available_processors = self .dataset .get_available_processors (user = self .dataset . creator )
243+ available_processors = self .dataset .get_available_processors (config = self .config )
245244 except ValueError :
246245 self .log .info ("Trying to queue next processor, but parent dataset no longer exists, halting" )
247246 break
@@ -329,7 +328,7 @@ def after_process(self):
329328
330329 self .job .finish ()
331330
332- if config .get ('mail.server' ) and self .dataset .get_parameters ().get ("email-complete" , False ):
331+ if self . config .get ('mail.server' ) and self .dataset .get_parameters ().get ("email-complete" , False ):
333332 owner = self .dataset .get_parameters ().get ("email-complete" , False )
334333 # Check that username is email address
335334 if re .match (r"[^@]+\@.*?\.[a-zA-Z]+" , owner ):
@@ -340,8 +339,8 @@ def after_process(self):
340339 import html2text
341340
342341 self .log .debug ("Sending email to %s" % owner )
343- dataset_url = ('https://' if config .get ('flask.https' ) else 'http://' ) + config .get ('flask.server_name' ) + '/results/' + self .dataset .key
344- sender = config .get ('mail.noreply' )
342+ dataset_url = ('https://' if self . config .get ('flask.https' ) else 'http://' ) + self . config .get ('flask.server_name' ) + '/results/' + self .dataset .key
343+ sender = self . config .get ('mail.noreply' )
345344 message = MIMEMultipart ("alternative" )
346345 message ["From" ] = sender
347346 message ["To" ] = owner
@@ -778,7 +777,7 @@ def is_filter(cls):
778777 return hasattr (cls , "category" ) and cls .category and "filter" in cls .category .lower ()
779778
780779 @classmethod
781- def get_options (cls , parent_dataset = None , user = None ):
780+ def get_options (cls , parent_dataset = None , config = None ):
782781 """
783782 Get processor options
784783
@@ -787,12 +786,11 @@ def get_options(cls, parent_dataset=None, user=None):
787786 fine-grained options, e.g. in cases where the availability of options
788787 is partially determined by the parent dataset's parameters.
789788
789+ :param config:
790790 :param DataSet parent_dataset: An object representing the dataset that
791791 the processor would be run on
792- :param User user: Flask user the options will be displayed for, in
793- case they are requested for display in the 4CAT web interface. This can
794- be used to show some options only to privileges users.
795- """
792+
793+
796794 return cls.options if hasattr(cls, "options") else {}
797795
798796 @classmethod
0 commit comments