Set a location by default

This commit is contained in:
Julien Duponchelle
2015-01-23 17:39:17 +01:00
parent 7bed9f56bc
commit 8e249b670d
4 changed files with 52 additions and 2 deletions

View File

@ -44,11 +44,11 @@ class Project:
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(uuid))
self._uuid = uuid
config = Config.instance().get_section_config("Server")
self._location = location
if location is None:
self._location = tempfile.mkdtemp()
self._location = config.get("project_directory", self._get_default_project_directory())
else:
config = Config.instance().get_section_config("Server")
if config.get("local", False) is False:
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
@ -61,6 +61,19 @@ class Project:
except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
def _get_default_project_directory(self):
"""
Return the default location for the project directory
depending of the operating system
"""
path = os.path.normpath(os.path.expanduser("~/GNS3/projects"))
try:
os.makedirs(path, exist_ok=True)
except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
return path
@property
def uuid(self):