Decorator to set the specified working directory to execute the function, and then restore the previous cwd.
961163
def set_cwd(fn):
        
        def wrapped(self, *args, **kwargs):
            log.info('Calling function: %s with args=%s', fn, args if args else [])
            cwd = os.getcwd()
            log.info('Saved cwd: %s', cwd)
            os.chdir(self._cwd)
            log.info('Changing working directory to: %s', self._cwd)
            try:
                return fn(self, *args, **kwargs)
            finally:
                os.chdir(cwd)
                log.info('Restored working directory to: %s', cwd)

        return wrapped
1063091
def chdir(method):
    
    def wrapper(self, dir, *args, **kw):
        dirstack = ChdirStack()
        dirstack.push(dir)
        try:
            return method(self, dir, *args, **kw)
        finally:
            dirstack.pop()

    return functools.wraps(method)(wrapper)
338034
def call(command, working_directory=config.BASE_DIR):
    
    LOG.info(command)
    proc = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE, cwd=working_directory, shell=True)
    out, err = proc.communicate()
    return (out, err)
46726
def set_working_directory(working_directory):
    
    logger.debug("starting")

    logger.debug(f"adding {working_directory} to sys.paths")
    sys.path.append(working_directory)

    logger.debug("done")
497009
def set_save_directory(base, source):
    
    root = os.path.join(base, source)
    if not os.path.isdir(root):
        os.makedirs(root)

    world.screenshot_root = root
280868
def set_recovery_range(working_dir, start_block, end_block):
    
    recovery_range_path = os.path.join(working_dir, '.recovery')
    with open(recovery_range_path, 'w') as f:
        f.write('{}\n{}\n'.format(start_block, end_block))
        f.flush()
        os.fsync(f.fileno())
35984
def performInDirectory(dirPath):
    
    originalDirectoryPath = os.getcwd()
    try:
        os.chdir(dirPath)
        yield
    finally:
        os.chdir(originalDirectoryPath)
1097332
def mkdir(path, recursive=True, **kwargs):
    """"""
    import os
    if recursive:
        os.makedirs(path, **kwargs)
    else:
        os.mkdir(path, **kwargs)
179018
def from_dir(cwd):
    ""
    import os
    curdir = os.getcwd()
    try:
        os.chdir(cwd)
        yield
    finally:
        os.chdir(curdir)
671616
def chdir(new_dir):
    
    cur_dir = os.getcwd()
    _mkdir(new_dir)
    os.chdir(new_dir)
    try:
        yield
    finally:
        os.chdir(cur_dir)
1263376
def cd(*args):
    
    if args[0] == "-":
        try:
            newpwd, os.environ["OLDPWD"] = os.environ["OLDPWD"], os.getcwd()
        except KeyError as e:  # $OLDPWD initially not set
            raise e
        else:
            os.chdir(newpwd)
            print(newpwd)
    else:
        os.environ["OLDPWD"] = os.getcwd()
        os.chdir(*args)
755634
def disk_cache(cls, basename, function, *args, method=True, **kwargs):
        
        @utility.disk_cache(basename, cls.directory(), method=method)
        def wrapper(*args, **kwargs):
            return function(*args, **kwargs)

        return wrapper(*args, **kwargs)
998675
def reset_directory(directory):
    
    if os.path.isdir(directory): shutil.rmtree(directory)
    if not os.path.isdir(directory): os.makedirs(directory)
1071892
def set_workdir(self, workdir, chroot=False):
        
        if not chroot and hasattr(self, "workdir") and self.workdir != workdir:
            raise ValueError("self.workdir != workdir: %s, %s" % (self.workdir,  workdir))

        # Directories with (input|output|temporary) data.
        self.workdir = os.path.abspath(workdir)
        self.indir = Directory(os.path.join(self.workdir, "indata"))
        self.outdir = Directory(os.path.join(self.workdir, "outdata"))
        self.tmpdir = Directory(os.path.join(self.workdir, "tmpdata"))
        self.wdir = Directory(self.workdir)
832049
def set_working_directory(self, dirname):
        
        if dirname:
            self.main.workingdirectory.chdir(dirname, refresh_explorer=True,
                                             refresh_console=False)
1094726
def cd(path):
    ''''''
    old_dir = os.getcwd()
    try:
        os.makedirs(path)
    except OSError:
        pass
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(old_dir)
1152435
function(options){
        if (!options) {
            options = {
                cwd: workingDirectory
            };

            return options;
        } else {
            workingDirectory = options.cwd;
            return options;
        }
    }