コード例 #1
0
ファイル: test_filesystem.py プロジェクト: Earth4/socorro
  def testVisitPath(self):
    f.makedirs('TestDir/a/b/c/d/e/f')
    fi = open('TestDir/a/b/c/d/D0','w')
    fi.write("hi\n")
    fi.close
    seen = set()
    def collector(x):
      seen.add(x)
    top = 'TestDir/a'
    last = 'TestDir/a/b/c/d'
    absTop = os.path.normpath(top)
    expected = set([absTop])
    for i in [['b'],['b','c'],['b','c','d']]:
      expected.add(os.path.join(absTop,os.sep.join(i)))
    f.visitPath(top,last,collector)
    assert expected == seen, 'but x-s=%s and s-x=%s'%(expected-seen,seen-expected)

    seen.clear()
    top = 'TestDir/a/b'
    last = 'TestDir/a/b/c/d/D0'
    normTop = os.path.normpath(top)
    expected = set([normTop])
    for i in [['c'],['c','d']]:
      expected.add(os.path.join(normTop,os.sep.join(i)))
    f.visitPath(top,last,collector)
    assert expected == seen, 'but x-s=%s and s-x=%s'%(expected-seen,seen-expected)

    #Test for non-existent leaf
    assert_raises(OSError,f.visitPath,'TestDir','TestDir/A/BB',collector)

    #Test for rootDir not abover fullPath
    assert_raises(OSError,f.visitPath,'TestDir/A/B','TestDir/A',collector)
コード例 #2
0
ファイル: dump_storage.py プロジェクト: rhelmer/socorro-lib
 def makeNameDir(self, ooid, timestamp=None):
     """Make sure the name directory exists, and return its path, and list
     of path components. Raises OSError on failure"""
     npath, nparts = self.namePath(ooid, timestamp)
     #self.logger.debug(
     #  "%s - trying makedirs %s",
     #  threading.currentThread().getName(),
     #  npath
     #)
     um = self.osModule.umask(0)
     try:
         try:
             socorro_fs.makedirs(npath, self.dirPermissions, self.osModule)
         except OSError:
             if not self.osModule.path.isdir(npath):
                 raise
     finally:
         self.osModule.umask(um)
     if self.dumpGID:
         socorro_fs.visitPath(
           os.path.join(*nparts[:2]),
           npath,
           self.chownGidVisitor
         )
     return npath, nparts
コード例 #3
0
  def testVisitPath(self):
    f.makedirs('TestDir/a/b/c/d/e/f')
    fi = open('TestDir/a/b/c/d/D0','w')
    fi.write("hi\n")
    fi.close
    seen = set()
    def collector(x):
      seen.add(x)
    top = 'TestDir/a'
    last = 'TestDir/a/b/c/d'
    absTop = os.path.normpath(top)
    expected = set([absTop])
    for i in [['b'],['b','c'],['b','c','d']]:
      expected.add(os.path.join(absTop,os.sep.join(i)))
    f.visitPath(top,last,collector)
    assert expected == seen, 'but x-s=%s and s-x=%s'%(expected-seen,seen-expected)

    seen.clear()
    top = 'TestDir/a/b'
    last = 'TestDir/a/b/c/d/D0'
    normTop = os.path.normpath(top)
    expected = set([normTop])
    for i in [['c'],['c','d']]:
      expected.add(os.path.join(normTop,os.sep.join(i)))
    f.visitPath(top,last,collector)
    assert expected == seen, 'but x-s=%s and s-x=%s'%(expected-seen,seen-expected)

    #Test for non-existent leaf
    assert_raises(OSError,f.visitPath,'TestDir','TestDir/A/BB',collector)

    #Test for rootDir not abover fullPath
    assert_raises(OSError,f.visitPath,'TestDir/A/B','TestDir/A',collector)
