diff --git a/deluge/core/core.py b/deluge/core/core.py index 36d41b744..693aa7e05 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -803,3 +803,19 @@ class Core(component.Component): return 0 else: return int(status) + + @export + def get_free_space(self, path): + """ + Returns the number of free bytes at path + + :param path: the path to check free space at + :type path: string + + :returns: the number of free bytes at path + :rtype: int + + :raises InvalidPathError: if the path is invalid + + """ + return deluge.common.free_space(path) diff --git a/deluge/error.py b/deluge/error.py index 86593477c..24c1e8352 100644 --- a/deluge/error.py +++ b/deluge/error.py @@ -35,10 +35,7 @@ class DelugeError(Exception): - def __init__(self, value): - self.value = value - def __str__(self): - return repr(self.value) + pass class NoCoreError(DelugeError): pass @@ -48,3 +45,6 @@ class DaemonRunningError(DelugeError): class InvalidTorrentError(DelugeError): pass + +class InvalidPathError(DelugeError): + pass diff --git a/tests/test_core.py b/tests/test_core.py index 0658cb4d0..70ade8246 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -11,6 +11,7 @@ import common from deluge.core.rpcserver import RPCServer from deluge.core.core import Core import deluge.component as component +import deluge.error class CoreTestCase(unittest.TestCase): def setUp(self): @@ -75,7 +76,6 @@ class CoreTestCase(unittest.TestCase): import base64 torrent_id = self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options) - import deluge.error self.assertRaises(deluge.error.InvalidTorrentError, self.core.remove_torrent, "torrentidthatdoesntexist", True) ret = self.core.remove_torrent(torrent_id, True) @@ -93,4 +93,11 @@ class CoreTestCase(unittest.TestCase): self.assertEquals(type(status), dict) self.assertEquals(status["write_hit_ratio"], 0.0) self.assertEquals(status["read_hit_ratio"], 0.0) - + + def test_get_free_space(self): + space = self.core.get_free_space(".") + self.assertTrue(type(space) == int) + self.assertTrue(space >= 0) + self.assertRaises(deluge.error.InvalidPathError, self.core.get_free_space, "/someinvalidpath") + +