Skip to content

Commit

Permalink
admin.py: handle errors in getdirsize
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmoore committed Dec 2, 2019
1 parent 14d60b3 commit fc93e6a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/omero/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,10 +1549,20 @@ def email(self, args):
cb.close(True)

def getdirsize(self, directory):
"""
Uses os.walk to calculate the deep size of the given
directory. If a directory disappears during calculation,
an error will be printed to stderr, but the calculation
will continue.
"""
total = 0
for values in os.walk(directory):
for filename in values[2]:
total += os.path.getsize(os.path.join(values[0], filename))
fullpath = os.path.join(values[0], filename)
try:
total += os.path.getsize(fullpath)
except Exception:
self.ctx.error("Failed to get size of: %s" % fullpath)
return total

def session_manager(self, communicator):
Expand Down

0 comments on commit fc93e6a

Please sign in to comment.