Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from gvallarelli/bug-847818_command_line_runne…
…r_mt bug-847818_command_line_runner_mt
- Loading branch information
Showing
2 changed files
with
94 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
import sys | ||
import os | ||
import argparse | ||
# -*- coding: utf-8 -*- | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
# Copyright (c) 2010-2011, GEM Foundation. | ||
# | ||
# OpenQuake is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License version 3 | ||
# only, as published by the Free Software Foundation. | ||
# | ||
# OpenQuake is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License version 3 for more details | ||
# (a copy is included in the LICENSE file that accompanied this code). | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# version 3 along with OpenQuake. If not, see | ||
# <http://www.gnu.org/licenses/lgpl-3.0.txt> for a copy of the LGPLv3 License. | ||
|
||
from mtoolkit.workflow import Context, PipeLineBuilder | ||
|
||
|
||
def build_cmd_parser(): | ||
"""Create a simple parser for cmdline""" | ||
|
||
parser = argparse.ArgumentParser(prog='MToolkit') | ||
parser.add_argument('-i', '--input-file', | ||
dest='input_file', | ||
nargs=1, | ||
metavar='input file', | ||
help="""Specify the configuration | ||
file (i.e. config.yml)""") | ||
parser.add_argument('-v', '--version', | ||
action='version', | ||
version="%(prog)s 0.0.1") | ||
return parser | ||
from mtoolkit.console import cmd_line | ||
from mtoolkit.workflow import Context, PipeLineBuilder | ||
|
||
|
||
if __name__ == '__main__': | ||
PARSER = build_cmd_parser() | ||
if len(sys.argv) == 1: | ||
PARSER.print_help() | ||
else: | ||
ARGS = PARSER.parse_args() | ||
if ARGS.input_file != None: | ||
if os.path.exists(ARGS.input_file[0]): | ||
CONTEXT = Context("config.yml") | ||
PIPELINE = PipeLineBuilder("test pipeline").build( | ||
CONTEXT.config) | ||
PIPELINE.run(CONTEXT) | ||
print CONTEXT.vcl | ||
print CONTEXT.vmain_shock | ||
print CONTEXT.flag_vector | ||
else: | ||
print 'Error: non existent input file\n' | ||
PARSER.print_help() | ||
INPUT_CONFIG_FILENAME = cmd_line() | ||
if INPUT_CONFIG_FILENAME != None: | ||
CONTEXT = Context(INPUT_CONFIG_FILENAME) | ||
PIPELINE = PipeLineBuilder("test pipeline").build( | ||
CONTEXT.config) | ||
PIPELINE.run(CONTEXT) | ||
|
||
print CONTEXT.vcl | ||
print CONTEXT.vmain_shock | ||
print CONTEXT.flag_vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
# Copyright (c) 2010-2011, GEM Foundation. | ||
# | ||
# OpenQuake is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License version 3 | ||
# only, as published by the Free Software Foundation. | ||
# | ||
# OpenQuake is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License version 3 for more details | ||
# (a copy is included in the LICENSE file that accompanied this code). | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# version 3 along with OpenQuake. If not, see | ||
# <http://www.gnu.org/licenses/lgpl-3.0.txt> for a copy of the LGPLv3 License. | ||
|
||
""" | ||
A set of utility functions for cmdline | ||
""" | ||
|
||
import os | ||
import sys | ||
import argparse | ||
|
||
|
||
def build_cmd_parser(): | ||
""" | ||
Create a simple parser for cmdline | ||
""" | ||
|
||
parser = argparse.ArgumentParser(prog='MToolkit') | ||
parser.add_argument('-i', '--input-file', | ||
dest='input_file', | ||
nargs=1, | ||
metavar='input file', | ||
help="""Specify the configuration | ||
file (i.e. config.yml)""") | ||
parser.add_argument('-v', '--version', | ||
action='version', | ||
version="%(prog)s 0.0.1") | ||
return parser | ||
|
||
|
||
def cmd_line(): | ||
""" | ||
Return cmdline input argument | ||
after checking the proper input | ||
has been given. | ||
""" | ||
|
||
parser = build_cmd_parser() | ||
input_filename = None | ||
if len(sys.argv) == 1: | ||
parser.print_help() | ||
else: | ||
args = parser.parse_args() | ||
if os.path.exists(args.input_file[0]): | ||
input_filename = args.input_file[0] | ||
else: | ||
print 'Error: non existent input file\n' | ||
parser.print_help() | ||
|
||
return input_filename |