import os
[docs]class DiskServer(object):
def __init__(self, utup, roots):
"""
utup: unique tuple ID
roots: dict(name => absolutepath)
"""
self.utup = utup
self.roots = roots
self.baseroot = os.getcwd()
[docs] def splitpath(self, path):
if path is None:
return None, None
if len(path) > 0 and path[0] == '/':
return None, path
if '/' not in path:
return path, None
return path[:path.index('/')], path[path.index('/')+1:]
[docs] def fullpath(self, path):
if path is None:
return None
root, path = self.splitpath(path)
if root is None:
return path
if path is None:
return os.path.join(self.baseroot, self.roots[root])
return os.path.normpath(os.path.join(self.baseroot, self.roots[root], path))
[docs]class SizelessServer(DiskServer):
def __init__(self, utup, cpus, roots):
"""
utup: unique tuple ID
cpus: integer
roots: dict(name => absolutepath)
"""
super(SizelessServer, self).__init__(utup, roots)
self.cpus = cpus
[docs] def push_disk(self, path, localds):
"""
path: subdirectory
local: local DiskServer
"""
raise NotImplementedError()
[docs] def pull_disk(self, path, localds):
"""
path: subdirectory
local: local DiskServer
"""
raise NotImplementedError()
[docs] def list_disk(self, path):
"""
path: subdirectory
"""
raise NotImplementedError()
[docs] def has_file(self, filepath):
"""
path: subdirectory
"""
basename = os.path.basename(filepath)
for filename in self.list_disk(os.path.dirname(filepath)):
if filename == basename:
return True
return False
[docs] def read_file(self, filepath):
"Returns string."
raise NotImplementedError()
[docs] def start_process(self, command, path=None):
"Returns process."
raise NotImplementedError()
[docs] def run_command(self, command, path=None):
"Returns (output, error) as strings."
raise NotImplementedError()
[docs]class SizelessConnectableServer(SizelessServer):
def __init__(self, utup, cpus, roots, credentials):
super(SizelessConnectableServer, self).__init__(utup, cpus, roots)
self.connected = False
self.credentials = credentials
[docs] def check_connection(self):
raise NotImplementedError()
[docs] def connect(self):
raise NotImplementedError()
[docs] def disconnect(self):
raise NotImplementedError()