|
33 | 33 | import shutil
|
34 | 34 | import sys
|
35 | 35 | from copy import copy
|
| 36 | +from pathlib import Path |
36 | 37 | from typing import TYPE_CHECKING
|
37 | 38 |
|
38 | 39 | import wx
|
@@ -466,16 +467,12 @@ def OnLocation(self, event):
|
466 | 467 | self.xylocation = event.GetString()
|
467 | 468 |
|
468 | 469 | # create a list of valid mapsets
|
469 |
| - tmplist = os.listdir(os.path.join(self.grassdatabase, self.xylocation)) |
| 470 | + location_path = Path(self.grassdatabase) / self.xylocation |
470 | 471 | self.mapsetList = []
|
471 |
| - for item in tmplist: |
472 |
| - if os.path.isdir( |
473 |
| - os.path.join(self.grassdatabase, self.xylocation, item) |
474 |
| - ) and os.path.exists( |
475 |
| - os.path.join(self.grassdatabase, self.xylocation, item, "WIND") |
476 |
| - ): |
477 |
| - if item != "PERMANENT": |
478 |
| - self.mapsetList.append(item) |
| 472 | + for item in location_path.iterdir(): |
| 473 | + if item.is_dir() and (item / "WIND").exists(): |
| 474 | + if item.name != "PERMANENT": |
| 475 | + self.mapsetList.append(item.name) |
479 | 476 |
|
480 | 477 | self.xymapset = "PERMANENT"
|
481 | 478 | utils.ListSortLower(self.mapsetList)
|
@@ -697,25 +694,13 @@ def OnEnterPage(self, event: WizardEvent | None = None) -> None:
|
697 | 694 | self.xymapset = self.parent.gisrc_dict["MAPSET"]
|
698 | 695 |
|
699 | 696 | # create a list of groups in selected mapset
|
700 |
| - if os.path.isdir( |
701 |
| - os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "group") |
702 |
| - ): |
703 |
| - tmplist = os.listdir( |
704 |
| - os.path.join( |
705 |
| - self.grassdatabase, self.xylocation, self.xymapset, "group" |
706 |
| - ) |
707 |
| - ) |
708 |
| - for item in tmplist: |
709 |
| - if os.path.isdir( |
710 |
| - os.path.join( |
711 |
| - self.grassdatabase, |
712 |
| - self.xylocation, |
713 |
| - self.xymapset, |
714 |
| - "group", |
715 |
| - item, |
716 |
| - ) |
717 |
| - ): |
718 |
| - self.groupList.append(item) |
| 697 | + group_path = ( |
| 698 | + Path(self.grassdatabase) / self.xylocation / self.xymapset / "group" |
| 699 | + ) |
| 700 | + if group_path.is_dir(): |
| 701 | + for item in group_path.iterdir(): |
| 702 | + if item.is_dir(): |
| 703 | + self.groupList.append(item.name) |
719 | 704 |
|
720 | 705 | if maptype == "raster":
|
721 | 706 | self.btn_vgroup.Hide()
|
@@ -2032,8 +2017,8 @@ def RMSError(self, xygroup, order):
|
2032 | 2017 | highest_idx = 0
|
2033 | 2018 |
|
2034 | 2019 | for index in range(self.list.GetItemCount()):
|
2035 |
| - key = self.list.GetItemData(index) |
2036 | 2020 | if self.list.IsItemChecked(index):
|
| 2021 | + key = self.list.GetItemData(index) |
2037 | 2022 | fwd_err, bkw_err = errlist[GCPcount].split()
|
2038 | 2023 | self.list.SetItem(index, 5, fwd_err)
|
2039 | 2024 | self.list.SetItem(index, 6, bkw_err)
|
@@ -2620,21 +2605,14 @@ def __init__(
|
2620 | 2605 | #
|
2621 | 2606 | # get list of valid vector directories
|
2622 | 2607 | #
|
2623 |
| - vectlist = os.listdir( |
2624 |
| - os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "vector") |
2625 |
| - ) |
2626 |
| - for dir in vectlist: |
2627 |
| - if not os.path.isfile( |
2628 |
| - os.path.join( |
2629 |
| - self.grassdatabase, |
2630 |
| - self.xylocation, |
2631 |
| - self.xymapset, |
2632 |
| - "vector", |
2633 |
| - dir, |
2634 |
| - "coor", |
2635 |
| - ) |
2636 |
| - ): |
2637 |
| - vectlist.remove(dir) |
| 2608 | + vector_path = ( |
| 2609 | + Path(self.grassdatabase) / self.xylocation / self.xymapset / "vector" |
| 2610 | + ) |
| 2611 | + vectlist = [ |
| 2612 | + coor_path.parent.name |
| 2613 | + for coor_path in vector_path.glob("*/coor") |
| 2614 | + if coor_path.is_file() |
| 2615 | + ] |
2638 | 2616 |
|
2639 | 2617 | utils.ListSortLower(vectlist)
|
2640 | 2618 |
|
|
0 commit comments