mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-04-20 23:56:34 -04:00
Make brozzler.behaviors more configurable
`behaviors.yaml` is no longer hard-coded but its an option and `behaviors.yaml` is the default value. This way, we could use another YAML conf to check for different set of behaviors if necessary. This is required because we need to define login behaviors as a different set and we'll reuse the same method to load them.
This commit is contained in:
parent
212111f581
commit
5307760aaf
@ -94,17 +94,19 @@ def _logging_handler_handle(self, record):
|
||||
logging.Handler.handle = _logging_handler_handle
|
||||
|
||||
_behaviors = None
|
||||
def behaviors(behaviors_dir=None):
|
||||
def behaviors(behaviors_dir=None, conf='behaviors.yaml'):
|
||||
"""Return list of JS behaviors loaded from YAML file.
|
||||
|
||||
:param behaviors_dir: Directory containing `behaviors.yaml` and
|
||||
`js-templates/`. Defaults to brozzler dir.
|
||||
:param conf: The YAML definition of behaviors, it could also be
|
||||
`login-behaviors.yaml` to load login action behaviors.
|
||||
"""
|
||||
import os, yaml, string
|
||||
global _behaviors
|
||||
if _behaviors is None:
|
||||
d = behaviors_dir or os.path.dirname(__file__)
|
||||
behaviors_yaml = os.path.join(d, 'behaviors.yaml')
|
||||
behaviors_yaml = os.path.join(d, conf)
|
||||
with open(behaviors_yaml) as fin:
|
||||
_behaviors = yaml.safe_load(fin)
|
||||
return _behaviors
|
||||
|
Loading…
x
Reference in New Issue
Block a user