Skip to content

Commit

Permalink
register.py: allow registering from io objects (OSGeo#1929)
Browse files Browse the repository at this point in the history
Added fd.close() (which also works with io objects). Take the liberty to merge this minor change...
* allow registering from io
* update docstring
* close file object
  • Loading branch information
ninsbl authored Oct 14, 2021
1 parent 75848ee commit 2e45948
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/grass/temporal/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def register_maps_in_space_time_dataset(
to None
:param maps: A comma separated list of map names
:param file: Input file, one map per line map with start and optional
end time
end time, or the same as io object (with readline capability)
:param start: The start date and time of the first map
(format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd",
format relative is integer 5)
Expand Down Expand Up @@ -154,7 +154,10 @@ def register_maps_in_space_time_dataset(

# Read the map list from file
if file:
fd = open(file, "r")
if hasattr(file, "readline"):
fd = file
else:
fd = open(file, "r")

line = True
while True:
Expand Down Expand Up @@ -222,6 +225,7 @@ def register_maps_in_space_time_dataset(
"The interval flag will be ignored because of time stamps in input file"
)
)
fd.close()

num_maps = len(maplist)
map_object_list = []
Expand Down

0 comments on commit 2e45948

Please sign in to comment.