コード例 #1
0
 def test_isfile_strict(self):
     this_file = os.path.abspath(__file__)
     assert isfile_strict(this_file)
     assert not isfile_strict(os.path.dirname(this_file))
     with mock.patch('psutil._common.os.stat',
                     side_effect=OSError(errno.EPERM, "foo")):
         self.assertRaises(OSError, isfile_strict, this_file)
     with mock.patch('psutil._common.os.stat',
                     side_effect=OSError(errno.EACCES, "foo")):
         self.assertRaises(OSError, isfile_strict, this_file)
     with mock.patch('psutil._common.os.stat',
                     side_effect=OSError(errno.ENOENT, "foo")):
         assert not isfile_strict(this_file)
     with mock.patch('psutil._common.stat.S_ISREG', return_value=False):
         assert not isfile_strict(this_file)
コード例 #2
0
 def open_files(self):
     retlist = []
     files = os.listdir("/proc/%s/fd" % self.pid)
     hit_enoent = False
     for fd in files:
         file = "/proc/%s/fd/%s" % (self.pid, fd)
         try:
             file = os.readlink(file)
         except OSError as err:
             # ENOENT == file which is gone in the meantime
             if err.errno in (errno.ENOENT, errno.ESRCH):
                 hit_enoent = True
                 continue
             elif err.errno == errno.EINVAL:
                 # not a link
                 continue
             else:
                 raise
         else:
             # If file is not an absolute path there's no way
             # to tell whether it's a regular file or not,
             # so we skip it. A regular file is always supposed
             # to be absolutized though.
             if file.startswith('/') and isfile_strict(file):
                 ntuple = _common.popenfile(file, int(fd))
                 retlist.append(ntuple)
     if hit_enoent:
         # raise NSP if the process disappeared on us
         os.stat('/proc/%s' % self.pid)
     return retlist
コード例 #3
0
ファイル: test_misc.py プロジェクト: nicolargo/psutil
 def test_isfile_strict(self):
     from psutil._common import isfile_strict
     this_file = os.path.abspath(__file__)
     assert isfile_strict(this_file)
     assert not isfile_strict(os.path.dirname(this_file))
     with mock.patch('psutil._common.os.stat',
                     side_effect=OSError(errno.EPERM, "foo")):
         self.assertRaises(OSError, isfile_strict, this_file)
     with mock.patch('psutil._common.os.stat',
                     side_effect=OSError(errno.EACCES, "foo")):
         self.assertRaises(OSError, isfile_strict, this_file)
     with mock.patch('psutil._common.os.stat',
                     side_effect=OSError(errno.EINVAL, "foo")):
         assert not isfile_strict(this_file)
     with mock.patch('psutil._common.stat.S_ISREG', return_value=False):
         assert not isfile_strict(this_file)
コード例 #4
0
ファイル: _pslinux.py プロジェクト: trizinix/psutil
 def open_files(self):
     retlist = []
     files = os.listdir("/proc/%s/fd" % self.pid)
     hit_enoent = False
     for fd in files:
         file = "/proc/%s/fd/%s" % (self.pid, fd)
         if os.path.islink(file):
             try:
                 file = os.readlink(file)
             except OSError:
                 # ENOENT == file which is gone in the meantime
                 err = sys.exc_info()[1]
                 if err.errno == errno.ENOENT:
                     hit_enoent = True
                     continue
                 raise
             else:
                 # If file is not an absolute path there's no way
                 # to tell whether it's a regular file or not,
                 # so we skip it. A regular file is always supposed
                 # to be absolutized though.
                 if file.startswith('/') and isfile_strict(file):
                     ntuple = _common.popenfile(file, int(fd))
                     retlist.append(ntuple)
     if hit_enoent:
         # raise NSP if the process disappeared on us
         os.stat('/proc/%s' % self.pid)
     return retlist
コード例 #5
0
ファイル: _psosx.py プロジェクト: mx739150/ambari-app
 def open_files(self):
     if self.pid == 0:
         return []
     files = []
     rawlist = cext.proc_open_files(self.pid)
     for path, fd in rawlist:
         if isfile_strict(path):
             ntuple = _common.popenfile(path, fd)
             files.append(ntuple)
     return files
