Commit 6f70b319 authored by Alexandre Boyer's avatar Alexandre Boyer
Browse files

add get-system

parent 48a8702b
......@@ -9,7 +9,6 @@ Downloads a credentialed, web-accessible content into src
Args
----
url or u: url to get the system
s or system-type: type of the system to download
location or l: path to store the system
user or U: username to access the url
password or p: password to access the url
......@@ -33,16 +32,16 @@ class ActevGetSystem(ActevCommand):
@param arg_parser: python arg parser to describe how to parse the command
"""
system_type_choices = list(system_types.keys())
help_system_types = ','.join(system_type_choices)
arg_parser.description= "Downloads a credentialed, web-accessible content into src"
required_named = arg_parser.add_argument_group('required named arguments')
required_named.add_argument("-u", "--url", help="url to get the system", required=True)
required_named.add_argument("-s", "--system-type", help="type of the system to download: %s" % help_system_types, required=True)
arg_parser.add_argument("-l", "--location", help="path to store the system")
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)
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)
......@@ -6,14 +6,15 @@ 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, user, password, token):
def entry_point(url, system_type, location="None", user="None", password="None", token="None"):
""" Private entry points.
"""
try:
script = system_types[system_type]
command = system_types[system_type]()
script = command.entry_point
except:
raise Exception("Unknown system type")
raise Exception("Unknown system type")
if not location:
location = "None"
if not user:
......@@ -25,7 +26,7 @@ def entry_point(url, system_type, location, user, password, token):
# go into the right directory to execute the script
path = os.path.dirname(__file__)
script = os.path.join(path, '../system_types/' + script)
script = os.path.join(path, '../system_types/get/' + script)
script += " " + url + \
" " + location + \
" " + user + \
......
"""
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")
......@@ -13,10 +13,10 @@ fi
if [ $token != "None" ]; then
curl "Authorization: Bearer $token" $url
else
if [ $user != "None" ] && [ $password != "None"];then
if [ $user != "None" ] && [ $password != "None" ];then
curl -u $user:$password $url
else
if [ $user != "None" ] && [ $password == "None"];then
if [ $user != "None" ] && [ $password == "None" ];then
curl -u $user $url
else
curl $url
......
......@@ -3,12 +3,17 @@ SOURCE
Dictionary of system types:
key: name of the system type
value: script to download the system
value: command to download the system
"""
from diva_evaluation_cli.bin.private_src.system_types.commands.docker_command import ActevGetSystemDocker
from diva_evaluation_cli.bin.private_src.system_types.commands.git_command import ActevGetSystemGit
from diva_evaluation_cli.bin.private_src.system_types.commands.other_command import ActevGetSystemOther
system_types = {
'docker': 'get_docker.sh',
'git': 'get_git.sh',
'other': 'get_other.sh'
'docker': ActevGetSystemDocker,
'git': ActevGetSystemGit,
'other': ActevGetSystemOther
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment