Revision eedbda4b

b/lib/backend.py
966 966
  for dir in top_dirs:
967 967
    if os.path.isdir(dir):
968 968
      try:
969
        f_names = os.listdir(dir)
969
        f_names = utils.ListVisibleFiles(dir)
970 970
      except EnvironmentError, err:
971 971
        logger.Error("Can't list the OS directory %s: %s" % (dir,str(err)))
972 972
        break
......
1282 1282

  
1283 1283
  """
1284 1284
  if os.path.isdir(constants.EXPORT_DIR):
1285
    return os.listdir(constants.EXPORT_DIR)
1285
    return utils.ListVisibleFiles(constants.EXPORT_DIR)
1286 1286
  else:
1287 1287
    return []
1288 1288

  
......
1392 1392
    subdir = "%s-%s.d" % (hpath, suffix)
1393 1393
    dir_name = "%s/%s" % (self._BASE_DIR, subdir)
1394 1394
    try:
1395
      dir_contents = os.listdir(dir_name)
1395
      dir_contents = utils.ListVisibleFiles(dir_name)
1396 1396
    except OSError, err:
1397 1397
      # must log
1398 1398
      return rr
b/lib/utils.py
848 848
    success = (not live_port_needed) and (errcode == errno.ECONNREFUSED)
849 849

  
850 850
  return success
851

  
852

  
853
def ListVisibleFiles(path):
854
  """Returns a list of all visible files in a directory.
855

  
856
  """
857
  return [i for i in os.listdir(path) if not i.startswith(".")]
b/test/ganeti.utils_unittest.py
28 28
import os.path
29 29
import md5
30 30
import socket
31

  
31
import shutil
32 32

  
33 33
import ganeti
34 34
from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \
35 35
     RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \
36 36
     ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \
37
     ShellQuote, ShellQuoteArgs, _ParseIpOutput, TcpPing
37
     ShellQuote, ShellQuoteArgs, _ParseIpOutput, TcpPing, \
38
     ListVisibleFiles
38 39
from ganeti.errors import LockError, UnitParseError
39 40

  
40 41

  
......
522 523
                 "failed to ping alive host on deaf port")
523 524

  
524 525

  
526
class TestListVisibleFiles(unittest.TestCase):
527
  """Test case for ListVisibleFiles"""
528

  
529
  def setUp(self):
530
    self.path = tempfile.mkdtemp()
531

  
532
  def tearDown(self):
533
    shutil.rmtree(self.path)
534

  
535
  def _test(self, files, expected):
536
    # Sort a copy
537
    expected = expected[:]
538
    expected.sort()
539

  
540
    for name in files:
541
      f = open(os.path.join(self.path, name), 'w')
542
      try:
543
        f.write("Test\n")
544
      finally:
545
        f.close()
546

  
547
    found = ListVisibleFiles(self.path)
548
    found.sort()
549

  
550
    self.assertEqual(found, expected)
551

  
552
  def testAllVisible(self):
553
    files = ["a", "b", "c"]
554
    expected = files
555
    self._test(files, expected)
556

  
557
  def testNoneVisible(self):
558
    files = [".a", ".b", ".c"]
559
    expected = []
560
    self._test(files, expected)
561

  
562
  def testSomeVisible(self):
563
    files = ["a", "b", ".c"]
564
    expected = ["a", "b"]
565
    self._test(files, expected)
566

  
567

  
525 568
if __name__ == '__main__':
526 569
  unittest.main()

Also available in: Unified diff