コード例 #4
0
ファイル: dump_storage.py プロジェクト: Meghashyamt/socorro
 def makeDateDir(self, date, webheadName=None):
     """Assure existence of date directory for the given date, return path,
     and list of components"""
     dpath, dparts = self.datePath(date, webheadName)
     um = self.osModule.umask(0)
     try:
         try:
             socorro_fs.makedirs(dpath, self.dirPermissions, self.osModule)
         except OSError, e:
             if not self.osModule.path.isdir(dpath):
                 #self.logger.debug(
                 #  "%s - in makeDateDir, got not isdir(%s): %s",
                 #  threading.currentThread().getName(),
                 #  dpath,
                 #  e
                 #)
                 raise
     finally:
         self.osModule.umask(um)
     if self.dumpGID:
         socorro_fs.visitPath(
           os.path.join(*dparts[:2]),
           dpath,
           self.chownGidVisitor
         )
     return dpath, dparts
コード例 #5
0
ファイル: dump_storage.py プロジェクト: rhelmer/socorro-lib
 def makeDateDir(self, date, webheadName=None):
     """Assure existence of date directory for the given date, return path,
     and list of components"""
     dpath, dparts = self.datePath(date, webheadName)
     um = self.osModule.umask(0)
     try:
         try:
             socorro_fs.makedirs(dpath, self.dirPermissions, self.osModule)
         except OSError:
             if not self.osModule.path.isdir(dpath):
                 raise
     finally:
         self.osModule.umask(um)
     if self.dumpGID:
         socorro_fs.visitPath(
           os.path.join(*dparts[:2]),
           dpath,
           self.chownGidVisitor
         )
     return dpath, dparts
コード例 #6
0
ファイル: test_filesystem.py プロジェクト: Earth4/socorro
 def testFailMakedirsOnFileInPath(self):
   path = 'TestDir/1/2/3/4'
   tpath = path
   while True:
     head,tail = os.path.split(tpath)
     if tail == 'TestDir': break
     try:
       shutil.rmtree('TestDir')
     except:
       pass
     f.makedirs(head)
     t = open(tpath,'w')
     t.write('nothing\n')
     t.close()
     try:
       f.makedirs(path)
       assert False, 'We should have had an OSError, but success for %s a file'%tpath
     except OSError:
       pass
     except Exception,x:
       assert False, 'We should have had an OSError, got %s: %s'%(type(x),x)
     tpath = head
コード例 #7
0
 def testFailMakedirsOnFileInPath(self):
   path = 'TestDir/1/2/3/4'
   tpath = path
   while True:
     head,tail = os.path.split(tpath)
     if tail == 'TestDir': break
     try:
       shutil.rmtree('TestDir')
     except:
       pass
     f.makedirs(head)
     t = open(tpath,'w')
     t.write('nothing\n')
     t.close()
     try:
       f.makedirs(path)
       assert False, 'We should have had an OSError, but success for %s a file'%tpath
     except OSError:
       pass
     except Exception,x:
       assert False, 'We should have had an OSError, got %s: %s'%(type(x),x)
     tpath = head
コード例 #8
0
ファイル: dump_storage.py プロジェクト: zenmind101/socorro
 def makeDateDir(self, date, webheadName=None):
     """Assure existence of date directory for the given date, return path,
     and list of components"""
     dpath, dparts = self.datePath(date, webheadName)
     um = self.osModule.umask(0)
     try:
         try:
             socorro_fs.makedirs(dpath, self.dirPermissions, self.osModule)
         except OSError, e:
             if not self.osModule.path.isdir(dpath):
                 #self.logger.debug(
                 #  "%s - in makeDateDir, got not isdir(%s): %s",
                 #  threading.currentThread().getName(),
                 #  dpath,
                 #  e
                 #)
                 raise
     finally:
         self.osModule.umask(um)
     if self.dumpGID:
         socorro_fs.visitPath(os.path.join(*dparts[:2]), dpath,
                              self.chownGidVisitor)
     return dpath, dparts
