Skip to content

Commit

Permalink
Merge pull request #201 from PolyJIT/b/fix-ConfigPath
Browse files Browse the repository at this point in the history
Minor Fixes & Adjustments.
  • Loading branch information
simbuerg committed Jul 11, 2018
2 parents 709db10 + 983a961 commit 837297a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
2 changes: 0 additions & 2 deletions benchbuild/cli/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from plumbum import cli

import benchbuild.utils.bootstrap as bs
import benchbuild.utils.path as p
from benchbuild.cli.main import BenchBuild
from benchbuild.settings import CFG

Expand All @@ -27,7 +26,6 @@ class BenchBuildBootstrap(cli.Application):
def main(self, *args):
del args # Unused

p.mkdir_interactive(str(CFG["build_dir"]))
print("Checking benchbuild binary dependencies...")
provide_package("cmake")
provide_package("fusermount")
Expand Down
3 changes: 0 additions & 3 deletions benchbuild/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def set_group(self, groups):
pretend = cli.Flag(['p', 'pretend'], default=False)

def __generate_plan(self, exps, prjs, cfg):
if prjs:
path.mkdir_interactive(str(cfg["build_dir"]))

for exp_cls in exps.values():
exp = exp_cls(projects=prjs)
eactn = actions.Experiment(obj=exp, actions=exp.actions())
Expand Down
2 changes: 1 addition & 1 deletion benchbuild/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def configure():
details_hdl.setFormatter(details_format)
root_logger.addHandler(details_hdl)
else:
brief_format = logging.Formatter('%(name)s %(message)s')
brief_format = logging.Formatter('%(message)s')
console_hdl = logging.StreamHandler()
console_hdl.setFormatter(brief_format)
root_logger.addHandler(console_hdl)
Expand Down
2 changes: 1 addition & 1 deletion benchbuild/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def mkdir_interactive(dirpath):
return

response = ui.ask(
"The build directory {dirname} does not exist yet. "
"The directory {dirname} does not exist yet. "
"Should I create it?".format(dirname=dirpath),
default_answer=True,
default_answer_str="yes")
Expand Down
37 changes: 27 additions & 10 deletions benchbuild/utils/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def process_result_value(self, value, dialect):
if isinstance(value, uuid.UUID):
return value
else:
LOG.error(str(value))
return uuid.UUID(str(value))


Expand Down Expand Up @@ -291,15 +290,37 @@ def needed_schema(connection, meta):
except sa.exc.CompileError as cerr:
LOG.fatal("Schema could not be created! Details: %s", str(cerr))
sys.exit(-4)
except sa.exc.OperationalError:
# SQLite throws an OperationalError
return False
except sa.exc.ProgrammingError:
# PostgreSQL throws a ProgrammingError
return False
return True


def setup_versioning():
def get_version_data():
"""Retreive migration information."""
connect_str = settings.CFG["db"]["connect_string"].value()
repo_url = bbpath.template_path("../db/")
return (connect_str, repo_url)


def enforce_versioning(force=False):
"""Install versioning on the db."""
connect_str, repo_url = get_version_data()
LOG.warning("Your database uses an unversioned benchbuild schema.")
if not force and not ui.ask(
"Should I enforce version control on your schema?"):
LOG.error("User declined schema versioning.")
return None
repo_version = migrate.version(repo_url, url=connect_str)
migrate.version_control(connect_str, repo_url, version=repo_version)
return repo_version


def setup_versioning():
connect_str, repo_url = get_version_data()
repo_version = migrate.version(repo_url, url=connect_str)
db_version = None
requires_versioning = False
Expand All @@ -309,19 +330,14 @@ def setup_versioning():
requires_versioning = True

if requires_versioning:
LOG.warning("Your database uses an unversioned benchbuild schema.")
if not ui.ask("Should I enforce version control on your schema?"):
LOG.error("User declined schema versioning.")
return (-1, -1)
migrate.version_control(connect_str, repo_url)
return setup_versioning()
db_version = enforce_versioning()

return (repo_version, db_version)


def maybe_update_db(repo_version, db_version):
if db_version is None:
db_version = -1
return
if db_version == repo_version:
return

Expand Down Expand Up @@ -371,7 +387,7 @@ def configure_engine(self):
try:
self.connection.execution_options(isolation_level="READ COMMITTED")
except sa.exc.ArgumentError:
LOG.error("Unable to set isolation level to READ COMMITTED")
LOG.warning("Unable to set isolation level to READ COMMITTED")
return True

def __init__(self):
Expand All @@ -390,6 +406,7 @@ def __init__(self):

if needed_schema(self.connection, BASE.metadata):
LOG.debug("Initialized new db schema.")
enforce_versioning(force=True)
repo_version, db_version = setup_versioning()
maybe_update_db(repo_version, db_version)

Expand Down
20 changes: 14 additions & 6 deletions benchbuild/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,14 @@ def value(self):
TEST_X_Z=2
"""

def validate(node_value):
if hasattr(node_value, 'validate'):
node_value.validate()
return node_value

if 'value' in self.node:
return self.node['value']
return validate(self.node['value'])
else:
return self

Expand Down Expand Up @@ -404,17 +410,19 @@ class ConfigPath(object):
>>> p = ConfigPath(['tmp']); str(p)
'/tmp'
>>> p = ConfigPath('/tmp/test/foo'); str(p)
The path '/tmp/test/foo' is required by your configuration.
'/tmp/test/foo'
>>> p.validate()
The path '/tmp/test/foo' is required by your configuration.
>>> p.validate()
>>> p = ConfigPath([]); str(p)
'/'
"""
components = attr.ib(converter=convert_components)

@components.validator
def validate_path(self, attribute, value):
del attribute
path_str = ConfigPath.path_to_str(value)
def validate(self):
"""Make sure this configuration path exists."""
path_str = ConfigPath.path_to_str(self.components)
path_exists = os.path.exists(path_str)

def create_dir():
Expand Down
8 changes: 7 additions & 1 deletion benchbuild/utils/user_interface.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""
User interface helpers for benchbuild.
"""
import sys
import logging
import os
import sys

LOG = logging.getLogger(__name__)


# Taken from the following recipe: http://code.activestate.com/recipes/577058/
Expand Down Expand Up @@ -76,4 +79,7 @@ def should_ignore_tty():
has_tty = sys.stdin.isatty() and not ignore_stdin_istty
if has_tty:
response = query_yes_no(question, default_answer_str)
else:
LOG.debug("NoTTY: %s -> %s", question, response)

return response

0 comments on commit 837297a

Please sign in to comment.