Commit cc5d2493 authored by Alexandre Boyer's avatar Alexandre Boyer
Browse files

Add get-system validate-system and exec, required named args

parent 0b6208aa
......@@ -52,6 +52,110 @@ Get the existing commands
actev -h
```
Get system
-------------
```
actev get-system -h
```
### Docker
Generic command:
```
actev get-system docker -u <docker image url>
```
With username and password:
```
actev get-system docker -u <docker image url> -U <username> -p <password>
```
:warning: if your password starts with *-* as in this example: `-9r45ijFo0`, you should write `--password=-9r45ijFo0` instead of `-p -9r45ijFo0`. Otherwise, the value will be interpreted as an argument to parse.
Example:
```
actev get-system docker -u gitlab.kitware.com:4567/diva-baseline/diva-baseline:eval_cli
```
### Git
Generic command:
```
actev get-system git -u <git repository>
```
With username and password:
```
actev get-system git -u <git repository url> -U <username> -p <password>
```
With a token:
```
actev get-system git -u <git repository url> -t <token>
```
Store the system in a specific directory:
```
actev get-system git -u <git repository url> ... -l <location>
```
:information_source: You can also directly add your credentials inside the url.
:warning: if your password or token starts with *-* as in this example: `-9r45ijFo0`, you should write `--password=-9r45ijFo0` instead of `-p -9r45ijFo0`. Otherwise, the value will be interpreted as an argument to parse.
Example:
```
actev get-system git -u https://gitlab.kitware.com/alexandreB/diva_evaluation_cli.git -l /tmp
```
### Other (web resources as a tar file)
Generic command:
```
actev get-system other -u <web resource url>
```
With username and password:
```
actev get-system other -u <web resource url> -U <username> -p <password>
```
With a token:
```
actev get-system git -u <web resource url> -t <token>
```
Store the system in a specific directory:
```
actev get-system git -u <web resource url> ... -l <location>
```
:information_source: You can also directly add your credentials inside the url.
:warning: if your password or token starts with *-* as in this example: `-9r45ijFo0`, you should write `--password=-9r45ijFo0` instead of `-p -9r45ijFo0`. Otherwise, the value will be interpreted as an argument to parse.
Example:
```
actev get-system other -u https://path/to/file.tgz -l /tmp
```
System setup
------------
......
......@@ -33,4 +33,5 @@ class ActevCommand():
logging.info("%s done" % self.command)
except:
logging.exception("Issue during %s" % self.command)
raise
"""
USAGE
ActEV exec
Description
-----------
Calls a team-implemented API. Captures time stamps, resource usage, etc.
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
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
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
from diva_evaluation_cli.bin.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.private_entry_points.actev_exec import entry_point
class ActevExec(ActevCommand):
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.
@param arg_parser: 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')
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("-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)
......@@ -9,16 +9,18 @@ Downloads a credentialed, web-accessible content into src
Args
----
url or u: url to get the system
user or U: username to access the url
password or p: password to access the url
token or t: token to access the url
location or l: path to store the system
user or U: username to access the url
password or p: password to access the url
token or t: token to access the url
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
from diva_evaluation_cli.bin.actev_command import ActevCommand
from diva_evaluation_cli.src.entry_points.actev_experiment_init import entry_point
from diva_evaluation_cli.bin.private_src.private_entry_points.actev_get_system import entry_point
from diva_evaluation_cli.bin.private_src.system_types.system_types_definition import system_types
class ActevGetSystem(ActevCommand):
......@@ -28,13 +30,18 @@ class ActevGetSystem(ActevCommand):
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
@param arg_parser: python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a credentialed, web-accessible content into src"
required_named = arg_parser.add_argument_group('required named arguments')
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')
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(func=ActevGetSystem.command, object=self)
required_named.add_argument("-u", "--url", help="url to get the system", required=True)
arg_parser.add_argument("-U", "--user", help="username to access the url")
arg_parser.add_argument("-p", "--password", help="password to access the url")
arg_parser.add_argument("-t", "--token", help="token to access the url")
arg_parser.set_defaults(func=ActevGetSystem.command, object=self)
"""
USAGE
ActEV validate-system
Description
-----------
Checks the structure of the directory after ActEV-system-setup is run. Checks for expected API contents, etc.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
from diva_evaluation_cli.bin.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.private_entry_points.actev_validate_system import entry_point
class ActevValidateSystem(ActevCommand):
def __init__(self):
super(ActevValidateSystem, self).__init__('validate-system', entry_point)
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description = "Checks the structure of the directory after ActEV-system-setup is run"
arg_parser.set_defaults(func=ActevValidateSystem.command, object=self)
......@@ -21,7 +21,9 @@ import logging
import argparse
import sys
from diva_evaluation_cli.bin.actev_get_system import ActevGetSystem
from diva_evaluation_cli.bin.actev_system_setup import ActevSystemSetup
from diva_evaluation_cli.bin.actev_validate_system import ActevValidateSystem
from diva_evaluation_cli.bin.actev_design_chunks import ActevDesignChunks
from diva_evaluation_cli.bin.actev_experiment_init import ActevExperimentInit
from diva_evaluation_cli.bin.actev_pre_process_chunk import ActevPreProcessChunk
......@@ -30,8 +32,16 @@ from diva_evaluation_cli.bin.actev_post_process_chunk import ActevPostProcessChu
from diva_evaluation_cli.bin.actev_reset_chunk import ActevResetChunk
from diva_evaluation_cli.bin.actev_experiment_cleanup import ActevExperimentCleanup
from diva_evaluation_cli.bin.actev_merge_chunks import ActevMergeChunks
from diva_evaluation_cli.bin.actev_exec import ActevExec
subcommands = [
private_subcommands = [
ActevGetSystem(),
ActevValidateSystem(),
ActevExec()
]
public_subcommands = [
ActevSystemSetup(),
ActevDesignChunks(),
ActevExperimentInit(),
......@@ -40,7 +50,7 @@ ActevProcessChunk(),
ActevPostProcessChunk(),
ActevResetChunk(),
ActevMergeChunks(),
ActevExperimentCleanup()
ActevExperimentCleanup(),
]
def cli_parser():
......@@ -56,6 +66,7 @@ def cli_parser():
subs = parser.add_subparsers(title='subcommands')
subparsers = {}
subcommands = private_subcommands + public_subcommands
# Initialize subparsers
for subcommand in subcommands:
subparser = subs.add_parser(subcommand.command)
......
#!/bin/bash
cd "$(dirname "$0")"
file_index=$1
activity_index=$2
chunks=$3
number_of_videos=$4
video_location=$5
system_cache_dir=$6
config=$7
output=$8
chunks_result=$9
tmp_file="chunk_ids.tmp"
actev design-chunks -f $file_index -a $activity_index -o $chunks -n $number_of_videos
actev experiment-init -f $file_index -a $activity_index -c $chunks -v $video_location -s $system_cache_dir
# Get chunks
python3 get_chunks_ids.py $chunks $tmp_file
for chunk_id in $(cat $tmp_file); do
actev pre-process-chunk -i $chunk_id
actev process-chunk -i $chunk_id
actev post-process-chunk -i $chunk_id
actev reset-chunk -i $chunk_id
done
rm $tmp_file
actev merge-chunks -o $output -c $chunks_result -r $system_cache_dir
actev experiment-cleanup
"""
SOURCE
"""
import json
import sys
def get_chunks_ids(chunk_file, output):
""" Get chunk ids from a chunk json file
"""
chunk_ids = []
chunks = json.load(open(chunk_file, 'r'))
with open(output, "w") as f:
for chunk_id in chunks:
f.write(chunk_id + "\n")
if __name__ == '__main__':
if len(sys.argv) == 3:
get_chunks_ids(sys.argv[1], sys.argv[2])
"""
ENTRY POINT
This file should not be modified.
"""
import os
def entry_point(file_index, activity_index, chunks, nb_videos_per_chunk,
video_location, system_cache_dir, output_file, chunks_result, config_file=None):
""" Private entry points.
"""
if not nb_videos_per_chunk:
nb_video_per_chunk = 96
if not config_file:
config_file = "None"
# go into the right directory to execute the script
path = os.path.dirname(__file__)
script = os.path.join(path, '../exec/exec.sh')
script += " " + file_index + \
" " + activity_index + \
" " + chunks + \
" " + nb_videos_per_chunk + \
" " + video_location + \
" " + system_cache_dir + \
" " + config_file + \
" " + output_file + \
" " + chunks_result
# execute the script
# status is the exit status code returned by the program
status = os.system(script)
if status != 0:
raise Exception("Error occured in exec.sh")
"""
ENTRY POINT
This file should not be modified.
"""
import os
from diva_evaluation_cli.bin.private_src.system_types.system_types_definition import system_types
def entry_point(url, system_type, location="None", user="None", password="None", token="None"):
""" Private entry points.
"""
try:
command = system_types[system_type]()
script = command.entry_point
except:
raise Exception("Unknown system type")
if not location:
location = "None"
if not user:
user = "None"
if not password:
password = "None"
if not token:
token = "None"
# go into the right directory to execute the script
path = os.path.dirname(__file__)
script = os.path.join(path, '../system_types/get/' + script)
script += " " + url + \
" " + location + \
" " + user + \
" " + password + \
" " + token
# execute the script
# status is the exit status code returned by the program
status = os.system(script)
if status != 0:
raise Exception("Error occured in exec.sh")
"""
ENTRY POINT
This file should not be modified.
"""
import os
from diva_evaluation_cli.bin.private_src.validation.validate_system import validate_system
def entry_point():
""" Private entry points.
"""
validate_system()
"""
USAGE
ActEV get-system docker
Description
-----------
Downloads a docker image
Args
----
user or U: url to get the system
password or p: password to access the url
Warning: this file should not be modified.
"""
from diva_evaluation_cli.bin.actev_command import ActevCommand
class ActevGetSystemDocker(ActevCommand):
def __init__(self):
super(ActevGetSystemDocker, self).__init__('docker', "get_docker.sh")
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a docker image"
required_named = arg_parser.add_argument_group('required named arguments')
arg_parser.add_argument("-U", "--user", help="username to access the url")
arg_parser.add_argument("-p", "--password", help="password to access the url")
"""
USAGE
ActEV get-system git
Description
-----------
Clones a git repository
Args
----
location or l: path to store the system
user or U: url to get the system
password or p: password to access the url
token or t: token to access the url
Warning: this file should not be modified.
"""
from diva_evaluation_cli.bin.actev_command import ActevCommand
class ActevGetSystemGit(ActevCommand):
def __init__(self):
super(ActevGetSystemGit, self).__init__('git', "get_git.sh")
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a git repository"
required_named = arg_parser.add_argument_group('required named arguments')
arg_parser.add_argument("-U", "--user", help="username to access the url")
arg_parser.add_argument("-p", "--password", help="password to access the url")
arg_parser.add_argument("-l", "--location", help="path to store the system")
arg_parser.add_argument("-t", "--token", help="token to access the url", type=str)
"""
USAGE
ActEV get-system other
Description
-----------
Downloads a web resources as a tar file
Args
----
location or l: path to store the system
user or U: url to get the system
password or p: password to access the url
token or t: token to access the url
Warning: this file should not be modified.
"""
from diva_evaluation_cli.bin.actev_command import ActevCommand
class ActevGetSystemOther(ActevCommand):
def __init__(self):
super(ActevGetSystemOther, self).__init__('other', "get_other.sh")
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a web resources as a tar file"
required_named = arg_parser.add_argument_group('required named arguments')
arg_parser.add_argument("-U", "--user", help="username to access the url")
arg_parser.add_argument("-p", "--password", help="password to access the url")
arg_parser.add_argument("-l", "--location", help="path to store the system")
arg_parser.add_argument("-t", "--token", help="token to access the url")
#!/bin/bash
url=$1
location=$2
user=$3
password=$4
token=$5
if [ $user != "None" ] && [ $password != "None" ];then
docker login --username $user --password $password
fi
docker pull $url
#!/bin/bash
url=$1
location=$2
user=$3
password=$4
token=$5
if [ $user != "None" ];then
if [ $password != "None" ]; then
credentials="${user}:${password}@"
else
if [ $token != "None" ];then
credentials="${user}:${token}@"
else
credentials=""
fi
fi
http=`echo $url | cut -d '/' -f1`