Add 'get_path_size' core method
This commit is contained in:
parent
f8c9d5f7ca
commit
aec7f35a71
|
@ -369,4 +369,18 @@ def create_magnet_uri(infohash, name=None, trackers=[]):
|
||||||
|
|
||||||
return uri
|
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
|
||||||
|
|
|
@ -641,6 +641,11 @@ class Core(
|
||||||
"""Returns True if we have established incoming connections"""
|
"""Returns True if we have established incoming connections"""
|
||||||
return self.session.status().has_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 ##
|
## Queueing functions ##
|
||||||
def export_queue_top(self, torrent_ids):
|
def export_queue_top(self, torrent_ids):
|
||||||
log.debug("Attempting to queue %s to top", torrent_ids)
|
log.debug("Attempting to queue %s to top", torrent_ids)
|
||||||
|
|
Loading…
Reference in New Issue