Commit 48a8702b authored by Alexandre Boyer's avatar Alexandre Boyer
Browse files

WIP add get-system command

parent 49f3445d
......@@ -8,10 +8,12 @@ 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
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
token or t: token to access the url
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
......@@ -19,6 +21,7 @@ import logging
from diva_evaluation_cli.bin.actev_command import ActevCommand
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,12 +31,17 @@ 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
"""
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")
......
......@@ -21,6 +21,7 @@ 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_design_chunks import ActevDesignChunks
from diva_evaluation_cli.bin.actev_experiment_init import ActevExperimentInit
......@@ -33,6 +34,7 @@ from diva_evaluation_cli.bin.actev_merge_chunks import ActevMergeChunks
from diva_evaluation_cli.bin.actev_exec import ActevExec
subcommands = [
ActevGetSystem(),
ActevSystemSetup(),
ActevDesignChunks(),
ActevExperimentInit(),
......
......@@ -4,21 +4,25 @@ ENTRY POINT
This file should not be modified.
"""
import os
system_types = {
'docker': 'get_docker.sh',
'git': 'get_git.sh',
'other': 'get_other.sh'
}
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):
""" Private entry points.
"""
try:
script = systems_types[system_type]
script = system_types[system_type]
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/' + script)
......@@ -26,8 +30,8 @@ def entry_point(url, system_type, location, user, password, token):
" " + location + \
" " + user + \
" " + password + \
" " + token + \
" " + token
# execute the script
# status is the exit status code returned by the program
status = os.system(script)
......
......@@ -6,7 +6,7 @@ user=$3
password=$4
token=$5
if [ $user != "None" ] && [ $password != "None"];then
if [ $user != "None" ] && [ $password != "None" ];then
docker login --username $user --password $password
fi
docker pull $url
......@@ -6,17 +6,25 @@ user=$3
password=$4
token=$5
if [ $user != "None" ] && [ [ $password != "None"] || [ $token != "None" ] ];then
if [ $password == "None" ]; then
credentials="${user}:${password}"
if [ $user != "None" ];then
if [ $password != "None" ]; then
credentials="${user}:${password}@"
else
credentials="${user}:${token}"
if [ $token != "None" ];then
credentials="${user}:${token}@"
else
credentials=""
fi
fi
http=`echo $url | cut -d '/' -f1`
git=`echo $url | cut -d '/' -f3`
end=`echo $url | cut -d '/' -f4-`
url="${http}//${credentials}${git}/${end}"
fi
url="${http}//${credentials}@${git}/${end}"
if [ $location != "None" ];then
cd $location
fi
git clone $url
......@@ -6,13 +6,21 @@ user=$3
password=$4
token=$5
if [ $user != "None" ] && [ $password != "None"];then
curl -u $user:$password $url
if [ $location != "None" ];then
cd $location
fi
if [ $token != "None" ]; then
curl "Authorization: Bearer $token" $url
else
if [ $user != "None" ] && [ $password == "None"];then
curl -u $user $url
if [ $user != "None" ] && [ $password != "None"];then
curl -u $user:$password $url
else
curl $url
if [ $user != "None" ] && [ $password == "None"];then
curl -u $user $url
else
curl $url
fi
fi
fi
"""
SOURCE
Dictionary of system types:
key: name of the system type
value: script to download the system
"""
system_types = {
'docker': 'get_docker.sh',
'git': 'get_git.sh',
'other': 'get_other.sh'
}
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