summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan S. Arnold <ryan.arnold@linaro.org>2016-08-17 23:16:19 -0500
committerRyan S. Arnold <ryan.arnold@linaro.org>2016-08-18 16:10:35 -0500
commit4ae6f70a3ff2dccf5f958c4e40d0626fef88fe1f (patch)
treec59004679f21b950ab927846dca611079b07ac66
parent1dc9a5afdc1d10083b4cac5d71ebe0ab8ed38936 (diff)
Remove non-conformant comments and add docstrings to proj.py.
-rw-r--r--linaropy/proj.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/linaropy/proj.py b/linaropy/proj.py
index 819cbe4..26f6d36 100644
--- a/linaropy/proj.py
+++ b/linaropy/proj.py
@@ -6,16 +6,23 @@ import tempfile
# Execute shell commands with the 'sh' package.
from sh import rm
-# TODO: Take an existing directory as an input, which allows the benefits of a
-# Proj without having to create the directory. BUT make sure that
-# persist=True is forced in such cases.
-
-# This class represents the project temporary directory whose lifetime is
-# managed. It is not persistent by default.
class Proj(object):
- # @ persist - True, False or None. Only True persists.
- # @ prefix - Optional prefix appended to projdir directory name.
- def __init__(self, prefix="", persist=None):
+ """
+ Create a project temporary directory in /tmp.
+ """
+ def __init__(self, prefix="", persist=False):
+ """
+ Create a /tmp project dir.
+
+ Parameters
+ ----------
+ prefix : str
+ Optional prefix appended to /tmp projdir directory name.
+
+ persist=False : bool
+ The projdir should persist after the cleanup function is called
+ only if persist=True.
+ """
# This allows string or bool inputs.
if str(persist).lower() == "true":
self.persist=True
@@ -28,19 +35,18 @@ class Proj(object):
logging.info("Created %s project directory in %s" % (longevity, self.projdir))
def cleanup(self):
-
- #FIXME: Only rm -rf if the directory exists. Make sure it's not / or /home
-# #TODO: make sure that persisdir isn't a mount-bind to /home
+ """Perform cleanup (removal) of the proj directory if Proj persist==False."""
if not self.persist and self.projdir != "/" and self.projdir != "/home":
logging.info("Removing project dir %s" % self.projdir)
+ #TODO: Test whether we need to trap an exception if the directory
+ # has already been removed when cleanup is called.
rm("-rf", "--preserve-root", self.projdir)
self.projdir=None
else:
logging.info("Project dir %s will persist" % self.projdir)
-
class TestProj(unittest.TestCase):
-
+ """Test the Proj class."""
def setUp(self):
self.persistdir=""
@@ -110,7 +116,6 @@ class TestProj(unittest.TestCase):
if self.persistdir != "/" and self.persistdir != "/home":
rm("-rf", "--preserve-root", self.persistdir)
-
if __name__ == '__main__':
#logging.basicConfig(level="INFO")
unittest.main()