Context manager that changes directory and resets it when existing
    
    >>> with change_directory('/tmp'):
    >>>     pass
497240
def change_directory(path=None):
    
    if path is not None:
        try:
            oldpwd = getcwd()
            logger.debug('changing directory from %s to %s' % (oldpwd, path))
            chdir(path)
            yield
        finally:
            chdir(oldpwd)
    else:
        yield
401274
def changed(dirname, filename='.md5', args=None, glob=None):
    
    root = Path(dirname)
    if not root.exists():
        # if dirname doesn't exist it is changed (by definition)
        return True

    cachefile = root / filename
    current_digest = cachefile.open().read() if cachefile.exists() else ""
    
    _digest = digest(dirname, glob=glob)
    if args and args.verbose:  # pragma: nocover
        print("md5:", _digest)
    has_changed = current_digest != _digest

    if has_changed:
        with open(os.path.join(dirname, filename), 'w') as fp:
            fp.write(_digest)

    return has_changed
1200467
def change_dir(directory):
  
  def cd_decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
      org_path = os.getcwd()
      os.chdir(directory)
      func(*args, **kwargs)
      os.chdir(org_path)
    return wrapper
  return cd_decorator
244247
def clean_tempdir(context, scenario):
    
    tempdir = getattr(context, 'tempdir', None)
    if tempdir and scenario.status == 'passed':
        shutil.rmtree(tempdir)
        del(context.tempdir)
351008
function updatePathContext(path, noDeregister) {
  if (path) {
    const allContexts = _getContextsFromPath(path)
    const contextsToAdd = allContexts.add
    let contextsToRemove = _getContextsMatchingRegexPathContexts()
    contextsToRemove = contextsToRemove.concat(allContexts.remove)

    removeContext(contextsToRemove)

    if (!noDeregister) {
      // There's no way to prevent users of genie from adding wishes that already exist in genie
      //   so we're completely removing them here
      deregisterWishesWithContext(contextsToRemove)
    }

    addContext(contextsToAdd)
  }
  return _context
}
213657
def read(self, context, cmd_args):
	
		
		
		try:
			current_dir = os.getcwd()
			os.chdir(context.resolve(self.__config_dir))
			args = []
			args.extend(cmd_args)
			args.append(context.resolve(self.__name))
			yield from super().read(args)
		finally:
			os.chdir(current_dir)
502073
def step_use_curdir_as_working_directory(context):
    
    context.workdir = os.path.abspath(".")
    command_util.ensure_workdir_exists(context)
1016590
def prepend_root_dir(opts, path_options):
    '''
    
    '''
    root_dir = os.path.abspath(opts['root_dir'])
    def_root_dir = salt.syspaths.ROOT_DIR.rstrip(os.sep)
    for path_option in path_options:
        if path_option in opts:
            path = opts[path_option]
            tmp_path_def_root_dir = None
            tmp_path_root_dir = None
            # When running testsuite, salt.syspaths.ROOT_DIR is often empty
            if path == def_root_dir or path.startswith(def_root_dir + os.sep):
                # Remove the default root dir prefix
                tmp_path_def_root_dir = path[len(def_root_dir):]
            if root_dir and (path == root_dir or
                             path.startswith(root_dir + os.sep)):
                # Remove the root dir prefix
                tmp_path_root_dir = path[len(root_dir):]
            if tmp_path_def_root_dir and not tmp_path_root_dir:
                # Just the default root dir matched
                path = tmp_path_def_root_dir
            elif tmp_path_root_dir and not tmp_path_def_root_dir:
                # Just the root dir matched
                path = tmp_path_root_dir
            elif tmp_path_def_root_dir and tmp_path_root_dir:
                # In this case both the default root dir and the override root
                # dir matched; this means that either
                # def_root_dir is a substring of root_dir or vice versa
                # We must choose the most specific path
                if def_root_dir in root_dir:
                    path = tmp_path_root_dir
                else:
                    path = tmp_path_def_root_dir
            elif salt.utils.platform.is_windows() and not os.path.splitdrive(path)[0]:
                # In windows, os.path.isabs resolves '/' to 'C:\\' or whatever
                # the root drive is.  This elif prevents the next from being
                # hit, so that the root_dir is prefixed in cases where the
                # drive is not prefixed on a config option
                pass
            elif os.path.isabs(path):
                # Absolute path (not default or overridden root_dir)
                # No prepending required
                continue
            # Prepending the root dir
            opts[path_option] = salt.utils.path.join(root_dir, path)
1301998
def temp_directory(*args, **kwargs):
    

    path = tempfile.mkdtemp(*args, **kwargs)
    try:
        yield path
    finally:
        shutil.rmtree(path)
