Exemplo n.º 1
0
def rename_mapset_interactively(guiparent, grassdb, location, mapset):
    """Rename mapset with user interaction.

    Exceptions during renaming are handled in get_reason_mapset_not_removable
    function.

    Returns newmapset if there was a change or None if the mapset cannot be
    renamed (see reasons given by get_reason_mapset_not_removable
    function) or if another error was encountered.
    """
    newmapset = None

    # Check selected mapset
    message = get_reason_mapset_not_removable(grassdb,
                                              location,
                                              mapset,
                                              check_permanent=True)
    if message:
        dlg = wx.MessageDialog(
            parent=guiparent,
            message=_(
                "Cannot rename mapset <{mapset}> for the following reason:\n\n"
                "{reason}\n\n"
                "No mapset will be renamed.").format(mapset=mapset,
                                                     reason=message),
            caption=_("Unable to rename selected mapset"),
            style=wx.OK | wx.ICON_WARNING)
        dlg.ShowModal()
        dlg.Destroy()
        return newmapset

    # Display question dialog
    dlg = MapsetDialog(
        parent=guiparent,
        default=mapset,
        message=_("Current name: {}\n\nEnter new name:").format(mapset),
        caption=_("Rename selected mapset"),
        database=grassdb,
        location=location,
    )
    if dlg.ShowModal() == wx.ID_OK:
        newmapset = dlg.GetValue()
        try:
            rename_mapset(grassdb, location, mapset, newmapset)
        except OSError as err:
            newmapset = None
            wx.MessageBox(
                parent=guiparent,
                caption=_("Error"),
                message=_("Unable to rename mapset.\n\n{}").format(err),
                style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
            )
    dlg.Destroy()
    return newmapset
Exemplo n.º 2
0
def rename_mapset_interactively(guiparent, grassdb, location, mapset):
    """
    Rename selected mapset
    """
    newmapset = None
    if mapset == "PERMANENT":
        GMessage(
            parent=guiparent,
            message=_(
                "Mapset <PERMANENT> is required for valid GRASS location.\n\n"
                "This mapset cannot be renamed."),
        )
        return newmapset

    dlg = MapsetDialog(
        parent=guiparent,
        default=mapset,
        message=_("Current name: {}\n\nEnter new name:").format(mapset),
        caption=_("Rename selected mapset"),
        database=grassdb,
        location=location,
    )

    if dlg.ShowModal() == wx.ID_OK:
        newmapset = dlg.GetValue()
        try:
            rename_mapset(grassdb, location, mapset, newmapset)
        except OSError as err:
            newmapset = None
            wx.MessageBox(
                parent=guiparent,
                caption=_("Error"),
                message=_("Unable to rename mapset.\n\n{}").format(err),
                style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
            )
    dlg.Destroy()
    return newmapset
Exemplo n.º 3
0
def rename_mapset_interactively(guiparent, grassdb, location, mapset):
    """Rename mapset with user interaction.

    If PERMANENT or current mapset found, rename operation is not performed.

    Exceptions during renaming are handled in this function.

    Returns newmapset if there was a change or None if the mapset cannot be
    renamed (see above the possible reasons) or if another error was encountered.
    """
    genv = gisenv()

    # Check selected mapset and remember issue.
    # Each error is reported only once (using elif).
    mapset_path = os.path.join(grassdb, location, mapset)
    newmapset = None
    issue = None

    # Check for permanent mapsets
    if mapset == "PERMANENT":
        issue = _("<{}> is required for a valid location.").format(mapset_path)
    # Check for current mapset
    elif (grassdb == genv['GISDBASE'] and location == genv['LOCATION_NAME']
          and mapset == genv['MAPSET']):
        issue = _("<{}> is the current mapset.").format(mapset_path)

    # If an issue, display the warning message and do not rename mapset
    if issue:
        dlg = wx.MessageDialog(
            parent=guiparent,
            message=_(
                "Cannot rename selected mapset for the following reason:\n\n"
                "{}\n\n"
                "No mapset will be renamed.").format(issue),
            caption=_("Unable to rename selected mapset"),
            style=wx.OK | wx.ICON_WARNING)
        dlg.ShowModal()
    else:
        dlg = MapsetDialog(
            parent=guiparent,
            default=mapset,
            message=_("Current name: {}\n\nEnter new name:").format(mapset),
            caption=_("Rename selected mapset"),
            database=grassdb,
            location=location,
        )

        if dlg.ShowModal() == wx.ID_OK:
            newmapset = dlg.GetValue()
            try:
                rename_mapset(grassdb, location, mapset, newmapset)
            except OSError as err:
                newmapset = None
                wx.MessageBox(
                    parent=guiparent,
                    caption=_("Error"),
                    message=_("Unable to rename mapset.\n\n{}").format(err),
                    style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
                )
    dlg.Destroy()
    return newmapset