Add get_free_space() to core
This commit is contained in:
parent
f6d3c108f7
commit
5977647528
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue