Commit 77c68864 authored by Baptiste CHOCOT's avatar Baptiste CHOCOT Committed by Jonathan Fiscus
Browse files

Development

parent 5da80293
MAKE=make
check:
@(echo "** Running UnitTests **\n")
(python3 -m unittest discover test)
\ No newline at end of file
......@@ -18,6 +18,7 @@ class ActevGetSystemGit(ActevCommand):
* token or t: token to access the url
* install-cli or i: install the cli to use it
* name or n: name to give to the system once it is downloaded
* sha or s: commit SHA or tag to checkout
"""
def __init__(self):
super(ActevGetSystemGit, self).__init__('git', "get_git.sh")
......@@ -40,5 +41,6 @@ class ActevGetSystemGit(ActevCommand):
type=str)
arg_parser.add_argument("-i", "--install-cli", help="install the cli to use it", action='store_true')
arg_parser.add_argument("-n", "--name", help="name to give to the system once it is downloaded")
arg_parser.add_argument("-s", "--sha", help="commit SHA or tag to checkout once the repository has been cloned")
......@@ -8,7 +8,7 @@ from diva_evaluation_cli.bin.private_src.implementation.utils.actev_cli_environm
from diva_evaluation_cli.bin.private_src.implementation.get_system.system_types_definition import system_types
def entry_point(url, system_type, location=None, user=None, password=None, token=None, install_cli=False, name=False):
def entry_point(url, system_type, location=None, user=None, password=None, token=None, install_cli=False, sha=None, name=False):
"""Private entry point.
Downloads a credentialed, web-accessible content into src
......@@ -20,6 +20,7 @@ def entry_point(url, system_type, location=None, user=None, password=None, token
password (str, optional): Password to access the url
token (str, optional): Token to access the url
install_cli (bool, optional): Information to know wether CLI has to be installed
sha (str, optional): commit SHA or tag to checkout after cloning
"""
try:
......@@ -62,8 +63,14 @@ def entry_point(url, system_type, location=None, user=None, password=None, token
install_cli = "True"
else:
install_cli = "False"
# SHA
if not sha:
sha = "None"
if not name:
name = ""
# go into the right directory to execute the script
path = os.path.dirname(__file__)
......@@ -74,6 +81,7 @@ def entry_point(url, system_type, location=None, user=None, password=None, token
" " + password + \
" " + token + \
" " + install_cli + \
" " + sha + \
" " + name
# execute the script
......
......@@ -6,7 +6,8 @@ user=$3
password=$4
token=$5
cli=$6
name=$7
sha=$7
name=$8
# If there are credentials
# Replace '@' by its hexa character to clean the fields to avoid confusion with the '@' delimiter
......@@ -35,10 +36,16 @@ fi
git clone --recursive $url $name
if [ $? -eq 0 ];then
repo_name=`echo $url | rev | cut -d '.' -f2 | rev`
repo_name=`echo $repo_name | rev | cut -d '/' -f1 | rev`
# If sha or tag is specified
if [ $sha != "None" ];then
cd $repo_name
git checkout $sha || exit 1
cd ..
fi
# If the system has to be installed
if [ $cli == "True" ];then
repo_name=`echo $url | rev | cut -d '.' -f2 | rev`
repo_name=`echo $repo_name | rev | cut -d '/' -f1 | rev`
cd $repo_name
diva_evaluation_cli/bin/install.sh
......
......@@ -21,6 +21,7 @@ Clones a git repository
| password | p | False | password to access the url |
| token | t | False | token to access the url |
| name | n | False | name to give to the system |
| sha | s | False | commit SHA or tag to checkout |
### Usage
......@@ -65,6 +66,14 @@ Example:
actev get-system git -u https://gitlab.kitware.com/actev/diva_evaluation_cli.git -l /tmp
```
Switching on a specific commit after cloning:
```
actev get-system git -u <url> -s <commit SHA or tag>
```
:warning: You can also use this feature with tags. However, be careful your project does not have a branch with the same name than your tag, otherwise the checkout will happen on the branch and not the tag. The correct format for tags is `--sha tags/<tag>`.
## get-system archive
### Description
......
# -*- coding: utf-8 -*-
'''
This module implements unit tests of the actev get-system command.
'''
import sys
import os
import shutil
import unittest
import argparse
from diva_evaluation_cli.bin.cli import cli_parser
def _clean_tmp_folder():
try:
shutil.rmtree('tmp')
except Exception as e:
pass
finally:
os.mkdir('tmp')
class TestGetSystemGit(unittest.TestCase):
"""
Test the actev get-system git --sha CLI call, using valid and invalid parameters
"""
def setUp(self):
self.gitURL = "https://gitlab.kitware.com/actev/diva_evaluation_cli.git"
_clean_tmp_folder()
def test_git_subcommand(self):
def _update_argv(args: list):
# Use this to modify CLI parameters
if isinstance(args, str):
args = [args]
sys.argv[1:] = ['get-system', 'git'] + args
##################
# Checking --sha #
##################
args = ['-u',
self.gitURL,
'-l',
'tmp',
'--sha']
# 0. No parameter
_update_argv(args)
with self.assertRaises(SystemExit):
cli_parser()
self.fail('System does not stop on invalid input.')
_clean_tmp_folder()
# 1. Correct tag
_update_argv(args + ['tags/1.0'])
try:
cli_parser()
except Exception:
self.fail('Could not checkout on tag `development`')
_clean_tmp_folder()
# 2. Incorrect tag
_update_argv(args + ['tags/0.1'])
with self.assertRaises(SystemExit):
cli_parser()
self.fail('The system managed to checkout on invalid tag `0.1`')
# 3. Correct SHA
_update_argv(args + ['eb26f205'])
try:
cli_parser()
except Exception:
self.fail('Could not checkout on commit `eb26f205`')
_clean_tmp_folder()
# 4. Incorrect SHA
_update_argv(args + ['abcdefgh'])
with self.assertRaises(SystemExit):
cli_parser()
self.fail('The system managed to checkout on invalid commit `abcdefgh`')
_clean_tmp_folder()
def tearDown(self):
# Clear archive and repository
shutil.rmtree('tmp')
if __name__ == '__main__':
unittest.main()
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