Skip to content
Snippets Groups Projects
Commit 96a19a19 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

benchmark: factor DATA-VARS parsing in a `data_vars_key` function

Lets repeat ourself less.
parent 5747709d
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,12 @@
)
def data_vars_key(value):
"""return the data-vars key for a value if any, None otherwise"""
if value is not None and value.startswith('DATA-VARS:'):
return value.split(':', 1)[1]
return None
class UnknownBenchmarkMethod(KeyError):
pass
......@@ -160,8 +166,8 @@
def needed_vars(self):
variables = set()
cwd = self.get_var('simple-command.cwd')
if cwd is not None and cwd.startswith('DATA-VARS:'):
key = cwd.split(':', 1)[1]
key = data_vars_key(cwd)
if key is not None:
variables.add(key)
# XXX missing the "variable" part
return variables
......@@ -252,11 +258,11 @@
variables = {}
if variables_data is not None:
for name, value in variables_data.items():
if value.startswith('DATA-VARS:'):
key = value.split(':', 1)[1]
key = data_vars_key(value)
if key is not None:
value = get_var(key)
assert value is not None
variables[name] = value
self.command = self.base_command.format(**variables)
......@@ -257,11 +263,11 @@
value = get_var(key)
assert value is not None
variables[name] = value
self.command = self.base_command.format(**variables)
if self.cwd.startswith('DATA-VARS:'):
key = self.cwd.split(':', 1)[1]
key = data_vars_key(self.cwd)
if key is not None:
self.cwd = get_var(key)
class PerfBenchmark(Benchmark):
......@@ -312,9 +318,9 @@
def needed_vars(self):
variables = set()
cwd = self.get_var('hg-perf-ext.cwd')
if cwd is not None and cwd.startswith('DATA-VARS:'):
key = cwd.split(':', 1)[1]
key = data_vars_key(cwd)
if key is not None:
variables.add(key)
args = self.get_var('hg-perf-ext.args')
if args is not None:
for value in args:
......@@ -317,9 +323,9 @@
variables.add(key)
args = self.get_var('hg-perf-ext.args')
if args is not None:
for value in args:
if value.startswith('DATA-VARS:'):
key = value.split(':', 1)[1]
key = data_vars_key(value)
if key is not None:
variables.add(key)
return variables
......@@ -345,8 +351,8 @@
cwd = data_env_path
cfg_cwd = self.get_var('hg-perf-ext.cwd')
if cfg_cwd is not None:
if cfg_cwd.startswith('DATA-VARS:'):
key = cfg_cwd.split(':', 1)[1]
key = data_vars_key(cfg_cwd)
if key is not None:
cfg_cwd = data_var(key)
cwd = os.path.join(cwd, cfg_cwd)
......@@ -372,8 +378,8 @@
]
def filter_arg(value):
if value.startswith('DATA-VARS:'):
key = value.split(':', 1)[1]
key = data_vars_key(value)
if key is not None:
value = data_var(key)
assert value is not None
return value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment