Miscellaneous operating system functions

sage.misc.sage_ostools.have_program(program, path=None)

Return True if a program executable is found in the path given by path.

INPUT:

  • program - a string, the name of the program to check.
  • path - string or None. Paths to search for program, separated by os.pathsep. If None, use the PATH environment variable.

OUTPUT: bool

EXAMPLES:

sage: from sage.misc.sage_ostools import have_program
sage: have_program('ls')
True
sage: have_program('there_is_not_a_program_with_this_name')
False
sage: have_program('ls', path=SAGE_ROOT)
False
sage.misc.sage_ostools.restore_cwd(*args, **kwds)

Context manager that restores the original working directory upon exiting.

INPUT:

  • chdir – optionally change directories to the given directory upon entering the context manager

EXAMPLES:

sage: import os sage: from sage.misc.sage_ostools import restore_cwd sage: from sage.misc.misc import SAGE_TMP sage: cwd = os.getcwd() sage: with restore_cwd(str(SAGE_TMP)): ….: print(os.getcwd() == SAGE_TMP) True sage: cwd == os.getcwd() True