コード例 #6
0
ファイル: _psosx.py プロジェクト: dangpu/momoko
 def open_files(self):
     if self.pid == 0:
         return []
     files = []
     rawlist = cext.proc_open_files(self.pid)
     for path, fd in rawlist:
         if isfile_strict(path):
             ntuple = _common.popenfile(path, fd)
             files.append(ntuple)
     return files
コード例 #7
0
 def open_files(self):
     if self.pid in (0, 4):
         return []
     retlist = []
     # Filenames come in in native format like:
     # "\Device\HarddiskVolume1\Windows\systemew\file.txt"
     # Convert the first part in the corresponding drive letter
     # (e.g. "C:\") by using Windows's QueryDosDevice()
     raw_file_names = cext.proc_open_files(self.pid)
     for file in raw_file_names:
         file = _convert_raw_path(file)
         if isfile_strict(file) and file not in retlist:
             ntuple = _common.popenfile(file, -1)
             retlist.append(ntuple)
     return retlist
コード例 #8
0
ファイル: _pswindows.py プロジェクト: dangpu/momoko
 def open_files(self):
     if self.pid in (0, 4):
         return []
     retlist = []
     # Filenames come in in native format like:
     # "\Device\HarddiskVolume1\Windows\systemew\file.txt"
     # Convert the first part in the corresponding drive letter
     # (e.g. "C:\") by using Windows's QueryDosDevice()
     raw_file_names = cext.proc_open_files(self.pid)
     for file in raw_file_names:
         file = _convert_raw_path(file)
         if isfile_strict(file) and file not in retlist:
             ntuple = _common.popenfile(file, -1)
             retlist.append(ntuple)
     return retlist
コード例 #9
0
ファイル: _pssunos.py プロジェクト: 2089764/psutil
 def open_files(self):
     retlist = []
     hit_enoent = False
     pathdir = '/proc/%d/path' % self.pid
     for fd in os.listdir('/proc/%d/fd' % self.pid):
         path = os.path.join(pathdir, fd)
         if os.path.islink(path):
             try:
                 file = os.readlink(path)
             except OSError as err:
                 # ENOENT == file which is gone in the meantime
                 if err.errno == errno.ENOENT:
                     hit_enoent = True
                     continue
                 raise
             else:
                 if isfile_strict(file):
                     retlist.append(_common.popenfile(file, int(fd)))
     if hit_enoent:
         # raise NSP if the process disappeared on us
         os.stat('/proc/%s' % self.pid)
     return retlist
コード例 #10
0
 def open_files(self, ret, info):
     self.assertIsInstance(ret, list)
     for f in ret:
         self.assertIsInstance(f.fd, int)
         self.assertIsInstance(f.path, str)
         if WINDOWS:
             self.assertEqual(f.fd, -1)
         elif LINUX:
             self.assertIsInstance(f.position, int)
             self.assertIsInstance(f.mode, str)
             self.assertIsInstance(f.flags, int)
             self.assertGreaterEqual(f.position, 0)
             self.assertIn(f.mode, ('r', 'w', 'a', 'r+', 'a+'))
             self.assertGreater(f.flags, 0)
         elif BSD and not f.path:
             # XXX see: https://github.com/giampaolo/psutil/issues/595
             continue
         assert os.path.isabs(f.path), f
         try:
             assert isfile_strict(f.path), f
         except FileNotFoundError:
             pass
コード例 #11
0
ファイル: _pssunos.py プロジェクト: aizhan00000/parser
 def open_files(self):
     retlist = []
     hit_enoent = False
     pathdir = '/proc/%d/path' % self.pid
     for fd in os.listdir('/proc/%d/fd' % self.pid):
         path = os.path.join(pathdir, fd)
         if os.path.islink(path):
             try:
                 file = os.readlink(path)
             except OSError as err:
                 # ENOENT == file which is gone in the meantime
                 if err.errno == errno.ENOENT:
                     hit_enoent = True
                     continue
                 raise
             else:
                 if isfile_strict(file):
                     retlist.append(_common.popenfile(file, int(fd)))
     if hit_enoent:
         # raise NSP if the process disappeared on us
         os.stat('/proc/%s' % self.pid)
     return retlist