def __init__(self, password=None, dbname='wa', host='localhost', port='5432', user='******', run_uuid=None, list_runs=False): if psycopg2 is None: msg = 'Please install the psycopg2 in order to connect to postgres databases' raise HostError(msg) self.dbname = dbname self.host = host self.port = port self.user = user self.password = password self.run_uuid = run_uuid self.conn = None self.info = None self.state = None self.result = None self.target_info = None self._combined_config = None self.jobs = [] self.job_specs = [] self.connect() super(RunDatabaseOutput, self).__init__(conn=self.conn, reload=False) local_schema_version, db_schema_version = get_schema_versions( self.conn) if local_schema_version != db_schema_version: self.disconnect() msg = 'The current database schema is v{} however the local ' \ 'schema version is v{}. Please update your database ' \ 'with the create command' raise HostError(msg.format(db_schema_version, local_schema_version)) if list_runs: print('Available runs are:') self._list_runs() self.disconnect() return if not self.run_uuid: print('Please specify "Run uuid"') self._list_runs() self.disconnect() return if not self.oid: self.oid = self._get_oid() self.reload()
def add_artifact(self, name, path, kind, description=None, classifiers=None): if not os.path.exists(path): path = self.get_path(path) if not os.path.exists(path): msg = 'Attempting to add non-existing artifact: {}' raise HostError(msg.format(path)) path = os.path.relpath(path, self.basepath) self.result.add_artifact(name, path, kind, description, classifiers)
def check_devlib_version(): if not installed_devlib_version or installed_devlib_version[: -1] <= required_devlib_version[: -1]: # Check the 'dev' field separately to account for comparing with release versions. if installed_devlib_version.dev and installed_devlib_version.dev < required_devlib_version.dev: msg = 'WA requires Devlib version >={}. Please update the currently installed version {}' raise HostError( msg.format(format_version(required_devlib_version), devlib.__version__))
def connect(self): if self.conn and not self.conn.closed: return try: self.conn = psycopg2.connect(dbname=self.dbname, user=self.user, host=self.host, password=self.password, port=self.port) except Psycopg2Error as e: raise HostError('Unable to connect to the Database: "{}'.format(e.args[0]))
def get_artifact(self, name): for artifact in self.artifacts: if artifact.name == name: return artifact raise HostError('Artifact "{}" not found'.format(name))
def check_devlib_version(): if not installed_devlib_version or installed_devlib_version < required_devlib_version: msg = 'WA requires Devlib version >={}. Please update the currently installed version {}' raise HostError( msg.format(format_version(required_devlib_version), devlib.__version__))