Commit b0775157 authored by Baptiste CHOCOT's avatar Baptiste CHOCOT
Browse files

Development is now pep8 compliant

parent f6f45cf5
......@@ -10,49 +10,61 @@ import argparse
import sys
from diva_evaluation_cli.bin.commands.actev_get_system import ActevGetSystem
from diva_evaluation_cli.bin.commands.actev_system_setup import ActevSystemSetup
from diva_evaluation_cli.bin.commands.actev_validate_system import ActevValidateSystem
from diva_evaluation_cli.bin.commands.actev_design_chunks import ActevDesignChunks
from diva_evaluation_cli.bin.commands.actev_experiment_init import ActevExperimentInit
from diva_evaluation_cli.bin.commands.actev_pre_process_chunk import ActevPreProcessChunk
from diva_evaluation_cli.bin.commands.actev_process_chunk import ActevProcessChunk
from diva_evaluation_cli.bin.commands.actev_post_process_chunk import ActevPostProcessChunk
from diva_evaluation_cli.bin.commands.actev_system_setup import \
ActevSystemSetup
from diva_evaluation_cli.bin.commands.actev_validate_system import \
ActevValidateSystem
from diva_evaluation_cli.bin.commands.actev_design_chunks import \
ActevDesignChunks
from diva_evaluation_cli.bin.commands.actev_experiment_init import \
ActevExperimentInit
from diva_evaluation_cli.bin.commands.actev_pre_process_chunk import \
ActevPreProcessChunk
from diva_evaluation_cli.bin.commands.actev_process_chunk import \
ActevProcessChunk
from diva_evaluation_cli.bin.commands.actev_post_process_chunk import \
ActevPostProcessChunk
from diva_evaluation_cli.bin.commands.actev_reset_chunk import ActevResetChunk
from diva_evaluation_cli.bin.commands.actev_experiment_cleanup import ActevExperimentCleanup
from diva_evaluation_cli.bin.commands.actev_merge_chunks import ActevMergeChunks
from diva_evaluation_cli.bin.commands.actev_experiment_cleanup import \
ActevExperimentCleanup
from diva_evaluation_cli.bin.commands.actev_merge_chunks import \
ActevMergeChunks
from diva_evaluation_cli.bin.commands.actev_exec import ActevExec
from diva_evaluation_cli.bin.commands.actev_status import ActevStatus
from diva_evaluation_cli.bin.commands.actev_validate_execution import ActevValidateExecution
from diva_evaluation_cli.bin.commands.actev_validate_execution import \
ActevValidateExecution
from diva_evaluation_cli.bin.commands.actev_clear_logs import ActevClearLogs
private_subcommands = [
ActevGetSystem(),
ActevValidateSystem(),
ActevExec(),
ActevStatus(),
ActevValidateExecution(),
ActevClearLogs()
ActevGetSystem(),
ActevValidateSystem(),
ActevExec(),
ActevStatus(),
ActevValidateExecution(),
ActevClearLogs()
]
public_subcommands = [
ActevSystemSetup(),
ActevDesignChunks(),
ActevExperimentInit(),
ActevPreProcessChunk(),
ActevProcessChunk(),
ActevPostProcessChunk(),
ActevResetChunk(),
ActevMergeChunks(),
ActevExperimentCleanup(),
ActevSystemSetup(),
ActevDesignChunks(),
ActevExperimentInit(),
ActevPreProcessChunk(),
ActevProcessChunk(),
ActevPostProcessChunk(),
ActevResetChunk(),
ActevMergeChunks(),
ActevExperimentCleanup(),
]
def cli_parser():
""" Main command to parse commands and arguments
"""
# Initialize logger
logging.getLogger().setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter('[%(asctime)s] diva_evaluation_cli-%(levelname)s: %(message)s'))
handler.setFormatter(logging.Formatter(
'[%(asctime)s] diva_evaluation_cli-%(levelname)s: %(message)s'))
logging.getLogger().addHandler(handler)
# Initialize parser
......@@ -73,8 +85,10 @@ def cli_parser():
else:
parser.print_help()
def main():
cli_parser()
if __name__ == '__main__':
main()
......@@ -3,14 +3,15 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
import logging
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.entry_points.actev_clear_logs import entry_point
from diva_evaluation_cli.bin.private_src.entry_points.actev_clear_logs import \
entry_point
class ActevClearLogs(ActevCommand):
......@@ -20,11 +21,14 @@ class ActevClearLogs(ActevCommand):
super(ActevClearLogs, self).__init__('clear-logs', entry_point)
def cli_parser(self, arg_parser):
"""Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to
parse the command
"""
arg_parser.description = "Delete temporary files as resource and status monitoring files"
arg_parser.description = "Delete temporary files as resource and " \
"status monitoring files"
arg_parser.set_defaults(func=ActevClearLogs.command, object=self)
......@@ -3,16 +3,22 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
import abc
import logging
import sys
import os
from diva_evaluation_cli.bin.private_src.implementation.utils.actev_cli_environment import activate_environment
from diva_evaluation_cli.bin.private_src.implementation.resources_monitoring.monitor import Monitor
from diva_evaluation_cli.bin.private_src.implementation.status.status_factory import StatusFactory
from diva_evaluation_cli.bin.private_src.implementation.utils.\
actev_cli_environment import activate_environment
from diva_evaluation_cli.bin.private_src.implementation.resources_monitoring.\
monitor import Monitor
from diva_evaluation_cli.bin.private_src.implementation.status.status_factory \
import StatusFactory
class ActevCommand():
""" Abstract class that represents an actev command.
......@@ -23,20 +29,24 @@ class ActevCommand():
Attributes:
command (str): Name of the actev command
entry_point (function): Python function that represents an entry point
before_entry_point (function, optional): Python function that should be executed before entry_point method
after_entry_point (function, optional): Python function that should be executed after entry_point method
before_entry_point (function, optional): Python function that should
be executed before entry_point method
after_entry_point (function, optional): Python function that should be
executed after entry_point method
"""
__metaclass__ = abc.ABCMeta
def __init__(self, command, entry_point, before_entry_point=None, after_entry_point=None):
def __init__(self, command, entry_point, before_entry_point=None,
after_entry_point=None):
"""
Args:
command (str): Name of the actev command
entry_point (function): Python function that represents an entry point
before_entry_point (function, optional): Python function that should be executed before entry_point method
after_entry_point (function, optional): Python function that should be executed after entry_point method
entry_point (function): Python function that represents an entry
point
before_entry_point (function, optional): Python function that
should be executed before entry_point method
after_entry_point (function, optional): Python function that
should be executed after entry_point method
"""
self.command = command
self.entry_point = entry_point
......@@ -45,20 +55,21 @@ class ActevCommand():
@abc.abstractmethod
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to
parse the command
"""
return
def before_command(self, args):
""" Execute an action before executing the command
"""Execute an action before executing the command
Args:
args (:obj:`dict`): contains the arguments passed during the actev command call
args (:obj:`dict`): contains the arguments passed during the actev
command call
"""
if self.before_entry_point:
self.before_entry_point(**args.__dict__)
......@@ -67,18 +78,19 @@ class ActevCommand():
""" Execute an action after executing the command
Args:
args (:obj:`dict`): contains the arguments passed during the actev command call
args (:obj:`dict`): contains the arguments passed during the actev
command call
"""
if self.after_entry_point:
self.after_entry_point(**args.__dict__)
def command(self, args):
""" Gets arguments and passe them to an entry point. Catch the exception occured.
"""Gets arguments and passe them to an entry point. Catch the
exception occured.
Args:
args (:obj:`dict`): contains the arguments passed during the actev command call
args (:obj:`dict`): contains the arguments passed during the actev
command call
"""
del args.__dict__['object']
del args.__dict__['func']
......@@ -96,7 +108,7 @@ class ActevCommand():
self.before_command(args)
mon = Monitor(self.entry_point, args, self.command)
mon.run_monitor()
mon.run_monitor()
self.after_command(args)
logging.info("%s done" % self.command)
......
......@@ -3,38 +3,52 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.src.entry_points.actev_design_chunks import entry_point
from diva_evaluation_cli.src.entry_points.actev_design_chunks import \
entry_point
class ActevDesignChunks(ActevCommand):
"""Given a file index and an activity index, produce a chunks file that is suitable for the system.
"""Given a file index and an activity index, produce a chunks file that is
suitable for the system.
Command args:
* file-index or f: path to file index json file for test set
* activity-index or a: path to activity index json file for test set
* file-index or f: path to file index json for test set
* activity-index or a: path to activity index json for test set
* output or o: path to save chunks file
* nb_video-per-chunk or n: number of videos in the chunk
"""
def __init__(self):
super(ActevDesignChunks, self).__init__('design-chunks', entry_point)
def cli_parser(self, arg_parser):
"""Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to
parse the command
"""
arg_parser.description = "Produce a chunks file that is suitable for the system"
required_named = arg_parser.add_argument_group('required named arguments')
required_named.add_argument("-f", "--file-index", help="path to file index json file", required=True)
required_named.add_argument("-a", "--activity-index", help="path to activity index json file", required=True)
required_named.add_argument("-o", "--output", help="path to save chunks file", required=True)
arg_parser.add_argument("-n", "--nb-videos-per-chunk", type=int, help="number of videos in a chunk")
arg_parser.description = "Produce a chunks file that is suitable " \
"for the system"
required_named = arg_parser.add_argument_group(
'required named arguments')
required_named.add_argument("-f", "--file-index",
help="path to file index json file",
required=True)
required_named.add_argument("-a", "--activity-index",
help="path to activity index json file",
required=True)
required_named.add_argument("-o", "--output",
help="path to save chunks file",
required=True)
arg_parser.add_argument("-n", "--nb-videos-per-chunk", type=int,
help="number of videos in a chunk")
arg_parser.set_defaults(func=ActevDesignChunks.command, object=self)
......@@ -3,52 +3,76 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
import logging
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.entry_points.actev_exec import entry_point
from diva_evaluation_cli.bin.private_src.entry_points.actev_exec import \
entry_point
class ActevExec(ActevCommand):
"""Calls a team-implemented API. Captures time stamps, resource usage, etc.
Command args:
* file-index or f: path to file index json file for test set
* activity-index or a: path to activity index json file for test set
* file-index or f: path to file index json for test set
* activity-index or a: path to activity index json for test set
* chunks or c: path to chunks json file
* nb-video-per-chunk or n: number of videos in the chunk
* video-location or v: path to videos content
* system-cache-dir or s: path to system cache directory
* config-file or C: path to config file
* output-file: path to merge chunks command result
* chunk_result: path to chunks json file after merge chunks execution
* chunk_result: path to chunks json file after merge
chunks execution
"""
def __init__(self):
super(ActevExec, self).__init__('exec', entry_point)
def cli_parser(self, arg_parser):
"""Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to
parse the command
"""
arg_parser.description= "Calls a team-implemented API. Captures time stamps, resource usage, etc."
required_named = arg_parser.add_argument_group('required named arguments')
arg_parser.description = "Calls a team-implemented API. Captures " \
"timestamps, resource usage, etc."
required_named = arg_parser.add_argument_group(
'required named arguments')
required_named.add_argument("-f", "--file-index", help="path to file index json file", required=True)
required_named.add_argument("-a", "--activity-index", help="path to activity index json file", required=True)
required_named.add_argument("-c", "--chunks", help="path to chunks json file", required=True)
arg_parser.add_argument("-n", "--nb-videos-per-chunk", help="number of videos in a chunk")
required_named.add_argument("-f", "--file-index",
help="path to file index json file",
required=True)
required_named.add_argument("-a", "--activity-index",
help="path to activity index json file",
required=True)
required_named.add_argument("-c", "--chunks",
help="path to chunks json file",
required=True)
arg_parser.add_argument("-n", "--nb-videos-per-chunk",
help="number of videos in a chunk")
required_named.add_argument("-v", "--video-location", help="path to videos content", required=True)
required_named.add_argument("-s", "--system-cache-dir", help="path to system cache directory", required=True)
arg_parser.add_argument("-C", "--config-file", help="path to config file")
required_named.add_argument("-v", "--video-location",
help="path to videos content",
required=True)
required_named.add_argument("-s", "--system-cache-dir",
help="path to system cache directory",
required=True)
arg_parser.add_argument("-C", "--config-file",
help="path to config file")
required_named.add_argument("-o", "--output-file", help="path to merge chunks command result", required=True)
required_named.add_argument("-r", "--chunks-result", help="path to chunks json file after merge chunks execution", required=True)
required_named.add_argument("-o", "--output-file",
help="path to merge chunks command result",
required=True)
required_named.add_argument("-r", "--chunks-result",
help="path to chunks json file after "
"merge chunks execution",
required=True)
arg_parser.set_defaults(func=ActevExec.command, object=self)
......@@ -3,13 +3,15 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
import logging
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.src.entry_points.actev_experiment_cleanup import entry_point
from diva_evaluation_cli.src.entry_points.actev_experiment_cleanup import \
entry_point
class ActevExperimentCleanup(ActevCommand):
......@@ -17,19 +19,23 @@ class ActevExperimentCleanup(ActevCommand):
Command args:
* system-cache-dir or s: path to system cache directory
"""
def __init__(self):
super(ActevExperimentCleanup, self).__init__('experiment-cleanup', entry_point)
super(ActevExperimentCleanup, self).__init__(
'experiment-cleanup', entry_point)
def cli_parser(self, arg_parser):
"""Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how
to parse the command
"""
arg_parser.description = "Close any servers, terminates cluster, etc."
arg_parser.add_argument("-s", "--system-cache-dir", help="path to system cache directory")
arg_parser.set_defaults(func=ActevExperimentCleanup.command, object=self)
arg_parser.add_argument("-s", "--system-cache-dir",
help="path to system cache directory")
arg_parser.set_defaults(func=ActevExperimentCleanup.command,
object=self)
......@@ -3,14 +3,18 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
import logging
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.entry_points.actev_experiment_init import before_entry_point
from diva_evaluation_cli.src.entry_points.actev_experiment_init import entry_point
from diva_evaluation_cli.bin.private_src.entry_points.actev_experiment_init \
import before_entry_point
from diva_evaluation_cli.src.entry_points.actev_experiment_init import \
entry_point
class ActevExperimentInit(ActevCommand):
"""Start servers, starts cluster, etc.
......@@ -22,25 +26,41 @@ class ActevExperimentInit(ActevCommand):
* video-location or v: path to videos content
* system-cache-dir or s: path to system cache directory
* config-file or C: path to config file
"""
def __init__(self):
super(ActevExperimentInit, self).__init__('experiment-init', entry_point, before_entry_point=before_entry_point)
super(ActevExperimentInit, self).__init__(
'experiment-init', entry_point,
before_entry_point=before_entry_point)
def cli_parser(self, arg_parser):
"""Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how
to parse the command
"""
arg_parser.description= "Start servers, starts cluster, etc."
required_named = arg_parser.add_argument_group('required named arguments')
required_named.add_argument("-f", "--file-index", help="path to file index json file", required=True)
required_named.add_argument("-a", "--activity-index", help="path to activity index json file", required=True)
required_named.add_argument("-c", "--chunks", help="path to chunks json file", required=True)
required_named.add_argument("-v", "--video-location", help="path to videos content", required=True)
required_named.add_argument("-s", "--system-cache-dir", help="path to system cache directory", required=True)
arg_parser.add_argument("-C", "--config-file", help="path to config file")
arg_parser.description = "Start servers, starts cluster, etc."
required_named = arg_parser.add_argument_group(
'required named arguments')
required_named.add_argument("-f", "--file-index",
help="path to file index json file",
required=True)
required_named.add_argument("-a", "--activity-index",
help="path to activity index json file",
required=True)
required_named.add_argument("-c", "--chunks",
help="path to chunks json file",
required=True)
required_named.add_argument("-v", "--video-location",
help="path to videos content",
required=True)
required_named.add_argument("-s", "--system-cache-dir",
help="path to system cache directory",
required=True)
arg_parser.add_argument("-C", "--config-file",
help="path to config file")
arg_parser.set_defaults(func=ActevExperimentInit.command, object=self)
......@@ -3,14 +3,18 @@
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified: see src/entry_points to add your
source code.
"""
import logging
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.entry_points.actev_get_system import entry_point
from diva_evaluation_cli.bin.private_src.implementation.get_system.system_types_definition import system_types
from diva_evaluation_cli.bin.private_src.entry_points.actev_get_system import \
entry_point
from diva_evaluation_cli.bin.private_src.implementation.get_system.\
system_types_definition import system_types
class ActevGetSystem(ActevCommand):
"""Downloads a credentialed, web-accessible content into src
......@@ -27,22 +31,31 @@ class ActevGetSystem(ActevCommand):
super(ActevGetSystem, self).__init__('get-system', entry_point)
def cli_parser(self, arg_parser):
"""Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and
optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to
parse the command
"""
arg_parser.description= "Downloads a credentialed, web-accessible content into src"
sub_parser_system_types = arg_parser.add_subparsers(title='subsubcommands', dest='system_type')
for system_type_name in system_types.keys():
sub_parser_system_type = sub_parser_system_types.add_parser(system_type_name)
required_named = sub_parser_system_type.add_argument_group('required named arguments')
arg_parser.description = "Downloads a credentialed, web-accessible " \
"content into src"
required_named.add_argument("-u", "--url", help="url to get the system", required=True)
command = system_types[system_type_name]().cli_parser(sub_parser_system_type)
sub_parser_system_type.set_defaults