Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavara Tarun committed Mar 12, 2020
1 parent 17c0ca2 commit e022049
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions qds_sdk/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,23 +1347,42 @@ def parse(cls, args):
v["command_type"] = "DbTapQueryCommand"
return v


class JupyterNotebookCommand(Command):
usage = "jupyternotebookcmd <submit|run> [options]"

optparser = GentleOptionParser(usage=usage)
optparser.add_option("--path", dest="path", help="Path including name of the Jupyter notebook to be run with extension.")
optparser.add_option("--cluster-label", dest="label", help="Label of the cluster on which the this command should be run. If this parameter is not specified then label = 'default' is used.")
optparser.add_option("--arguments", dest="arguments", help="Valid JSON to be sent to the notebook. Specify the parameters in notebooks and pass the parameter value using the JSON format. key is the parameter's name and value is the parameter's value. Supported types in parameters are string, integer, float and boolean.")
optparser.add_option("--macros", dest="macros", help="expressions to expand macros used in query")
optparser.add_option("--path", dest="path",
help="Path including name of the Jupyter notebook to be run with extension.")
optparser.add_option("--cluster-label", dest="label",
help="Label of the cluster on which the this command should be run. \
If this parameter is not specified then label = 'default' is used.")
optparser.add_option("--arguments", dest="arguments",
help="Valid JSON to be sent to the notebook. Specify the parameters in \
notebooks and pass the parameter value using the JSON format. key is \
the parameter's name and value is the parameter's value. Supported \
types in parameters are string, integer, float and boolean.")
optparser.add_option("--macros", dest="macros",
help="expressions to expand macros used in query")
optparser.add_option("--name", dest="name", help="Assign a name to this query")
optparser.add_option("--tags", dest="tags", help="comma-separated list of tags to be associated with the query ( e.g. tag1 tag1,tag2 )")
optparser.add_option("--notify", action="store_true", dest="can_notify", default=False, help="sends an email on command completion")
optparser.add_option("--timeout", dest="timeout", type="int", help="Timeout for command execution in seconds")
optparser.add_option("--retry", dest="retry", choices=['1','2','3'], help="Number of retries for a job")
optparser.add_option("--retry-delay", dest="retry_delay", type="int", help="Time interval between the retries when a job fails.")
optparser.add_option("--pool", dest="pool", help="Specify the Fairscheduler pool name for the command to use")
optparser.add_option("--print-logs", action="store_true", dest="print_logs", default=False, help="Fetch logs and print them to stderr.")
optparser.add_option("--print-logs-live", action="store_true", dest="print_logs_live", default=False, help="Fetch logs and print them to stderr while command is running.")
optparser.add_option("--tags", dest="tags",
help="comma-separated list of tags to be associated with the query \
( e.g. tag1 tag1,tag2 )")
optparser.add_option("--notify", action="store_true", dest="can_notify",
default=False, help="sends an email on command completion")
optparser.add_option("--timeout", dest="timeout", type="int",
help="Timeout for command execution in seconds")
optparser.add_option("--retry", dest="retry", choices=['1', '2', '3'],
help="Number of retries for a job")
optparser.add_option("--retry-delay", dest="retry_delay", type="int",
help="Time interval between the retries when a job fails.")
optparser.add_option("--pool", dest="pool",
help="Specify the Fairscheduler pool name for the command to use")
optparser.add_option("--print-logs", action="store_true", dest="print_logs",
default=False, help="Fetch logs and print them to stderr.")
optparser.add_option("--print-logs-live", action="store_true",
dest="print_logs_live", default=False,
help="Fetch logs and print them to stderr while command is running.")

@classmethod
def parse(cls, args):
Expand All @@ -1383,7 +1402,8 @@ def parse(cls, args):
try:
options, args = cls.optparser.parse_args(args)
if options.path is None:
raise ParseError("Notebook Path must be specified", cls.optparser.format_help())
raise ParseError("Notebook Path must be specified",
cls.optparser.format_help())
if options.arguments is not None:
validate_json_input(options.arguments, 'Arguments', cls)
if options.macros is not None:
Expand Down Expand Up @@ -1419,11 +1439,13 @@ def handler(self, signum, frame):
if signum in self.term_signals:
self.received_term_signal = True


def validate_json_input(string, option_type, cls):
try:
return json.loads(string)
except ValueError as e:
raise ParseError("Given %s is not valid JSON: %s" % (option_type, str(e)), cls.optparser.format_help())
raise ParseError("Given %s is not valid JSON: %s" % (option_type, str(e)),
cls.optparser.format_help())

def _read_iteratively(key_instance, fp, delim):
key_instance.open_read()
Expand Down

0 comments on commit e022049

Please sign in to comment.