Bobby R. Bruce has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/51369 )
Change subject: python: Set a default resource dir to download to
......................................................................
python: Set a default resource dir to download to
Prior to this patch the downloader would download resources to the
user's pwd unless explictly stated otherwise. This patch checks the
environment variable `GEM5_RESOURCE_DIR` for a resource directory and if
this is not set, it will default to `~/.cache/gem5`.
Change-Id: I672479a37342d2a97e8ac6404775f3fd969b07b8
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/51369
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/python/gem5/resources/resource.py
1 file changed, 46 insertions(+), 6 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/python/gem5/resources/resource.py
b/src/python/gem5/resources/resource.py
index 4e7a459..bf83e0a 100644
--- a/src/python/gem5/resources/resource.py
+++ b/src/python/gem5/resources/resource.py
@@ -26,6 +26,7 @@
from abc import ABCMeta
import os
+from pathlib import Path
from .downloader import get_resource
@@ -89,21 +90,42 @@
"""
:param resource_name: The name of the gem5 resource.
:param resource_directory: The location of the directory in which
the
- resource is to be stored.
+ resource is to be stored. If this parameter is not set, it will
set to
+ the environment variable `GEM5_RESOURCE_DIR`. If the environment
is not
+ set it will default to `~/.cache/gem5`.
:param override: If the resource is present, but does not have the
correct md5 value, the resoruce will be deleted and re-downloaded
if
this value is True. Otherwise an exception will be thrown. False by
default.
"""
- if resource_directory != None:
- if not os.path.exists(resource_directory):
- os.makedirs(resource_directory)
- to_path = os.path.join(resource_directory, resource_name)
+ if resource_directory == None:
+ resource_directory = os.getenv(
+ "GEM5_RESOURCE_DIR", self._get_default_resource_dir()
+ )
+
+ if os.path.exists(resource_directory):
+ if not os.path.isdir(resource_directory):
+ raise Exception(
+ "gem5 resource directory, "
+ "'{}', exists but is not a directory".format(
+ resource_directory
+ )
+ )
else:
- to_path = resource_name
+ os.makedirs(resource_directory)
+
+ to_path = os.path.join(resource_directory, resource_name)
super(Resource, self).__init__(local_path=to_path)
get_resource(
resource_name=resource_name, to_path=to_path, override=override
)
+
+ def _get_default_resource_dir(cls) -> str:
+ """
+ Obtain the default gem5 resources directory on the host system.
+
+ :returns: The default gem5 resources directory.
+ """
+ return os.path.join(Path.home(), ".cache", "gem5")
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/51369
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I672479a37342d2a97e8ac6404775f3fd969b07b8
Gerrit-Change-Number: 51369
Gerrit-PatchSet: 6
Gerrit-Owner: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s