1038163
def replace_folder(path):
    """"""
    if os.path.exists(path):
        shutil.rmtree(path)
        os.makedirs(path)
    else:
        os.makedirs(path)
1132409
def push(self, dir):
        
        self.stack.append(os.getcwd())
        os.chdir(dir or os.getcwd())
903551
def on_change_dir_button(self, event):
        
        currentDirectory = self.WD #os.getcwd()
        change_dir_dialog = wx.DirDialog(self.panel,
                                         "Choose your working directory to create or edit a MagIC contribution:",
                                         defaultPath=currentDirectory,
                                         style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON | wx.DD_CHANGE_DIR)
        result = change_dir_dialog.ShowModal()
        if result == wx.ID_CANCEL:
            return
        if result == wx.ID_OK:
            self.WD = change_dir_dialog.GetPath()
            self.dir_path.SetValue(self.WD)
        change_dir_dialog.Destroy()
        wait = wx.BusyInfo('Initializing data object in new directory, please wait...')
        wx.SafeYield()
        print('-I- Initializing magic data object')
        # make new builder object, but reuse old data_model
        self.er_magic = builder.ErMagicBuilder(self.WD, self.er_magic.data_model)
        print('-I- Read in any available data from working directory')
        self.er_magic.get_all_magic_info()
        print('-I- Initializing headers')
        self.er_magic.init_default_headers()
        self.er_magic.init_actual_headers()
        del wait
1165757
def _remap_dirname(local, remote):
    
    def do(x):
        return x.replace(local, remote, 1)
    return do
873062
def chdir(self, directory_path, make=False):
        """"""
        if os.sep in directory_path:
            for directory in directory_path.split(os.sep):
                if make and not self.directory_exists(directory):
                    try:
                        self.session.mkd(directory)
                    except ftplib.error_perm:
                        # Directory already exists
                        pass
                self.session.cwd(directory)
        else:
            self.session.cwd(directory_path)
177671
def ensure_directory(path):
    """"""
    dirname = os.path.dirname(path)
    py31compat.makedirs(dirname, exist_ok=True)
1026186
function (context, path, callback) {
  path = normalize(path);
  var name = basename(path);
  var parentPath = dirname(path);

  var directoryNode;
  var directoryData;
  var parentDirectoryNode;
  var parentDirectoryData;

  function read_parent_directory_data(error, result) {
    if(error) {
      callback(error);
    } else {
      parentDirectoryNode = result;
      context.getObject(parentDirectoryNode.data, check_if_node_exists);
    }
  }

  function check_if_node_exists(error, result) {
    if(error) {
      callback(error);
    } else if(ROOT_DIRECTORY_NAME === name) {
      callback(new Errors.EBUSY(null, path));
    } else if(!result.hasOwnProperty(name)) {
      callback(new Errors.ENOENT(null, path));
    } else {
      parentDirectoryData = result;
      directoryNode = parentDirectoryData[name].id;
      context.getObject(directoryNode, check_if_node_is_directory);
    }
  }

  function check_if_node_is_directory(error, result) {
    if(error) {
      callback(error);
    } else if(result.type !== NODE_TYPE_DIRECTORY) {
      callback(new Errors.ENOTDIR(null, path));
    } else {
      directoryNode = result;
      context.getObject(directoryNode.data, check_if_directory_is_empty);
    }
  }

  function check_if_directory_is_empty(error, result) {
    if(error) {
      callback(error);
    } else {
      directoryData = result;
      if(Object.keys(directoryData).length > 0) {
        callback(new Errors.ENOTEMPTY(null, path));
      } else {
        _entry_from_parent_directory_node();
      }
    }
  }

  function update_time(error) {
    if(error) {
      callback(error);
    } else {
      var now = Date.now();
      update_node_times(context, parentPath, parentDirectoryNode, { mtime: now, ctime: now }, _node);
    }
  }

  function _entry_from_parent_directory_node() {
    delete parentDirectoryData[name];
    context.putObject(parentDirectoryNode.data, parentDirectoryData, update_time);
  }

  function _node(error) {
    if(error) {
      callback(error);
    } else {
      context.delete(directoryNode.id, _data);
    }
  }

  function _data(error) {
    if(error) {
      callback(error);
    } else {
      context.delete(directoryNode.data, callback);
    }
  }

  find_node(context, parentPath, read_parent_directory_data);
}
677218
def rmdir(self, dir_name):
        """"""
        self.check_write(dir_name)
        path = normpath_url(join_url(self.cur_dir, dir_name))
        # write("REMOVE %r" % path)
        shutil.rmtree(path)