Add 'get_path_size' core method

This commit is contained in:
Andrew Resch 2008-09-20 02:27:29 +00:00
parent f8c9d5f7ca
commit aec7f35a71
2 changed files with 20 additions and 1 deletions

View File

@ -369,4 +369,18 @@ def create_magnet_uri(infohash, name=None, trackers=[]):
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

View File

@ -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)