コード例 #9
0
    def testCleanEmptySubdirectories(self):
        f.makedirs('TestDir/A/B/C/D')
        f.makedirs('TestDir/AA/BB/C')
        f.makedirs('TestDir/AA/BB/CC/DD')
        fi = open('TestDir/A/a', 'w')
        fi.write('file a\n')
        fi.close()
        # Test short-circuit path, full stopper
        assert os.path.isdir('TestDir/A/B/C/D')
        f.cleanEmptySubdirectories('TestDir/A/B/C/D', 'TestDir/A/B/C/D')
        assert os.path.isdir('TestDir/A/B/C/D')
        # Test short-circuit path, name stopper
        f.cleanEmptySubdirectories('D', 'TestDir/A/B/C/D')
        assert os.path.isdir('TestDir/A/B/C/D')

        # Test some empties, name stopper
        f.cleanEmptySubdirectories('C', 'TestDir/A/B/C/D')
        assert not os.path.exists('TestDir/A/B/C/D')
        assert os.path.isdir('TestDir/A/B/C')
        # Test some empties, path stopper
        f.cleanEmptySubdirectories('TestDir/A/B', 'TestDir/A/B/C')
        assert not os.path.exists('TestDir/A/B/C')
        assert os.path.isdir('TestDir/A/B')

        #Test stopping on a file in a subdir
        f.cleanEmptySubdirectories('TestDir', 'TestDir/A/B')
        assert not os.path.exists('TestDir/A/B')
        assert os.path.isdir('TestDir/A')

        #Test stopping on another subdir
        f.cleanEmptySubdirectories('TestDir/AA', 'TestDir/AA/BB/CC/DD')
        assert not os.path.exists('TestDir/AA/BB/CC')
        assert os.path.isdir('TestDir/AA/BB')

        #Test for stopper not in path
        assert_raises(OSError, f.cleanEmptySubdirectories, 'Woo',
                      'TestDir/AA/BB')

        #Test for non-existent leaf
        assert_raises(OSError, f.cleanEmptySubdirectories, 'TestDir',
                      'TestDir/AA/BB/CC/DD')
コード例 #10
0
ファイル: test_filesystem.py プロジェクト: Earth4/socorro
  def testCleanEmptySubdirectories(self):
    f.makedirs('TestDir/A/B/C/D')
    f.makedirs('TestDir/AA/BB/C')
    f.makedirs('TestDir/AA/BB/CC/DD')
    fi = open('TestDir/A/a','w')
    fi.write('file a\n')
    fi.close()
    # Test short-circuit path, full stopper
    assert os.path.isdir('TestDir/A/B/C/D')
    f.cleanEmptySubdirectories('TestDir/A/B/C/D','TestDir/A/B/C/D')
    assert os.path.isdir('TestDir/A/B/C/D')
    # Test short-circuit path, name stopper
    f.cleanEmptySubdirectories('D','TestDir/A/B/C/D')
    assert os.path.isdir('TestDir/A/B/C/D')

    # Test some empties, name stopper
    f.cleanEmptySubdirectories('C','TestDir/A/B/C/D')
    assert not os.path.exists('TestDir/A/B/C/D')
    assert os.path.isdir('TestDir/A/B/C')
    # Test some empties, path stopper
    f.cleanEmptySubdirectories('TestDir/A/B','TestDir/A/B/C')
    assert not os.path.exists('TestDir/A/B/C')
    assert os.path.isdir('TestDir/A/B')

    #Test stopping on a file in a subdir
    f.cleanEmptySubdirectories('TestDir','TestDir/A/B')
    assert not os.path.exists('TestDir/A/B')
    assert os.path.isdir('TestDir/A')

    #Test stopping on another subdir
    f.cleanEmptySubdirectories('TestDir/AA','TestDir/AA/BB/CC/DD')
    assert not os.path.exists('TestDir/AA/BB/CC')
    assert os.path.isdir('TestDir/AA/BB')

    #Test for stopper not in path
    assert_raises(OSError,f.cleanEmptySubdirectories,'Woo','TestDir/AA/BB')

    #Test for non-existent leaf
    assert_raises(OSError,f.cleanEmptySubdirectories,'TestDir','TestDir/AA/BB/CC/DD')