aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2014-03-26 12:24:33 +0000
committerBryn M. Reeves <bmr@redhat.com>2014-03-26 12:24:33 +0000
commit6b3b56ee17e14a0f0de8a16a6a52b3708d01146b (patch)
tree5fda2d209cdec297e5014823e2bdab03e1f521af
parente708041c050245bf05a7205e6661f8402e8e6a66 (diff)
downloadsos-6b3b56ee17e14a0f0de8a16a6a52b3708d01146b.tar.gz
Dead code removal: DirTree
The DirTree class has remained unused since it was implemented. Remove the definition and associated test cases. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/utilities.py89
-rw-r--r--tests/utilities_tests.py11
2 files changed, 1 insertions, 99 deletions
diff --git a/sos/utilities.py b/sos/utilities.py
index a9aca74b..8602a529 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -185,95 +185,6 @@ def shell_out(cmd):
Does not handle exceptions."""
return sos_get_command_output(cmd)[1]
-class DirTree(object):
- """Builds an ascii representation of a directory structure"""
-
- def __init__(self, top_directory):
- self.directory_count = 0
- self.file_count = 0
- self.buffer = []
- self.top_directory = top_directory
- self._build_tree()
-
- def buf(self, s):
- self.buffer.append(s)
-
- def printtree(self):
- print (six.u(self))
-
- def as_string(self):
- return self.__str__()
-
- def __str__(self):
- return "\n".join(self.buffer)
-
- def _build_tree(self):
- self.buf(os.path.abspath(self.top_directory))
- self.tree_i(self.top_directory, first=True)
-
- def _get_user(self, stats):
- try:
- import pwd
- return pwd.getpwuid(stats.st_uid)[0]
- except:
- return six.u(stats.st_uid)
-
- def _get_group(self, stats):
- try:
- import grp
- return grp.getgrgid(stats.st_gid)[0]
- except:
- return six.u(stats.st_uid)
-
- def _format(self, path):
- """Conditionally adds detail to paths"""
- stats = os.stat(path)
- details = {
- "filename": os.path.basename(path),
- "user": self._get_user(stats),
- "group": self._get_group(stats),
- "filesize": convert_bytes(stats.st_size),
- }
- return ("[%(user)s %(group)s %(filesize)s] " % details, "%(filename)s" % details)
-
- def tree_i(self, dir_, padding='', first=False, fmt="%-30s %s%s%s"):
- if not first:
- details, filename = self._format(os.path.abspath(dir_))
- line = fmt % (details, padding[:-1], "+-- ", filename)
- self.buf(line)
- padding += ' '
-
- count = 0
- files = os.listdir(dir_)
- files.sort(key=str.lower)
- for f in files:
- count += 1
- path = os.path.join(dir_, f)
-
- if f.startswith("."):
- pass
- elif os.path.isfile(path):
- self.file_count += 1
- details, filename = self._format(path)
- line = fmt % (details, padding, "+-- ", filename)
- self.buf(line)
- elif os.path.islink(path):
- self.buf(padding +
- '+-- ' +
- f +
- ' -> ' + os.path.basename(os.path.realpath(path)))
- if os.path.isdir(path):
- self.directory_count += 1
- else:
- self.file_count += 1
- elif os.path.isdir(path):
- self.directory_count += 1
- if count == len(files):
- self.tree_i(path, padding + ' ')
- else:
- self.tree_i(path, padding + '|')
-
-
class ImporterHelper(object):
"""Provides a list of modules that can be imported in a package.
Importable modules are located along the module __path__ list and modules
diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py
index 04c52412..da0987ff 100644
--- a/tests/utilities_tests.py
+++ b/tests/utilities_tests.py
@@ -5,7 +5,7 @@ import unittest
import six
from six import StringIO
-from sos.utilities import grep, DirTree, checksum, get_hash_name, is_executable, sos_get_command_output, find, tail, shell_out
+from sos.utilities import grep, checksum, get_hash_name, is_executable, sos_get_command_output, find, tail, shell_out
import sos
TEST_DIR = os.path.dirname(__file__)
@@ -43,15 +43,6 @@ class TailTest(unittest.TestCase):
self.assertEquals(t, six.b(expected))
-class DirTreeTest(unittest.TestCase):
-
- def test_makes_tree(self):
- # I'll admit, this a pretty lame test, but it will at least sniff out
- # some syntax issues
- t = DirTree(os.path.dirname(sos.__file__)).as_string()
- self.assertTrue('sos' in t)
-
-
class ChecksumTest(unittest.TestCase):
def test_simple_hash(self):