Ejemplo n.º 1
0
def test_is_nonsymlink_exe_with_shebang(tmpdir):
    with tmpdir.as_cwd():
        # Create an executable with shebang.
        with open('executable_script', 'wb') as f:
            f.write(b'#!/interpreter')
        os.chmod('executable_script', 0o100775)

        with open('executable_but_not_script', 'wb') as f:
            f.write(b'#/not-a-shebang')
        os.chmod('executable_but_not_script', 0o100775)

        with open('not_executable_with_shebang', 'wb') as f:
            f.write(b'#!/interpreter')
        os.chmod('not_executable_with_shebang', 0o100664)

        os.symlink('executable_script', 'symlink_to_executable_script')

        assert fs.is_nonsymlink_exe_with_shebang('executable_script')
        assert not fs.is_nonsymlink_exe_with_shebang('executable_but_not_script')
        assert not fs.is_nonsymlink_exe_with_shebang('not_executable_with_shebang')
        assert not fs.is_nonsymlink_exe_with_shebang('symlink_to_executable_script')
Ejemplo n.º 2
0
 def add_files_to_view(self, view, merge_map, skip_if_exists=True):
     bin_dir = self.spec.prefix.bin
     python_prefix = self.extendee_spec.prefix
     python_is_external = self.extendee_spec.external
     global_view = same_path(python_prefix,
                             view.get_projection_for_spec(self.spec))
     for src, dst in merge_map.items():
         if os.path.exists(dst):
             continue
         elif global_view or not path_contains_subdirectory(src, bin_dir):
             view.link(src, dst)
         elif not os.path.islink(src):
             shutil.copy2(src, dst)
             is_script = is_nonsymlink_exe_with_shebang(src)
             if is_script and not python_is_external:
                 filter_file(
                     python_prefix,
                     os.path.abspath(view.get_projection_for_spec(
                         self.spec)), dst)
         else:
             orig_link_target = os.path.realpath(src)
             new_link_target = os.path.abspath(merge_map[orig_link_target])
             view.link(new_link_target, dst)