From 157bc18ebd1df53d5d2d44d5e7c9541a231ccf49 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 13 May 2015 14:29:03 +0200 Subject: [PATCH] Use a temporary directory as egg cache We have use with broken permission on their system. We try to workaround the issue. Fix #182 --- gns3server/main.py | 10 ++++++++ gns3server/utils/get_resource.py | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 gns3server/utils/get_resource.py diff --git a/gns3server/main.py b/gns3server/main.py index 30360876..e0bf9af2 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -16,6 +16,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +# WARNING +# Due to buggy user machines we choose to put this as the first loading modules +# otherwise the egg cache is initialized in his standard location and +# if is not writetable the application crash. It's the user fault +# because one day the user as used sudo to run an egg and break his +# filesystem permissions, but it's a common mistake. +import gns3server.utils.get_resource + + import os import datetime import sys diff --git a/gns3server/utils/get_resource.py b/gns3server/utils/get_resource.py new file mode 100644 index 00000000..f28152ab --- /dev/null +++ b/gns3server/utils/get_resource.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015 GNS3 Technologies Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import tempfile +import pkg_resources +import atexit +import logging + +log = logging.getLogger(__name__) + +try: + egg_cache_dir = tempfile.mkdtemp() + pkg_resources.set_extraction_path(dir) +except ValueError: + # If the path is already set the module throw an error + pass + + +@atexit.register +def clean_egg_cache(): + try: + import shutil + log.debug("Clean egg cache %s", egg_cache_dir) + shutil.rmtree(egg_cache_dir) + except Exception: + # We don't care if we can not cleanup + pass