mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-23 23:38:21 +00:00
Use the user data dir to store built-in appliances
This commit is contained in:
parent
6a614fbd78
commit
df2f96828e
@ -255,6 +255,8 @@ class Controller:
|
||||
if not previous_version or \
|
||||
parse_version(__version__.split("+")[0]) > parse_version(previous_version.split("+")[0]):
|
||||
self._appliance_manager.install_builtin_appliances()
|
||||
elif not os.listdir(self._appliance_manager.builtin_appliances_path()):
|
||||
self._appliance_manager.install_builtin_appliances()
|
||||
|
||||
self._appliance_manager.appliances_etag = controller_settings.get("appliances_etag")
|
||||
self._appliance_manager.load_appliances()
|
||||
|
@ -21,6 +21,7 @@ import uuid
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import shutil
|
||||
import platformdirs
|
||||
|
||||
|
||||
try:
|
||||
@ -81,13 +82,13 @@ class ApplianceManager:
|
||||
os.makedirs(appliances_path, exist_ok=True)
|
||||
return appliances_path
|
||||
|
||||
def _builtin_appliances_path(self, delete_first=False):
|
||||
def builtin_appliances_path(self, delete_first=False):
|
||||
"""
|
||||
Get the built-in appliance storage directory
|
||||
"""
|
||||
|
||||
config = Config.instance()
|
||||
appliances_dir = os.path.join(config.config_dir, "appliances")
|
||||
appname = vendor = "GNS3"
|
||||
appliances_dir = os.path.join(platformdirs.user_data_dir(appname, vendor, roaming=True), "appliances")
|
||||
if delete_first:
|
||||
shutil.rmtree(appliances_dir, ignore_errors=True)
|
||||
os.makedirs(appliances_dir, exist_ok=True)
|
||||
@ -98,7 +99,7 @@ class ApplianceManager:
|
||||
At startup we copy the built-in appliances files.
|
||||
"""
|
||||
|
||||
dst_path = self._builtin_appliances_path(delete_first=True)
|
||||
dst_path = self.builtin_appliances_path(delete_first=True)
|
||||
log.info(f"Installing built-in appliances in '{dst_path}'")
|
||||
from . import Controller
|
||||
try:
|
||||
@ -112,7 +113,7 @@ class ApplianceManager:
|
||||
"""
|
||||
|
||||
self._appliances = {}
|
||||
for directory, builtin in ((self._builtin_appliances_path(), True,), (self._custom_appliances_path(), False,)):
|
||||
for directory, builtin in ((self.builtin_appliances_path(), True,), (self._custom_appliances_path(), False,)):
|
||||
if directory and os.path.isdir(directory):
|
||||
for file in os.listdir(directory):
|
||||
if not file.endswith('.gns3a') and not file.endswith('.gns3appliance'):
|
||||
@ -215,7 +216,7 @@ class ApplianceManager:
|
||||
from . import Controller
|
||||
Controller.instance().save()
|
||||
json_data = await response.json()
|
||||
appliances_dir = self._builtin_appliances_path()
|
||||
appliances_dir = self.builtin_appliances_path()
|
||||
downloaded_appliance_files = []
|
||||
for appliance in json_data:
|
||||
if appliance["type"] == "file":
|
||||
|
@ -11,6 +11,7 @@ psutil==5.9.5
|
||||
async-timeout>=4.0.2,<4.1
|
||||
distro>=1.8.0
|
||||
py-cpuinfo>=9.0.0,<10.0
|
||||
platformdirs>=3.10.0
|
||||
importlib-resources>=1.3; python_version <= '3.9'
|
||||
truststore>=0.7.0; python_version >= '3.10'
|
||||
setuptools>=60.8.1; python_version >= '3.7'
|
||||
|
Loading…
Reference in New Issue
Block a user