Skip to content

Commit

Permalink
small update to the command line interface
Browse files Browse the repository at this point in the history
  • Loading branch information
squoilin committed Feb 9, 2020
1 parent 8e02a6f commit b2cc2a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
16 changes: 3 additions & 13 deletions dispaset/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import click

from .preprocessing.data_handler import load_config_excel,load_config_yaml
from .preprocessing.data_handler import load_config
from .preprocessing.preprocessing import build_simulation
from .solve import solve_GAMS
from ._version import __version__
Expand All @@ -14,17 +14,10 @@
@click.pass_context
def cli(ctx, config):
"""Build and run the Dispaset model according to a config file.
E.g. ./dispaset.py -c ./ConfigFiles/ConfigTest.xlsx build simulate
E.g. dispaset -c ./ConfigFiles/ConfigTest.xlsx build simulate
"""
ctx.obj = {}
if config.endswith(('.xlsx','.xls')):
ctx.obj['conf'] = load_config_excel(config)
elif config.endswith(('.yml','.yaml')):
ctx.obj['conf'] = load_config_yaml(config)
else:
logging.error('Unrecognized file format')
sys.exit(1)

ctx.obj['conf'] = load_config(config)

@cli.command()
@click.pass_context
Expand All @@ -41,6 +34,3 @@ def simulate(ctx):
conf = ctx.obj['conf']

r = solve_GAMS(conf['SimulationDirectory'], conf['GAMS_folder'])

#if __name__ == '__main__':
# cli(obj={},standalone_mode=False)
4 changes: 2 additions & 2 deletions dispaset/preprocessing/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ def load_config(ConfigFile,AbsPath=True):
"""
Wrapper function around load_config_excel and load_config_yaml
"""
if ConfigFile[-5:] == '.xlsx':
if ConfigFile.endswith(('.xlsx','.xls')):
config = load_config_excel(ConfigFile,AbsPath=True)
elif ConfigFile[-4:] == '.yml':
elif ConfigFile.endswith(('.yml','.yaml')):
config = load_config_yaml(ConfigFile,AbsPath=True)
else:
logging.critical('The extension of the config file should be .xlsx or .yml')
Expand Down

0 comments on commit b2cc2a0

Please sign in to comment.