Skip to content

Commit

Permalink
g.proj: fix reading input WKT (OSGeo#1582)
Browse files Browse the repository at this point in the history
properly terminate input WKT string

Co-authored-by: Marc Jansen <jansen@terrestris.de>
  • Loading branch information
a0x8o and marcjansen committed Aug 23, 2024
1 parent 9e2a78d commit dc8b886
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ COPY --from=build /usr/local/grass* /usr/local/grass/
RUN apk add curl && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py pip==20.0.2 && rm get-pip.py

# install external Python API
RUN pip3 install --upgrade grass-session
RUN pip3 install --upgrade pip six grass-session --ignore-installed six

RUN ln -s /usr/local/grass /usr/local/grass7
RUN ln -s /usr/local/grass `grass --config path`
Expand Down
16 changes: 16 additions & 0 deletions general/g.proj/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ int input_wkt(char *wktfile)
infd = fopen(wktfile, "r");

if (infd) {
<<<<<<< HEAD
size_t wktlen;

wktlen = fread(buff, 1, sizeof(buff), infd);
Expand All @@ -128,6 +129,21 @@ int input_wkt(char *wktfile)
buff[wktlen] = '\0';
/* Get rid of newlines */
G_squeeze(buff);
=======
size_t wktlen;

wktlen = fread(buff, 1, sizeof(buff), infd);
if (wktlen == sizeof(buff))
G_fatal_error(_("Input WKT definition is too long"));
if (ferror(infd))
G_fatal_error(_("Error reading WKT definition"));
else
fclose(infd);
/* terminate WKT string */
buff[wktlen] = '\0';
/* Get rid of newlines */
G_squeeze(buff);
>>>>>>> b3579a4902 (g.proj: fix reading input WKT (#1582))
}
else
G_fatal_error(_("Unable to open file '%s' for reading"), wktfile);
Expand Down
35 changes: 35 additions & 0 deletions gui/wxpython/gui_core/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,41 @@ def __init__(self, parent, giface, menuModel):
if giface:
giface.currentMapsetChanged.connect(self._reloadListOfMaps)
giface.grassdbChanged.connect(self._reloadListOfMaps)
<<<<<<< HEAD
=======

def _readHistory(self):
"""Get list of commands from history file"""
hist = list()
env = grass.gisenv()
try:
fileHistory = codecs.open(
os.path.join(
env["GISDBASE"],
env["LOCATION_NAME"],
env["MAPSET"],
".bash_history",
),
encoding="utf-8",
mode="r",
errors="replace",
)
except IOError:
return hist

try:
for line in fileHistory.readlines():
hist.append(line.replace("\n", ""))
finally:
fileHistory.close()

return hist

def _loadHistory(self):
"""Load history from a history file to data structures"""
self.cmdbuffer = self._readHistory()
self.cmdindex = len(self.cmdbuffer)
>>>>>>> b3579a4902 (g.proj: fix reading input WKT (#1582))

def _getListOfMaps(self):
"""Get list of maps"""
Expand Down
26 changes: 22 additions & 4 deletions python/grass/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
ignore =
E203, # whitespace before ':' (Black)
W503, # line break before binary operator (Black)
E722, # do not use bare 'except'

per-file-ignores =
# C wrappers call libgis.G_gisinit before importing other modules.
Expand All @@ -29,12 +28,31 @@ per-file-ignores =
script/db.py: E501
script/task.py: W605
script/vector.py: E501 # Long doctest lines which need review anyway
temporal/*.py: E501, F841
temporal/abstract_space_time_dataset.py: W605, E501, F841
temporal/temporal_algebra.py: E741, E501, F841
temporal/abstract_map_dataset.py: E501
temporal/abstract_space_time_dataset.py: W605, E501, F841, E722
temporal/aggregation.py: E501
temporal/base.py: E501
temporal/c_libraries_interface.py: E501, F841, E722
temporal/core.py: E501, E722
temporal/datetime_math.py: E501, F841, E722
temporal/list_stds.py: E501
temporal/metadata.py: E501
temporal/open_stds.py: F841
temporal/register.py: E501
temporal/space_time_datasets.py: E501
temporal/spatial_extent.py: E501
temporal/spatial_topology_dataset_connector.py: E501, E722
temporal/spatio_temporal_relationships.py: E501
temporal/temporal_algebra.py: E741, E501, F841, E722
temporal/temporal_extent.py: E501
temporal/temporal_granularity.py: E501, F841, E722
temporal/temporal_operator.py: E501
temporal/temporal_raster_algebra.py: E741
temporal/temporal_raster_base_algebra.py: E501, F841, E722
temporal/temporal_raster3d_algebra.py: E741
temporal/temporal_topology_dataset_connector.py: E501, E722
temporal/temporal_vector_algebra.py: E741, E501, F841
temporal/univar_statistics.py: E501
# Current benchmarks/tests are changing sys.path before import.
# Possibly, a different approach should be taken there anyway.
pygrass/tests/benchmark.py: E501, E402, F401, F821
Expand Down
27 changes: 27 additions & 0 deletions scripts/g.extension/g.extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,29 @@ def replace_shebang_win(python_file):
os.rename(tmp_name, python_file) # rename temp to original name


def replace_shebang_win(python_file):
"""
Replaces "python" with "python3" in python files
using UTF8 encoding on MS Windows
"""

cur_dir = os.path.dirname(python_file)
tmp_name = os.path.join(cur_dir, gscript.tempname(12))

with codecs.open(python_file, "r", encoding="utf8") as in_file, codecs.open(
tmp_name, "w", encoding="utf8"
) as out_file:

for line in in_file:
new_line = line.replace(
"#!/usr/bin/env python\n", "#!/usr/bin/env python3\n"
)
out_file.write(new_line)

os.remove(python_file) # remove original
os.rename(tmp_name, python_file) # rename temp to original name


def urlretrieve(url, filename, *args, **kwargs):
"""Same function as 'urlretrieve', but with the ability to
define headers.
Expand Down Expand Up @@ -1637,7 +1660,11 @@ def install_extension_win(name):
for r, d, f in os.walk(srcdir):
for file in f:
# Filter GRASS module name patterns
<<<<<<< HEAD
if re.search(module_name_pattern, file):
=======
if re.search(r"^[d,db,g,i,m,p,ps,r,r3,s,t,v,wx]\..*[\.py,\.exe]$", file):
>>>>>>> b3579a4902 (g.proj: fix reading input WKT (#1582))
modulename = os.path.splitext(file)[0]
module_list.append(modulename)
# remove duplicates in case there are .exe wrappers for python scripts
Expand Down

0 comments on commit dc8b886

Please sign in to comment.