Bobby R. Bruce has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/51369 )

Change subject: python: Set `~/.cache/gem5` as the default resource dir
......................................................................

python: Set `~/.cache/gem5` as the default resource dir

Prior to this patch the downloader would download resources to the
user's pwd. This patch sets the default download location to
`~/.cache/gem5`. The directory is created if it does not already exist.

The user may specify another directory to download to via the `Resouce`
class's constructor.

Change-Id: I672479a37342d2a97e8ac6404775f3fd969b07b8
---
M src/python/gem5/resources/resource.py
1 file changed, 38 insertions(+), 6 deletions(-)



diff --git a/src/python/gem5/resources/resource.py b/src/python/gem5/resources/resource.py
index 4e7a459..691180e 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,36 @@
         """
         :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 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 = 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: 1
Gerrit-Owner: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to