Skip to content

Commit

Permalink
Merge pull request #187 from opengisch/import_stack_fix
Browse files Browse the repository at this point in the history
Fix error stack thrown when trying to import/synchronize data from a non-existing directory
  • Loading branch information
m-kuhn authored Sep 20, 2020
2 parents 3e32557 + c4104f9 commit 27dc051
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions qfieldsync/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from qfieldsync.utils.exceptions import NoProjectFoundError, QFieldSyncError

from qgis.PyQt.QtCore import QCoreApplication

def fileparts(fn, extension_dot=True):
path = os.path.dirname(fn)
Expand All @@ -44,6 +45,10 @@ def fileparts(fn, extension_dot=True):


def get_children_with_extension(parent, specified_ext, count=1):
if not os.path.isdir(parent):
raise QFieldSyncError(
QCoreApplication.translate("QFieldFileUtils","The directory {} could not be found").format(parent))

res = []
extension_dot = specified_ext.startswith(".")
for fn in os.listdir(parent):
Expand All @@ -52,8 +57,8 @@ def get_children_with_extension(parent, specified_ext, count=1):
res.append(os.path.join(parent, fn))
if len(res) != count:
raise QFieldSyncError(
"Expected {} children with extension {} under {}, got {}".format(
count, specified_ext, parent, len(res)))
QCoreApplication.translate("QFieldFileUtils","Expected {expected_count} children with extension {file_extension} under {parent}, got {real_count}").format(
expected_count=count, file_extension=specified_ext, parent=parent, real_count=len(res)))

return res

Expand Down

0 comments on commit 27dc051

Please sign in to comment.