mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Add Workspace.write_script().
This commit is contained in:
parent
9f88f6fefd
commit
ac7b58e6d8
1 changed files with 18 additions and 0 deletions
|
|
@ -42,6 +42,9 @@ class Workspace(object):
|
|||
def write(self, *path, **kwargs):
|
||||
return self._write(path, **kwargs)
|
||||
|
||||
def write_script(self, *path, **kwargs):
|
||||
return self._write_script(path, **kwargs)
|
||||
|
||||
def lockfile(self, filename, timeout=1.0):
|
||||
_timeout = timeout
|
||||
filename = self.resolve(filename)
|
||||
|
|
@ -57,6 +60,8 @@ class Workspace(object):
|
|||
warnings.warn('timed out')
|
||||
return filename, wait
|
||||
|
||||
# internal methods
|
||||
|
||||
def _write(self, path, content='', fixup=True):
|
||||
if fixup:
|
||||
content = dedent(content)
|
||||
|
|
@ -65,6 +70,17 @@ class Workspace(object):
|
|||
outfile.write(content)
|
||||
return filename
|
||||
|
||||
def _write_script(self, path, executable, mode='0755', content='',
|
||||
fixup=True):
|
||||
if isinstance(mode, str):
|
||||
mode = int(mode, base=8)
|
||||
if fixup:
|
||||
content = dedent(content)
|
||||
content = '#!/usr/bin/env {}\n'.format(executable) + content
|
||||
filename = self._write(path, content, fixup=False)
|
||||
os.chmod(filename, mode)
|
||||
return filename
|
||||
|
||||
|
||||
class PathEntry(Workspace):
|
||||
|
||||
|
|
@ -103,6 +119,8 @@ class PathEntry(Workspace):
|
|||
filename = os.path.join(dirname, filename)
|
||||
return self.write(filename, content=content)
|
||||
|
||||
# internal methods
|
||||
|
||||
def _ensure_package(self, name, root=None):
|
||||
parent, sep, name = name.rpartition('.')
|
||||
if sep:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue