Skip to content

Commit

Permalink
Update logging in cli related files
Browse files Browse the repository at this point in the history
  • Loading branch information
doaa-altarawy committed Jul 18, 2019
1 parent 01111a8 commit 2549ae3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions qcfractal/cli/qcfractal_server.py
Expand Up @@ -239,7 +239,6 @@ def server_start(args, config):
logfile = str(config.base_path / config.fractal.logfile)

print("\n>>> Checking the PostgreSQL connection...")
database_name = config.database.database_name
psql = PostgresHarness(config, quiet=False, logger=print)

if not psql.is_alive():
Expand All @@ -251,7 +250,7 @@ def server_start(args, config):
sys.exit(1)

# make sure DB is created
psql.create_database(database_name)
psql.create_database(config.database.database_name)

print("\n>>> Initializing the QCFractal server...")
try:
Expand All @@ -267,7 +266,7 @@ def server_start(args, config):

# Database
storage_uri=config.database_uri(safe=False, database=""),
storage_project_name=database_name,
storage_project_name=config.database.database_name,
query_limit=config.fractal.query_limit,

# Log options
Expand Down
7 changes: 3 additions & 4 deletions qcfractal/config.py
Expand Up @@ -8,7 +8,6 @@
from typing import Optional

from pydantic import BaseSettings, Schema, validator
from typing import ClassVar
import yaml


Expand Down Expand Up @@ -103,7 +102,7 @@ class Config(SettingsCommonConfig):
class FractalConfig(ConfigSettings):

# class variable, not in the pydantic model
defaults_file_path: ClassVar[str] = os.path.expanduser("~/.qca/qcfractal_defaults.yaml")
_defaults_file_path: str = os.path.expanduser("~/.qca/qcfractal_defaults.yaml")

base_folder: str = Schema(os.path.expanduser("~/.qca/qcfractal"),
description="The QCFractal base instance to attach to.")
Expand All @@ -118,8 +117,8 @@ def __init__(self, **kwargs):
# If no base_folder provided, read it from ~/.qca/qcfractal_defaults.yaml (if it exists)
# else, use the default base_folder
if 'base_folder' not in kwargs:
if Path(FractalConfig.defaults_file_path).exists():
with open(FractalConfig.defaults_file_path, "r") as handle:
if Path(FractalConfig._defaults_file_path).exists():
with open(FractalConfig._defaults_file_path, "r") as handle:
kwargs['base_folder'] = yaml.load(handle.read(),
Loader=yaml.FullLoader)['default_base_folder']

Expand Down
13 changes: 7 additions & 6 deletions qcfractal/postgres_harness.py
Expand Up @@ -130,7 +130,7 @@ def command(self, cmd: str) -> Any:
self._check_psql()

if not self.quiet:
logger(f"pqsl command: {cmd}")
self.logger(f"pqsl command: {cmd}")
psql_cmd = [shutil.which("psql"), "-p", str(self.config.database.port), "-c"]
return self._run(psql_cmd + [cmd])

Expand Down Expand Up @@ -179,7 +179,7 @@ def create_tables(self):
"""Create database tables using SQLAlchemy models"""

uri = self.config.database_uri()
print(f'Creating tables for database: {uri}')
self.logger(f'tables for database: {uri}')
engine = create_engine(uri, echo=False, pool_size=1)

# actually create the tables
Expand All @@ -204,8 +204,8 @@ def upgrade(self):
ret = self._run(cmd)

if ret['retcode'] != 0:
raise ValueError("\nFailed to Upgrade the database, make sure to init the database first before being able to upgrade it.\n")
print(ret)
self.logger(ret)
raise ValueError(f"\nFailed to Upgrade the database, make sure to init the database first before being able to upgrade it.\n")

return True

Expand Down Expand Up @@ -326,16 +326,17 @@ def init_database(self):
self.create_tables()

# update alembic_version table with the current version
print('\nStamping Database with current version..')
self.logger(f'\nStamping Database with current version..')

ret = self._run([shutil.which('alembic'),
'-c', self._alembic_ini,
'-x', 'uri='+self.config.database_uri(),
'stamp', 'head'])

if ret['retcode'] != 0:
self.logger(ret)
raise ValueError("\nFailed to Stamp the database with current version.\n")
print(ret)



class TemporaryPostgres:
Expand Down

0 comments on commit 2549ae3

Please sign in to comment.