Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Merlijn Wajer
Python Derivermodule
Commits
ec999a72
Commit
ec999a72
authored
Nov 03, 2020
by
Merlijn Wajer
Browse files
task: add get arg and env getting
parent
d17d4a3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
derivermodule/scandata.py
View file @
ec999a72
...
...
@@ -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
):
"""
...
...
derivermodule/task.py
View file @
ec999a72
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):
Returns:
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.
Args:
* 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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment