Skip to content
Merged
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
4 changes: 2 additions & 2 deletions display/d.mon/render_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def render(cmd, mapfile):
grass.run_command(cmd[0], env=env, **cmd[1])
# display driver can generate a blank map file unnecessarily for
# non-rendering modules; delete it
if cmd[0] in non_rendering_modules and os.path.exists(mapfile):
if cmd[0] in non_rendering_modules and Path(mapfile).exists():
remove_mapfile(mapfile)

except CalledModuleError as e:
Expand Down Expand Up @@ -198,7 +198,7 @@ def read_stdin(cmd):
render(cmd, mapfile)

update_cmd_file(os.path.join(path, "cmd"), cmd, mapfile)
if cmd[0] == "d.erase" and os.path.exists(legfile):
if cmd[0] == "d.erase" and Path(legfile).exists():
os.remove(legfile)

sys.exit(0)
4 changes: 2 additions & 2 deletions gui/wxpython/animation/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
@author Anna Petrasova <kratochanna gmail.com>
"""

import os
import copy
from pathlib import Path

from grass.script.utils import parse_key_val
from grass.script import core as gcore
Expand Down Expand Up @@ -134,7 +134,7 @@ def SetWorkspaceFile(self, fileName):
if fileName == "":
raise ValueError(_("No workspace file selected."))

if not os.path.exists(fileName):
if not Path(fileName).exists():
raise OSError(_("File %s not found") % fileName)
self._workspaceFile = fileName

Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ def OnRemove(self, event):
def OnExport(self, event):
for decor in self.decorations:
if decor["name"] == "image":
if not os.path.exists(decor["file"]):
if not Path(decor["file"]).exists():
if decor["file"]:
GError(
parent=self, message=_("File %s not found.") % decor["file"]
Expand All @@ -1456,7 +1456,7 @@ def OnExport(self, event):

if self.formatChoice.GetSelection() == 0:
name = self.dirBrowse.GetValue()
if not os.path.exists(name):
if not Path(name).exists():
if name:
GError(parent=self, message=_("Directory %s not found.") % name)
else:
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def _export_file_validation(self, filebrowsebtn, file_path, file_postfix):
file_path += file_postfix

base_dir = os.path.dirname(file_path)
if not os.path.exists(base_dir):
if not Path(base_dir).exists():
GError(
parent=self,
message=file_path_does_not_exist_err_message.format(
Expand All @@ -1562,7 +1562,7 @@ def _export_file_validation(self, filebrowsebtn, file_path, file_postfix):
)
return False

if os.path.exists(file_path):
if Path(file_path).exists():
overwrite_dlg = wx.MessageDialog(
self.GetParent(),
message=_(
Expand Down
9 changes: 5 additions & 4 deletions gui/wxpython/animation/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import wx
import tempfile
from multiprocessing import Process, Queue
from pathlib import Path

from core.gcmd import GException, DecodeString
from core.settings import UserSettings
Expand Down Expand Up @@ -175,7 +176,7 @@ def _dryRender(self, uniqueCmds, regions, force):
filename = GetFileFromCmd(self._tempDir, cmd, region)
if (
not force
and os.path.exists(filename)
and Path(filename).exists()
and self._mapFilesPool.GetSize(HashCmd(cmd, region))
== (self.imageWidth, self.imageHeight)
):
Expand Down Expand Up @@ -378,7 +379,7 @@ def Render(self, cmdList, regions, regionFor3D, bgcolor, force, nprocs):
filename = GetFileFromCmd(self._tempDir, cmd, region)
if (
not force
and os.path.exists(filename)
and Path(filename).exists()
and self._mapFilesPool.GetSize(HashCmd(cmd, region))
== (self.imageWidth, self.imageHeight)
):
Expand Down Expand Up @@ -791,7 +792,7 @@ def __init__(self, tempDir):
def __call__(self):
import shutil

if os.path.exists(self._tempDir):
if Path(self._tempDir).exists():
try:
shutil.rmtree(self._tempDir)
Debug.msg(5, "CleanUp: removed directory {t}".format(t=self._tempDir))
Expand Down Expand Up @@ -901,7 +902,7 @@ def test():
mapFilesPool = MapFilesPool()

tempDir = "/tmp/test"
if os.path.exists(tempDir):
if Path(tempDir).exists():
shutil.rmtree(tempDir)
os.mkdir(tempDir)
# comment this line to keep the directory after program ends
Expand Down
5 changes: 3 additions & 2 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import codecs
import locale
from pathlib import Path

import wx
from wx.lib.newevent import NewEvent
Expand Down Expand Up @@ -607,11 +608,11 @@ def load_source(modname, filename):
if sys.platform == "win32":
pyFile += ".py"
pyPath = os.path.join(os.environ["GISBASE"], "scripts", pyFile)
if not os.path.exists(pyPath):
if not Path(pyPath).exists():
pyPath = os.path.join(
os.environ["GRASS_ADDON_BASE"], "scripts", pyFile
)
if not os.path.exists(pyPath):
if not Path(pyPath).exists():
GError(
parent=self._guiparent,
message=_("Module <%s> not found.") % command[0],
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def UpdateGRASSAddOnCommands(eList=None):
nCmd = 0
pathList = os.getenv("PATH", "").split(os.pathsep)
for path in addonPath.split(os.pathsep):
if not os.path.exists(path) or not os.path.isdir(path):
if not Path(path).exists() or not Path(path).is_dir():
continue

# check if addon is in the path
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def IsHidden(self):

def IsRendered(self) -> bool:
"""!Check if layer was rendered (if the image file exists)"""
return bool(os.path.exists(self.mapfile))
return bool(Path(self.mapfile).exists())

def SetType(self, ltype):
"""Set layer type"""
Expand Down Expand Up @@ -531,7 +531,7 @@ def _init(self):
self.layers = []

# re-render from scratch
if os.path.exists(self.Map.mapfile):
if Path(self.Map.mapfile).exists():
os.remove(self.Map.mapfile)

def _checkRenderedSizes(self, env, layers):
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ def ReadSettingsFile(self, settings=None):
if settings is None:
settings = self.userSettings

if os.path.exists(self.filePath):
if Path(self.filePath).exists():
self._readFile(settings)
elif os.path.exists(self.legacyFilePath):
elif Path(self.legacyFilePath).exists():
self._readLegacyFile(settings)

# set environment variables
Expand Down Expand Up @@ -982,7 +982,7 @@ def SaveToFile(self, settings=None):
settings = self.userSettings

dirPath = GetSettingsPath()
if not os.path.exists(dirPath):
if not Path(dirPath).exists():
try:
os.mkdir(dirPath)
except OSError:
Expand Down
14 changes: 7 additions & 7 deletions gui/wxpython/core/toolboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def GetSettingsPath():

def _getUserToolboxesFile():
userToolboxesFile = os.path.join(GetSettingsPath(), "toolboxes", "toolboxes.xml")
if not os.path.exists(userToolboxesFile):
if not Path(userToolboxesFile).exists():
userToolboxesFile = None
return userToolboxesFile


def _getUserMainMenuFile():
userMainMenuFile = os.path.join(GetSettingsPath(), "toolboxes", "main_menu.xml")
if not os.path.exists(userMainMenuFile):
if not Path(userMainMenuFile).exists():
userMainMenuFile = None
return userMainMenuFile

Expand Down Expand Up @@ -96,7 +96,7 @@ def toolboxesOutdated():
"""Removes auto-generated menudata.xml
to let gui regenerate it next time it starts."""
path = os.path.join(GetSettingsPath(), "toolboxes", "menudata.xml")
if os.path.exists(path):
if Path(path).exists():
try_remove(path)


Expand All @@ -118,7 +118,7 @@ def getMenudataFile(userRootFile, newFile, fallback):

distributionRootFile = os.path.join(WXGUIDIR, "xml", userRootFile)
userRootFile = os.path.join(GetSettingsPath(), "toolboxes", userRootFile)
if not os.path.exists(userRootFile):
if not Path(userRootFile).exists():
userRootFile = None

# always create toolboxes directory if does not exist yet
Expand All @@ -133,7 +133,7 @@ def getMenudataFile(userRootFile, newFile, fallback):
# when any of main_menu.xml or toolboxes.xml are changed,
# generate new menudata.xml

if os.path.exists(menudataFile):
if Path(menudataFile).exists():
# remove menu file when there is no main_menu and toolboxes
if not _getUserToolboxesFile() and (not userRootFile):
os.remove(menudataFile)
Expand Down Expand Up @@ -217,7 +217,7 @@ def _setupToolboxes():
"""Create 'toolboxes' directory if doesn't exist."""
basePath = GetSettingsPath()
path = os.path.join(basePath, "toolboxes")
if not os.path.exists(basePath):
if not Path(basePath).exists():
return None

if _createPath(path):
Expand All @@ -227,7 +227,7 @@ def _setupToolboxes():

def _createPath(path):
"""Creates path (for toolboxes) if it doesn't exist'"""
if not os.path.exists(path):
if not Path(path).exists():
try:
os.mkdir(path)
except OSError as e:
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import re
import inspect
import operator
from pathlib import Path
from string import digits
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -826,7 +827,7 @@ def StoreEnvVariable(key, value=None, envFile=None):
# read env file
environ = {}
lineSkipped = []
if os.path.exists(envFile):
if Path(envFile).exists():
try:
with open(envFile) as fd:
for line in fd:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ def ScheduleWatchCurrentMapset(self):
)
for element, directory in self._elements_dirs:
path = os.path.join(mapset_path, directory)
if not os.path.exists(path):
if not Path(path).exists():
try:
os.mkdir(path)
except OSError:
pass
if os.path.exists(path):
if Path(path).exists():
self._observer.schedule(
MapWatch(self._patterns, element, self._evt_handler),
path=path,
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def OnVGroup(self, event):
self.grassdatabase, self.xylocation, self.xymapset, "vector"
)

if os.path.exists(vector_dir):
if Path(vector_dir).exists():
dlg = VectGroup(
parent=self,
id=wx.ID_ANY,
Expand Down Expand Up @@ -1104,7 +1104,7 @@ def __init__(
}

# make a backup of the current points file
if os.path.exists(self.file["points"]):
if Path(self.file["points"]).exists():
shutil.copy(self.file["points"], self.file["points_bak"])

# polynomial order transformation for georectification
Expand Down Expand Up @@ -1928,10 +1928,10 @@ def OnQuit(self, event):
self.SaveGCPs(None)
elif ret == wx.NO:
# restore POINTS file from backup
if os.path.exists(self.file["points_bak"]):
if Path(self.file["points_bak"]).exists():
shutil.copy(self.file["points_bak"], self.file["points"])

if os.path.exists(self.file["points_bak"]):
if Path(self.file["points_bak"]).exists():
os.unlink(self.file["points_bak"])

self.SrcMap.Clean()
Expand Down Expand Up @@ -2705,7 +2705,7 @@ def MakeVGroup(self):

dirname = os.path.dirname(self.vgrpfile)

if not os.path.exists(dirname):
if not Path(dirname).exists():
os.makedirs(dirname)

with open(self.vgrpfile, mode="w") as f:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def OnModelSaveAs(self, event=None):
if filename[-4:] != ".gxm":
filename += ".gxm"

if os.path.exists(filename):
if Path(filename).exists():
dlg = wx.MessageDialog(
parent=self,
message=_(
Expand Down Expand Up @@ -1742,7 +1742,7 @@ def SaveAs(self, force=False):
if filename[-len(file_ext) - 1 :] != f".{file_ext}":
filename += f".{file_ext}"

if os.path.exists(filename):
if Path(filename).exists():
dlg = wx.MessageDialog(
self,
message=_(
Expand Down
Loading
Loading