def __init__(self, address, client): self.client = client FileServer.__init__(self, address, tempfile.gettempdir()) (_, self.port) = address for command in RemoteBundleClient.CLIENT_COMMANDS: self.register_function(getattr(self.client, command), command) for command in self.SERVER_COMMANDS: self.register_function(getattr(self, command), command)
def __init__(self, manager): self.host = manager.config['server']['host'] self.port = manager.config['server']['port'] self.verbose = manager.config['server']['verbose'] # This server is backed by a LocalBundleClient that processes client commands self.client = manager.client('local', is_cli=False) # args might be a large object; summarize it (e.g., take prefixes of lists) def compress_args(args): if isinstance(args, basestring): if len(args) > 100: args = args[:100] + '...' if isinstance(args, list): if len(args) > 4: args = args[:4] + ['...'] if isinstance(args, tuple): return tuple(map(compress_args, args)) elif isinstance(args, list): return map(compress_args, args) elif isinstance(args, dict): return dict((compress_args(k), compress_args(v)) for k, v in args.items()) return args tempdir = tempfile.gettempdir( ) # Consider using CodaLab's temp directory FileServer.__init__(self, (self.host, self.port), tempdir, manager.auth_handler()) def wrap(command, func): def inner(*args, **kwargs): if command == 'login': log_args = args[:2] # Don't log password else: log_args = compress_args(args) if self.verbose >= 1: print "bundle_rpc_server: %s %s" % (command, log_args) try: start_time = time.time() result = func(*args, **kwargs) # Log this activity. self.client.model.update_events_log( start_time=start_time, user_id=self.client._current_user_id(), user_name=self.client._current_user_name(), command=command, args=log_args) return result except Exception, e: if not (isinstance(e, UsageError) or isinstance(e, PermissionError)): # This is really bad and shouldn't happen. # If it does, someone should get paged. print '=== INTERNAL ERROR:', e traceback.print_exc() raise e return inner
def __init__(self, manager): self.host = manager.config['server']['host'] self.port = manager.config['server']['port'] self.client = manager.client('local') FileServer.__init__(self, (self.host, self.port), tempfile.gettempdir(), manager.auth_handler()) for command in RemoteBundleClient.CLIENT_COMMANDS: self.register_function(getattr(self.client, command), command) for command in self.SERVER_COMMANDS: self.register_function(getattr(self, command), command)
def __init__(self, manager): self.host = manager.config['server']['host'] self.port = manager.config['server']['port'] self.verbose = manager.config['server']['verbose'] # This server is backed by a LocalBundleClient that processes client commands self.client = manager.client('local', is_cli=False) # args might be a large object; summarize it (e.g., take prefixes of lists) def compress_args(args): if isinstance(args, basestring): if len(args) > 100: args = args[:100] + '...' if isinstance(args, list): if len(args) > 4: args = args[:4] + ['...'] if isinstance(args, tuple): return tuple(map(compress_args, args)) elif isinstance(args, list): return map(compress_args, args) elif isinstance(args, dict): return dict((compress_args(k), compress_args(v)) for k, v in args.items()) return args tempdir = tempfile.gettempdir() # Consider using CodaLab's temp directory FileServer.__init__(self, (self.host, self.port), tempdir, manager.auth_handler()) def wrap(command, func): def inner(*args, **kwargs): if command == 'login': log_args = args[:2] # Don't log password else: log_args = compress_args(args) if self.verbose >= 1: print "bundle_rpc_server: %s %s" % (command, log_args) try: start_time = time.time() result = func(*args, **kwargs) # Log this activity. self.client.model.update_events_log( start_time=start_time, user_id=self.client._current_user_id(), user_name=self.client._current_user_name(), command=command, args=log_args) return result except Exception, e: if not (isinstance(e, UsageError) or isinstance(e, PermissionError)): # This is really bad and shouldn't happen. # If it does, someone should get paged. print '=== INTERNAL ERROR:', e traceback.print_exc() raise e return inner
def __init__(self, manager): self.host = manager.config['server']['host'] self.port = manager.config['server']['port'] self.verbose = manager.config['server']['verbose'] # This server is backed by a LocalBundleClient that processes client commands self.client = manager.client('local', is_cli=False) tempdir = tempfile.gettempdir() # Consider using CodaLab's temp directory FileServer.__init__(self, (self.host, self.port), tempdir, manager.auth_handler()) def wrap(command, func): def inner(*args, **kwargs): if self.verbose >= 1: print "bundle_rpc_server: %s %s" % (command, args if command != 'login' else '...') try: return func(*args, **kwargs) except Exception, e: if not (isinstance(e, UsageError) or isinstance(e, PermissionError)): # This is really bad and shouldn't happen. # If it does, someone should get paged. print '=== INTERNAL ERROR:', e traceback.print_exc() raise e return inner
def serve_forever(self): print 'BundleRPCServer serving to %s at port %s...' % ( 'ALL hosts' if self.host == '' else 'host ' + self.host, self.port) FileServer.serve_forever(self)
def serve_forever(self): print 'BundleRPCServer serving to %s at port %s...' % ('ALL hosts' if self.host == '' else 'host ' + self.host, self.port) FileServer.serve_forever(self)
def serve_forever(self): print 'BundleRPCServer serving at port %s...' % (self.port,) FileServer.serve_forever(self)
def __init__(self, manager): self.host = manager.config['server']['host'] self.port = manager.config['server']['port'] self.verbose = manager.config['server']['verbose'] self.download_manager = manager.download_manager() self.auth_handler = manager.auth_handler() # This server is backed by a LocalBundleClient that processes client commands self.client = manager.client('local', is_cli=False) # This server is backed by a file server that processes file commands. self.file_server = FileServer() # args might be a large object; summarize it (e.g., take prefixes of lists) def compress_args(args): if isinstance(args, basestring): if len(args) > 100: args = args[:100] + '...' if isinstance(args, list): if len(args) > 4: args = args[:4] + ['...'] if isinstance(args, tuple): return tuple(map(compress_args, args)) elif isinstance(args, list): return map(compress_args, args) elif isinstance(args, dict): return dict((compress_args(k), compress_args(v)) for k, v in args.items()) return args SimpleXMLRPCServer.__init__( self, (self.host, self.port), allow_none=True, requestHandler=AuthenticatedXMLRPCRequestHandler, logRequests=(self.verbose >= 1)) def wrap(target, command): def function_to_register(*args, **kwargs): # Process args for logging if command == 'login': log_args = args[:2] # Don't log password else: log_args = compress_args(args) if self.verbose >= 1: print "bundle_rpc_server: %s %s" % (command, log_args) try: start_time = time.time() # Dynamically bind method and call it result = getattr(target, command)(*args, **kwargs) # Log this activity. if not isinstance(target, FileServer): self.client.model.update_events_log( start_time=start_time, user_id=self.client._current_user_id(), user_name=self.client._current_user_name(), command=command, args=log_args) return result except Exception, e: if not (isinstance(e, UsageError) or isinstance(e, PermissionError)): # This is really bad and shouldn't happen. # If it does, someone should get paged. print '=== INTERNAL ERROR:', e traceback.print_exc() raise e return function_to_register