diff --git a/deluge/common.py b/deluge/common.py index d5b848947..2ca04a782 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -368,5 +368,19 @@ def create_magnet_uri(infohash, name=None, trackers=[]): uri = uri + "&tr=" + t return uri - +def get_path_size(path): + """Returns the size in bytes of 'path'. If path does not exist, then -1 is + returned.""" + if not os.path.exists(path): + return -1 + + if os.path.isfile(path): + return os.path.getsize(path) + + dir_size = 0 + for (p, dirs, files) in os.walk(path): + for file in files: + filename = os.path.join(p, file) + dir_size += os.path.getsize(filename) + return dir_size diff --git a/deluge/core/core.py b/deluge/core/core.py index dccb2754b..cf8e0bf03 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -641,6 +641,11 @@ class Core( """Returns True if we have established incoming connections""" return self.session.status().has_incoming_connections + def export_get_path_size(self, path): + """Returns the size of the file or folder 'path' and -1 if the path is + unaccessible (non-existent or insufficient privs)""" + return deluge.common.get_path_size(path) + ## Queueing functions ## def export_queue_top(self, torrent_ids): log.debug("Attempting to queue %s to top", torrent_ids)