Select directory.
967096
def select_location(self):
        """"""
        location = osp.normpath(getexistingdirectory(self,
                                                     _("Select directory"),
                                                     self.location))

        if location:
            if is_writable(location):
                self.location = location
                self.update_location()
1097332
def mkdir(path, recursive=True, **kwargs):
    """"""
    import os
    if recursive:
        os.makedirs(path, **kwargs)
    else:
        os.mkdir(path, **kwargs)
1047807
def _list_dir(self, path):
        """"""
        try:
            elements = [
                os.path.join(path, x) for x in os.listdir(path)
            ] if os.path.isdir(path) else []
            elements.sort()
        except OSError:
            elements = None
        return elements
1020829
def select_directory_dialog(windowTitle, defaultPath=os.getcwd(), style=None):
    
    app = wx.App(None)

    if style == None:
        style = wx.DD_DIR_MUST_EXIST

    dialog = wx.DirDialog(None, windowTitle, defaultPath=defaultPath, style=style)

    if dialog.ShowModal() == wx.ID_OK:
        path = dialog.GetPath()
    else:
        path = None
    dialog.Destroy()
    return path
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)
1218637
def include_dir(self, root):
        """"""
        parts = [root]
        parts.extend(self.pathname.split(os.path.sep))
        return "/".join(parts)
1235896
def _on_selection(self):
        
        if self.value and os.path.isdir(self.value):
            self._populate_list(self.value)
        elif self._external_notification:
            self._external_notification()
779902
def files_in_dir(path, extension):
    """"""
    ends = '.{0}'.format(extension)
    return (f for f in os.listdir(path) if f.endswith(ends))
1054942
def do_cd(self, arg):
        """"""
        from os import chdir, path
        fullpath = path.abspath(path.expanduser(arg))
        if path.isdir(fullpath):
            chdir(fullpath)
        else:
            msg.err("'{}' is not a valid directory.".format(arg))
605279
def mkdir_and_cd(dirname):
    """"""
    if not os.path.exists(dirname):
        os.makedirs(dirname)
        os.chdir(dirname)
    else:
        os.chdir(dirname)
994005
def select_output_directory(self):
        """"""
        # Input layer
        input_layer_path = self.layer.source()
        input_file_name = os.path.basename(input_layer_path)
        input_extension = os.path.splitext(input_file_name)[1]

        # Get current path
        current_file_path = self.output_path_line_edit.text()
        if not current_file_path or not os.path.exists(current_file_path):
            current_file_path = input_layer_path

        # Filtering based on input layer
        extension_mapping = {
            '.shp': tr('Shapefile (*.shp);;'),
            '.geojson': tr('GeoJSON (*.geojson);;'),
            '.tif': tr('Raster TIF/TIFF (*.tif, *.tiff);;'),
            '.tiff': tr('Raster TIF/TIFF (*.tiff, *.tiff);;'),
            '.asc': tr('Raster ASCII File (*.asc);;'),
        }
        # Open File Dialog
        file_path, __ = QFileDialog.getSaveFileName(
            self,
            tr('Output File'),
            current_file_path,
            extension_mapping[input_extension]
        )
        if file_path:
            self.output_path_line_edit.setText(file_path)
825072
def prepare_storage_dir(storage_directory):
    """"""
    storage_directory = os.path.expanduser(storage_directory)
    if not os.path.exists(storage_directory):
        os.mkdir(storage_directory)

    return storage_directory
950939
def directory(self):
        """"""
        if self._directory is None:
            self._directory = self.api._load_directory(self.cid)
        return self._directory
944430
def _directory (self):
        """"""
        if self._filename is None:
            return os.path.join(self._ROOT_DIR, 'config')
        else:
            return os.path.dirname(self._filename)
517802
def clicked(self):
        """"""
        fnames = self.get_selected_filenames()
        for fname in fnames:
            if osp.isdir(fname):
                self.directory_clicked(fname)
            else:
                self.open([fname])
416182
def get_dir(self, objtxt):
        """"""
        obj, valid = self._eval(objtxt)
        if valid:
            return getobjdir(obj)
300080
def choose_path():
    
    dirs = webview.create_file_dialog(webview.FOLDER_DIALOG)
    if dirs and len(dirs) > 0:
        directory = dirs[0]
        if isinstance(directory, bytes):
            directory = directory.decode("utf-8")

        response = {"status": "ok", "directory": directory}
    else:
        response = {"status": "cancel"}

    return jsonify(response)