summaryrefslogtreecommitdiff
path: root/silx/resources/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/resources/__init__.py')
-rw-r--r--silx/resources/__init__.py45
1 files changed, 14 insertions, 31 deletions
diff --git a/silx/resources/__init__.py b/silx/resources/__init__.py
index 250aed1..a45457a 100644
--- a/silx/resources/__init__.py
+++ b/silx/resources/__init__.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -56,7 +56,7 @@ of this modules to ensure access across different distribution schemes:
__authors__ = ["V.A. Sole", "Thomas Vincent", "J. Kieffer"]
__license__ = "MIT"
-__date__ = "06/09/2017"
+__date__ = "15/02/2018"
import os
@@ -162,7 +162,7 @@ def list_dir(resource):
:param str resource: Name of the resource directory to list
:return: list of name contained in the directory
- :rtype: list
+ :rtype: List
"""
resource_directory, resource_name = _get_package_and_resource(resource)
@@ -194,6 +194,16 @@ def is_dir(resource):
return os.path.isdir(path)
+def exists(resource):
+ """True is the resource exists.
+
+ :param str resource: Name of the resource
+ :rtype: bool
+ """
+ path = resource_filename(resource)
+ return os.path.exists(path)
+
+
def _get_package_and_resource(resource, default_directory=None):
"""
Return the resource directory class and a cleaned resource name without
@@ -301,7 +311,6 @@ class ExternalResources(object):
"""
self.project = project
self._initialized = False
- self._tempdir = None
self.sem = threading.Semaphore()
self.env_key = env_key or (self.project.upper() + "_DATA")
self.url_base = url_base
@@ -309,14 +318,6 @@ class ExternalResources(object):
self.timeout = timeout
self.data_home = None
- def _initialize_tmpdir(self):
- """Initialize the temporary directory"""
- if not self._tempdir:
- with self.sem:
- if not self._tempdir:
- self._tempdir = tempfile.mkdtemp("_" + getpass.getuser(),
- self.project + "_")
-
def _initialize_data(self):
"""Initialize for downloading test data"""
if not self._initialized:
@@ -335,26 +336,8 @@ class ExternalResources(object):
self.all_data = set(json.load(f))
self._initialized = True
- @property
- def tempdir(self):
- if not self._tempdir:
- self._initialize_tmpdir()
- return self._tempdir
-
def clean_up(self):
- """Removes the temporary directory (and all its content !)"""
- with self.sem:
- if not self._tempdir:
- return
- if not os.path.isdir(self._tempdir):
- return
- for root, dirs, files in os.walk(self._tempdir, topdown=False):
- for name in files:
- os.remove(os.path.join(root, name))
- for name in dirs:
- os.rmdir(os.path.join(root, name))
- os.rmdir(self._tempdir)
- self._tempdir = None
+ pass
def getfile(self, filename):
"""Downloads the requested file from web-server available