mirror of
https://github.com/upa/mscp.git
synced 2026-05-18 10:29:37 +08:00
fix mscp.py
This commit is contained in:
68
mscp/mscp.py
68
mscp/mscp.py
@@ -35,24 +35,24 @@ SEVERITY_NOTICE = pymscp.SEVERITY_NOTICE
|
|||||||
SEVERITY_INFO = pymscp.SEVERITY_INFO
|
SEVERITY_INFO = pymscp.SEVERITY_INFO
|
||||||
SEVERITY_DEBUG = pymscp.SEVERITY_DEBUG
|
SEVERITY_DEBUG = pymscp.SEVERITY_DEBUG
|
||||||
|
|
||||||
__STATE_INIT = 0
|
STATE_INIT = 0
|
||||||
__STATE_CONNECTED = 1
|
STATE_CONNECTED = 1
|
||||||
__STATE_PREPARED = 2
|
STATE_PREPARED = 2
|
||||||
__STATE_RUNNING = 3
|
STATE_RUNNING = 3
|
||||||
__STATE_STOPPED = 4
|
STATE_STOPPED = 4
|
||||||
__STATE_JOINED = 5
|
STATE_JOINED = 5
|
||||||
__STATE_CLEANED = 6
|
STATE_CLEANED = 6
|
||||||
__STATE_RELEASED = 7
|
STATE_RELEASED = 7
|
||||||
|
|
||||||
_state_str = {
|
_state_str = {
|
||||||
__STATE_INIT: "init",
|
STATE_INIT: "init",
|
||||||
__STATE_CONNECTED: "connected",
|
STATE_CONNECTED: "connected",
|
||||||
__STATE_PREPARED: "prepared",
|
STATE_PREPARED: "prepared",
|
||||||
__STATE_RUNNING: "running",
|
STATE_RUNNING: "running",
|
||||||
__STATE_STOPPED: "stopped",
|
STATE_STOPPED: "stopped",
|
||||||
__STATE_JOINED: "joined",
|
STATE_JOINED: "joined",
|
||||||
__STATE_CLEANED: "cleaned",
|
STATE_CLEANED: "cleaned",
|
||||||
__STATE_RELEASED: "released",
|
STATE_RELEASED: "released",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class mscp:
|
|||||||
|
|
||||||
self.src_paths = []
|
self.src_paths = []
|
||||||
self.dst_path = None
|
self.dst_path = None
|
||||||
self.state = __STATE_INIT
|
self.state = STATE_INIT
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "mscp:{}:{}".format(self.remote, self.__state2str())
|
return "mscp:{}:{}".format(self.remote, self.__state2str())
|
||||||
@@ -81,9 +81,9 @@ class mscp:
|
|||||||
if not hasattr(self, "state"):
|
if not hasattr(self, "state"):
|
||||||
return # this instance failed on mscp_init
|
return # this instance failed on mscp_init
|
||||||
|
|
||||||
if self.state == __STATE_RUNNING:
|
if self.state == STATE_RUNNING:
|
||||||
self.stop()
|
self.stop()
|
||||||
if self.state == __STATE_STOPPED:
|
if self.state == STATE_STOPPED:
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
@@ -94,10 +94,10 @@ class mscp:
|
|||||||
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
if not (self.state == __STATE_INIT or state.state == __STATE_CLEANED):
|
if not (self.state == STATE_INIT or state.state == STATE_CLEANED):
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
pymscp.mscp_connect(m = self.m)
|
pymscp.mscp_connect(m = self.m)
|
||||||
self.state = __STATE_CONNECTED
|
self.state = STATE_CONNECTED
|
||||||
|
|
||||||
def add_src_path(self, src_path: str):
|
def add_src_path(self, src_path: str):
|
||||||
self.src_paths.append(src_path)
|
self.src_paths.append(src_path)
|
||||||
@@ -108,7 +108,7 @@ class mscp:
|
|||||||
pymscp.mscp_set_dst_path(m = self.m, dst_path = dst_path);
|
pymscp.mscp_set_dst_path(m = self.m, dst_path = dst_path);
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
if self.state != __STATE_CONNECTED:
|
if self.state != STATE_CONNECTED:
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
if not self.src_paths:
|
if not self.src_paths:
|
||||||
raise RuntimeError("src path list is empty")
|
raise RuntimeError("src path list is empty")
|
||||||
@@ -116,45 +116,45 @@ class mscp:
|
|||||||
raise RuntimeError("dst path is not set")
|
raise RuntimeError("dst path is not set")
|
||||||
|
|
||||||
pymscp.mscp_prepare(m = self.m)
|
pymscp.mscp_prepare(m = self.m)
|
||||||
self.state = __STATE_PREPARED
|
self.state = STATE_PREPARED
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.state != __STATE_PREPARED:
|
if self.state != STATE_PREPARED:
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
|
|
||||||
pymscp.mscp_start(m = self.m)
|
pymscp.mscp_start(m = self.m)
|
||||||
self.state = __STATE_RUNNING
|
self.state = STATE_RUNNING
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.state != __STATE_RUNNING:
|
if self.state != STATE_RUNNING:
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
pymscp.mscp_stop(m = self.m)
|
pymscp.mscp_stop(m = self.m)
|
||||||
self.state = __STATE_STOPPED
|
self.state = STATE_STOPPED
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
if not (self.state == __STATE_RUNNING or self.state == __STATE_STOPPED):
|
if not (self.state == STATE_RUNNING or self.state == STATE_STOPPED):
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
pymscp.mscp_join(m = self.m)
|
pymscp.mscp_join(m = self.m)
|
||||||
self.state = __STATE_JOINED
|
self.state = STATE_JOINED
|
||||||
|
|
||||||
def stats(self):
|
def stats(self):
|
||||||
return pymscp.mscp_get_stats(m = self.m)
|
return pymscp.mscp_get_stats(m = self.m)
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
if self.state == __STATE_RUNNING:
|
if self.state == STATE_RUNNING:
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
pymscp.mscp_cleanup(m = self.m)
|
pymscp.mscp_cleanup(m = self.m)
|
||||||
self.state = __STATE_CLEANED
|
self.state = STATE_CLEANED
|
||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
if self.state != __STATE_CLEANED:
|
if self.state != STATE_CLEANED:
|
||||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||||
pymscp.mscp_free(m = self.m)
|
pymscp.mscp_free(m = self.m)
|
||||||
self.state = __STATE_RELEASED
|
self.state = STATE_RELEASED
|
||||||
|
|
||||||
# Simple interface: mscp.copy(src, dst)
|
# Simple interface: mscp.copy(src, dst)
|
||||||
def copy(self, src, dst, nonblock = False):
|
def copy(self, src, dst, nonblock = False):
|
||||||
if self.state < __STATE_CONNECTED:
|
if self.state < STATE_CONNECTED:
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
if type(src) == list:
|
if type(src) == list:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* for pymscp.
|
* for pymscp.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAX_MSCP_INSTS 16
|
#define MAX_MSCP_INSTS 64
|
||||||
|
|
||||||
/* XXX: cut corners */
|
/* XXX: cut corners */
|
||||||
struct instance {
|
struct instance {
|
||||||
|
|||||||
Reference in New Issue
Block a user