Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ def __init__(
self.tselect = Select(parent=self, type="strds")
iconTheme = UserSettings.Get(group="appearance", key="iconTheme", subkey="type")
bitmapPath = os.path.join(globalvar.ICONDIR, iconTheme, "layer-open.png")
if os.path.isfile(bitmapPath) and Path(bitmapPath).stat().st_size:
if Path(bitmapPath).is_file() and Path(bitmapPath).stat().st_size:
bitmap = wx.Bitmap(name=bitmapPath)
else:
bitmap = wx.ArtProvider.GetBitmap(
Expand Down
25 changes: 12 additions & 13 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_tempfile_name(suffix, create=False):

if not create:
# remove empty file to have a clean state later
os.remove(name)
Path(name).unlink()
return name


Expand Down Expand Up @@ -428,8 +428,8 @@ def Render(self, cmd, env):
if self.layer.GetType() in {"vector", "thememap"}:
if not self.layer._legrow:
self.layer._legrow = grass.tempfile(create=True)
if os.path.isfile(self.layer._legrow):
os.remove(self.layer._legrow)
if (p := Path(self.layer._legrow)).is_file():
p.unlink()
env_cmd["GRASS_LEGEND_FILE"] = text_to_string(self.layer._legrow)

cmd_render = copy.deepcopy(cmd)
Expand Down Expand Up @@ -531,8 +531,8 @@ def _init(self):
self.layers = []

# re-render from scratch
if Path(self.Map.mapfile).exists():
os.remove(self.Map.mapfile)
if (p := Path(self.Map.mapfile)).is_file():
p.unlink()

def _checkRenderedSizes(self, env, layers):
"""Check if rendering size in current env differs from size of
Expand Down Expand Up @@ -663,7 +663,7 @@ def OnRenderDone(self, env):
if layer.GetType() == "overlay":
continue

if os.path.isfile(layer.mapfile):
if Path(layer.mapfile).is_file():
maps.append(layer.mapfile)
masks.append(layer.maskfile)
opacities.append(str(layer.opacity))
Expand Down Expand Up @@ -707,8 +707,8 @@ def OnRenderDone(self, env):
if layer.GetType() not in {"vector", "thememap"}:
continue

if os.path.isfile(layer._legrow) and not layer.hidden:
line = Path(layer._legrow).read_text()
if (p := Path(layer._legrow)).is_file() and not layer.hidden:
line = p.read_text()
outfile.write(line)
new_legend.append(line)

Expand Down Expand Up @@ -1414,11 +1414,10 @@ def DeleteLayer(self, layer, overlay=False):
# it as it is, although it does not really fit with the
# new system (but probably works well enough)
for f in glob.glob(basefile):
os.remove(f)
Path(f).unlink()

if layer.GetType() in {"vector", "thememap"}:
if os.path.isfile(layer._legrow):
os.remove(layer._legrow)
Path(layer._legrow).unlink(missing_ok=True)

list_.remove(layer)

Expand Down Expand Up @@ -1534,8 +1533,8 @@ def RemoveLayer(self, name=None, id=None):
for layer in self.layers:
if layer.name == name:
retlayer = layer
os.remove(layer.mapfile)
os.remove(layer.maskfile)
Path(layer.mapfile).unlink()
Path(layer.maskfile).unlink()
self.layers.remove(layer)
return retlayer
# del by id
Expand Down
5 changes: 3 additions & 2 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,9 @@ def GetListOfMapsets(dbase, location, selectable=False):
listOfMapsets += line.split(" ")
else:
for mapset in glob.glob(os.path.join(dbase, location, "*")):
if os.path.isdir(mapset) and os.path.isfile(
os.path.join(dbase, location, mapset, "WIND")
if (
Path(mapset).is_dir()
and Path(dbase, location, mapset, "WIND").is_file()
):
listOfMapsets.append(os.path.basename(mapset))

Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ def LoadData(self):
self.DeleteAllItems()

self.render = False
if os.path.isfile(self.gcp.file["points"]):
if Path(self.gcp.file["points"]).is_file():
self.gcp.ReadGCPs()
else:
# 3 gcp is minimum
Expand Down Expand Up @@ -2636,7 +2636,7 @@ def __init__(
#
self.listMap = CheckListBox(parent=self, id=wx.ID_ANY, choices=vectlist)

if os.path.isfile(self.vgrpfile):
if Path(self.vgrpfile).is_file():
with open(self.vgrpfile) as f:
checked = []
for line in f:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
style=wx.TE_MULTILINE,
size=(-1, 75),
)
if p.get("value", "") and os.path.isfile(p["value"]):
if p.get("value", "") and Path(p["value"]).is_file():
ifbb.Clear()
try:
# Python >= 3.11
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gui_core/ghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,14 @@ def LoadPage(self, path=None):
def GetFile(self):
"""Get HTML file"""
fMan = os.path.join(self.content.fspath, self.command + ".html")
if os.path.isfile(fMan):
if Path(fMan).is_file():
return fMan

# check also addons
faMan = os.path.join(
os.getenv("GRASS_ADDON_BASE"), "docs", "html", self.command + ".html"
)
if os.getenv("GRASS_ADDON_BASE") and os.path.isfile(faMan):
if os.getenv("GRASS_ADDON_BASE") and Path(faMan).is_file():
return faMan

return None
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def CreateSelectionButton(self, tooltip):
Button must be custom (not toolbar tool) to set smaller width.
"""
arrowPath = os.path.join(IMGDIR, "small_down_arrow.png")
if os.path.isfile(arrowPath) and Path(arrowPath).stat().st_size:
if Path(arrowPath).is_file() and Path(arrowPath).stat().st_size:
bitmap = wx.Bitmap(name=arrowPath)
else:
bitmap = wx.ArtProvider.GetBitmap(
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/icons/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def GetBitmap(self, size=None):
id=self.imagepath, client=wx.ART_TOOLBAR, size=size
)
elif self.type == "img":
if os.path.isfile(self.imagepath) and Path(self.imagepath).stat().st_size:
if Path(self.imagepath).is_file() and Path(self.imagepath).stat().st_size:
if size and len(size) == 2:
image = wx.Image(name=self.imagepath)
image.Rescale(size[0], size[1])
Expand Down
16 changes: 9 additions & 7 deletions gui/wxpython/image2target/ii2t_gis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ def _readGisRC(self):

gisrc = os.getenv("GISRC")

if gisrc and os.path.isfile(gisrc):
with open(gisrc) as rc:
if gisrc and (gisrc_path := Path(gisrc)).is_file():
with gisrc_path.open() as rc:
for line in rc:
try:
key, val = line.split(":", 1)
Expand Down Expand Up @@ -920,8 +920,9 @@ def UpdateMapsets(self, location):
disabled = []
idx = 0
for mapset in self.listOfMapsets:
if mapset not in self.listOfMapsetsSelectable or os.path.isfile(
os.path.join(self.gisdbase, locationName, mapset, ".gislock")
if (
mapset not in self.listOfMapsetsSelectable
or Path(self.gisdbase, locationName, mapset, ".gislock").is_file()
):
disabled.append(idx)
idx += 1
Expand Down Expand Up @@ -952,8 +953,9 @@ def OnSelectLocation(self, event):
locationName = ""

for mapset in self.listOfMapsets:
if mapset not in self.listOfMapsetsSelectable or os.path.isfile(
os.path.join(self.gisdbase, locationName, mapset, ".gislock")
if (
mapset not in self.listOfMapsetsSelectable
or Path(self.gisdbase, locationName, mapset, ".gislock").is_file()
):
disabled.append(idx)
idx += 1
Expand Down Expand Up @@ -1093,7 +1095,7 @@ def OnStart(self, event):
mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]

lockfile = os.path.join(dbase, location, mapset, ".gislock")
if os.path.isfile(lockfile):
if Path(lockfile).is_file():
dlg = wx.MessageDialog(
parent=self,
message=_(
Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,7 @@ def LoadData(self):
self.DeleteAllItems()

self.render = False
if os.path.isfile(self.gcp.file["control_points"]):
if Path(self.gcp.file["control_points"]).is_file():
self.gcp.ReadGCPs()
else:
# 3 gcp is minimum
Expand Down Expand Up @@ -2559,7 +2559,7 @@ def __init__(
).iterdir()
]
for dir in vectlist:
if not os.path.isfile(
if not Path(
os.path.join(
self.grassdatabase,
self.xylocation,
Expand All @@ -2568,7 +2568,7 @@ def __init__(
dir,
"coor",
)
):
).is_file():
vectlist.remove(dir)

utils.ListSortLower(vectlist)
Expand All @@ -2595,7 +2595,7 @@ def __init__(
#
self.listMap = CheckListBox(parent=self, id=wx.ID_ANY, choices=vectlist)

if os.path.isfile(self.vgrpfile):
if Path(self.vgrpfile).is_file():
with open(self.vgrpfile) as f:
checked = []
for line in f:
Expand Down
13 changes: 7 additions & 6 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,15 +1479,15 @@ def OnEnterPage(self, event: WizardEvent) -> None:
event.Skip()

def OnPageChanging(self, event: WizardEvent) -> None:
if event.GetDirection() and not os.path.isfile(self.georeffile):
if event.GetDirection() and not Path(self.georeffile).is_file():
event.Veto()
self.GetNext().SetPrev(self)

def OnText(self, event):
"""File changed"""
self.georeffile = event.GetString()
nextButton = wx.FindWindowById(wx.ID_FORWARD)
if len(self.georeffile) > 0 and os.path.isfile(self.georeffile):
if len(self.georeffile) > 0 and Path(self.georeffile).is_file():
if not nextButton.IsEnabled():
nextButton.Enable(True)
elif nextButton.IsEnabled():
Expand Down Expand Up @@ -2644,7 +2644,7 @@ def OnWizFinished(self):
location = self.startpage.location

# location already exists?
if os.path.isdir(os.path.join(database, location)):
if Path(database, location).is_dir():
GError(
parent=self.wizard,
message="%s <%s>: %s"
Expand All @@ -2660,7 +2660,7 @@ def OnWizFinished(self):
current_gdb = decode(grass.gisenv()["GISDBASE"])
if current_gdb != database:
# change to new GISDbase or create new one
if not os.path.isdir(database):
if not Path(database).is_dir():
# create new directory
try:
os.mkdir(database)
Expand Down Expand Up @@ -2730,8 +2730,9 @@ def OnWizFinished(self):
desc=self.startpage.locTitle,
)
elif coordsys == "file":
if not self.filepage.georeffile or not os.path.isfile(
self.filepage.georeffile
if (
not self.filepage.georeffile
or not Path(self.filepage.georeffile).is_file()
):
return _("File <%s> not found.") % self.filepage.georeffile

Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/mapwin/buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def GetOverlay(self):
for overlay in self.Map.GetListOfLayers(ltype="overlay", active=True):
if (
overlay.mapfile is None
or not os.path.isfile(overlay.mapfile)
or not Path(overlay.mapfile).is_file()
or (not Path(overlay.mapfile).stat().st_size)
):
continue
Expand All @@ -824,7 +824,7 @@ def GetImage(self):
imgId = 99
if (
self.Map.mapfile
and os.path.isfile(self.Map.mapfile)
and Path(self.Map.mapfile).is_file()
and Path(self.Map.mapfile).stat().st_size
):
img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/colorrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ def GetImage(self):
"""Converts files to wx.Image"""
if (
self.Map.mapfile
and os.path.isfile(self.Map.mapfile)
and Path(self.Map.mapfile).is_file()
and Path(self.Map.mapfile).stat().st_size
):
img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def GetImage(self):
"""Converts files to wx.Image"""
if (
self.Map.mapfile
and os.path.isfile(self.Map.mapfile)
and Path(self.Map.mapfile).is_file()
and Path(self.Map.mapfile).stat().st_size
):
img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ def LoadData(self):
self.DeleteAllItems()

self.render = False
if os.path.isfile(self.gcp.file["points"]):
if Path(self.gcp.file["points"]).is_file():
self.gcp.ReadGCPs()
else:
# 3 gcp is minimum
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/web_services/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import shutil

from copy import deepcopy
from pathlib import Path

import grass.script as gs
from grass.script.task import cmdlist_to_tuple, cmdtuple_to_list
Expand Down Expand Up @@ -676,7 +677,7 @@ def __del__(self):

def _setRevertCapFiles(self, ws_cap_files):
for ws, f in ws_cap_files.items():
if os.path.isfile(f):
if Path(f).is_file():
shutil.copyfile(f, self.revert_ws_cap_files[ws])
else:
# delete file content
Expand Down
4 changes: 2 additions & 2 deletions imagery/i.cluster/testsuite/test_i_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _signature_exists(self):
"sig",
"sig",
)
return os.path.isfile(sig_file_path)
return Path(sig_file_path).is_file()

def test_cluster_creation(self):
"""Test the creation of a signature file and validate the number of classes."""
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_sample_interval(self):
sample=sample_interval,
overwrite=True,
)
self.assertTrue(os.path.isfile(report_file))
self.assertTrue(Path(report_file).is_file())
content = Path(report_file).read_text()
expected_cells = (100 // sample_interval[0]) * (100 // sample_interval[1])
match = re.search(r"Sample size:\s+(\d+)", content)
Expand Down
Loading
Loading