예제 #1
0
 def test_is_broken_false(self):
   tmp1 = tempfile.NamedTemporaryFile()
   tmp2 = tempfile.NamedTemporaryFile()
   file_util.remove(tmp1.name)
   os.symlink(tmp2.name, tmp1.name)
   self.assertEqual( True, path.islink(tmp1.name) )
   self.assertEqual( False, file_symlink.is_broken(tmp1.name) )
    def _cleanup_usr_local_links(self):
        'Cleanup symlinks in /usr/local/bin that break after uninstalling python'

        links = dir_util.list('/usr/local/bin')
        broken_links = [l for l in links if file_symlink.is_broken(l)]
        for broken_link in broken_links:
            target = os.readlink(broken_link)
            if 'Library/Frameworks/Python.framework/Versions' in target:
                self.blurb_verbose(
                    'Removing broken /usr/local link: {}'.format(broken_link))
                file_util.remove(broken_link)
예제 #3
0
 def _find_all_exes(clazz, sanitize_path=True):
     'Return all the executables in PATH and other platform specific places'
     if not sanitize_path in clazz._all_exes_cache:
         exe_patterns = python_source.possible_python_exe_patterns()
         extra_path = python_source.possible_python_bin_dirs()
         env_path = os_env_var('PATH').path + extra_path
         if sanitize_path:
             sanitized_env_path = clazz._sanitize_env_path(env_path)
         else:
             sanitized_env_path = env_path
         result = file_path.glob(sanitized_env_path, exe_patterns)
         result = [f for f in result if not file_symlink.is_broken(f)]
         clazz._log.log_d('      exe_patterns={}'.format(exe_patterns))
         clazz._log.log_d('          env_path={}'.format(env_path))
         clazz._log.log_d('        extra_path={}'.format(extra_path))
         clazz._log.log_d(
             'sanitized_env_path={}'.format(sanitized_env_path))
         clazz._log.log_d('            result={}'.format(result))
         clazz._all_exes_cache[sanitize_path] = sorted(
             result,
             key=lambda exe: semantic_version(str(clazz.version(exe))
                                              )._tokens,
             reverse=True)
     return clazz._all_exes_cache[sanitize_path]
 def _remove_broken_symlink(self, link):
     if file_symlink.is_broken(link):
         self.blurb_verbose(
             'Removing broken framework link: {}'.format(link))
         file_util.remove(link)
예제 #5
0
 def is_broken_link(self):
   return file_symlink.is_broken(self.filename)
예제 #6
0
 def test_is_broken_true(self):
   tmp = tempfile.NamedTemporaryFile()
   file_util.remove(tmp.name)
   os.symlink('/somethingnotthere', tmp.name)
   self.assertEqual( True, path.islink(tmp.name) )
   self.assertEqual( True, file_symlink.is_broken(tmp.name) )