Add a shell wrapper for simplify the life of users

This commit is contained in:
Julien Duponchelle 2015-05-22 12:10:29 +02:00
parent 3175e72da9
commit 68fcefdc38
4 changed files with 60 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
__pycache__
*.pyc
.venv

View File

@ -4,21 +4,21 @@ GNS3-registry
This is the GNS3 devices registry.
You need python 3.4
You need python 3.4 installed
Add an image
************
.. code:: bash
python3.4 gns3registry/main.py --add ~/Downloads/linux-microcore-3.4.1.img
bin/gns3-get --add ~/Downloads/linux-microcore-3.4.1.img
Search an image
****************
.. code:: bash
python3.4 gns3registry/main.py --search core
bin/gns3-get --search core
Micro Core Linux:
* 3.4.1 linux-microcore-3.4.1.img: 5f42d71b30bc682e44ccf7340e20ea7ea8967ef5
@ -32,6 +32,6 @@ If the image is available from the internet you can download and install it:
.. code:: bash
python3.4 gns3registry/main.py --install 0252f2c913519c993b812325bbd553af2d77218a
bin/gns3-get --install 0252f2c913519c993b812325bbd553af2d77218a
Download http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/linux-microcore-4.0.2-clean.img to /Users/noplay/GNS3/images/linux-microcore-4.0.2-clean.img

44
bin/gns3-get Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
SCRIPT_PATH="${BASH_SOURCE[0]}";
GNS3_REPOSITORY_DIR=`dirname ${SCRIPT_PATH}`/..
# Detect Python 3.4 installation
PY34_TEST="import sys; sys.exit(1) if sys.version_info[0] != 3 or sys.version_info[1] < 4 else sys.exit(0)"
if python -c "$PY34_TEST" 2> /dev/null
then
PYTHON="python"
elif python3 -c "$PY34_TEST" 2> /dev/null
then
PYTHON="python3"
elif python3.4 -c "$PY34_TEST" 2> /dev/null
then
PYTHON="python3.4"
elif python34 -c "$PY34_TEST" 2> /dev/null
then
PYTHON="python34"
else
echo "No Python 3.4 installation"
echo "On debian based distribution":
echo "apt-get install python3"
echo "On MacOSX:"
echo "brew install python3"
echo "port install python34"
exit 1
fi
$PYTHON -m venv $GNS3_REPOSITORY_DIR/.venv
source $GNS3_REPOSITORY_DIR/.venv/bin/activate
$PYTHON $GNS3_REPOSITORY_DIR/gns3registry/main.py --test
if [ $? -ne 0 ]
then
$PYTHON -m pip install -r $GNS3_REPOSITORY_DIR/requirements.txt
fi
$PYTHON $GNS3_REPOSITORY_DIR/gns3registry/main.py $*

View File

@ -23,10 +23,10 @@ from distutils.util import strtobool
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from gns3registry.registry import Repository
from gns3registry.registry import Registry
from gns3registry.config import Config
registry = Repository()
registry = Registry()
config = Config()
@ -38,6 +38,11 @@ def yes_no(message):
pass
def add_image(image):
print("WARNING WARNING WARNING")
print("It's experimental")
print("Please close the GUI before using it")
print("")
confs = registry.detect_image(image)
if len(confs) > 0:
print("Found: {} devices configuration".format(len(confs)))
@ -55,13 +60,13 @@ if __name__ == "__main__":
help="Search an image for GNS3")
parser.add_argument("--install", dest="install", action="store",
help="Download and install an image for GNS3")
parser.add_argument("--test", dest="test", action="store_true",
help="Test if installation of gns3 registry is OK")
args = parser.parse_args()
print("WARNING WARNING WARNING")
print("It's experimental")
print("Please close the GUI before using it")
print("")
if args.test:
sys.exit(0)
if args.add_image:
add_image(args.add_image)