Commit ec999a72 authored by Merlijn Wajer's avatar Merlijn Wajer
Browse files

task: add get arg and env getting

parent d17d4a3d
......@@ -7,7 +7,7 @@ from pathlib import Path
import xmltodict
from .const import PB_ITEM, PB_TMP
from . import logger
from .logger import logger
def get_scandata_xml(identifier, source_file):
from json import load, dump
from os.path import join
from os import environ
from .const import PB_TASK
......@@ -40,4 +41,37 @@ def get_task_args(task_info):
dict of task arguments
return task['task']['args']
if 'task' in task_info and 'args' in task_info['task']:
return task_info['task']['args']
return {}
def get_task_arg_or_environ_arg(task_args, name):
Returns the value of a task argument if it is present in task_args or in
the environment.
The naming of task arguments is using lowercase and hypens, whereas the
enviroment variables are upper cased and use underscores. The functions
applies the task argument to environment variable to the `name` argument.
So if the task argument is 'ocr-perform-foo', pass that as `name`, and the
function will also check the environment variables for 'OCR_PERFORM_FOO'.
Environment arguments are preferred over task arguments.
* task_args: As returned by get_task_args
* name: Custom task argument name, implementation defined.
Returns the value of the argument, if present, and None otherwise.
environ_name = name.replace('-', '_').upper()
if environ_name in environ:
return environ.get(environ_name)
if name is task_args:
return task_args.get(name)
return None
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment