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