diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2009-08-07 10:58:27 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2009-08-07 10:58:27 +0200 |
commit | 417ecf4be0c01159bd464d1264cae24f91bf023b (patch) | |
tree | 115fbbcc05add490721f1d07809f71d3431ef14d | |
parent | 29fbb301a61d85214a0de76b7308ffb7d9c9fd96 (diff) | |
download | logilab-common-417ecf4be0c01159bd464d1264cae24f91bf023b.tar.gz |
more deprecated modules
-rw-r--r-- | logservice.py | 37 | ||||
-rw-r--r-- | monclient.py | 68 | ||||
-rw-r--r-- | monserver.py | 123 |
3 files changed, 0 insertions, 228 deletions
diff --git a/logservice.py b/logservice.py deleted file mode 100644 index 5a06a1d..0000000 --- a/logservice.py +++ /dev/null @@ -1,37 +0,0 @@ -"""Log utilities. - -:copyright: 2000-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: General Public License version 2 - http://www.gnu.org/licenses - -# FIXME using logging instead -""" -__docformat__ = "restructuredtext en" - -from warnings import warn -warn('logservice module is deprecated and will disappear in a near release. \ -use logging module instead.', - DeprecationWarning, stacklevel=2) - -from logilab.common.logger import make_logger, LOG_ERR, LOG_WARN, LOG_NOTICE, \ - LOG_INFO, LOG_CRIT, LOG_DEBUG - -def init_log(treshold, method='eprint', sid='common-log-service', - logger=None, output=None): - """init the logging system and and log methods to builtins""" - if logger is None: - logger = make_logger(method, treshold, sid, output=output) - # add log functions and constants to builtins - __builtins__.update({'log': logger.log, - 'log_traceback' : logger.log_traceback, - 'LOG_CRIT': LOG_CRIT, - 'LOG_ERR': LOG_ERR, - 'LOG_WARN': LOG_WARN, - 'LOG_NOTICE': LOG_NOTICE, - 'LOG_INFO' : LOG_INFO, - 'LOG_DEBUG': LOG_DEBUG, - }) - -init_log(LOG_ERR) - - diff --git a/monclient.py b/monclient.py deleted file mode 100644 index 6124db4..0000000 --- a/monclient.py +++ /dev/null @@ -1,68 +0,0 @@ -"""Simple interpreter client for monserver provides a simple readline interface. - -:copyright: 2000-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: General Public License version 2 - http://www.gnu.org/licenses -""" -__docformat__ = "restructuredtext en" - -from warnings import warn -warn('this module is deprecated and will disappear in a near release', - DeprecationWarning, stacklevel=1) - -from socket import socket, SOCK_STREAM, AF_INET -from select import select -import sys -import readline -import threading - -class SocketPrinter(threading.Thread): - """A thread that reads from a socket and output - to stdout as data are received""" - def __init__(self, sock): - threading.Thread.__init__(self) - self.socket = sock - self.stop = False - - def run(self): - """prints socket input indefinitely""" - fd = self.socket.fileno() - self.socket.setblocking(0) - while not self.stop: - iwl, _, _ = select([fd], [], [], 2) - if fd in iwl: - data = self.socket.recv(100) - if data: - sys.stdout.write(data) - sys.stdout.flush() - - - -def client( host, port ): - """simple client that just sends input to the server""" - sock = socket( AF_INET, SOCK_STREAM ) - sock.connect( (host, port) ) - sp_thread = SocketPrinter(sock) - sp_thread.start() - while 1: - try: - line = raw_input() + "\n" - sock.send( line ) - except EOFError: - print "Bye" - break - except: - sp_thread.stop = True - sp_thread.join() - raise - sp_thread.stop = True - sp_thread.join() - - -if __name__ == "__main__": - server_host = sys.argv[1] - server_port = int(sys.argv[2]) - client(server_host, server_port) - - - diff --git a/monserver.py b/monserver.py deleted file mode 100644 index 6fcdebf..0000000 --- a/monserver.py +++ /dev/null @@ -1,123 +0,0 @@ -# -*- coding: utf-8 -*- -"""A TCP server implemented in a separate thread that -allows *one* client to connect and provides a command line interpreter -allowing the remote client to explore the process on the fly. - -:copyright: 2000-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: General Public License version 2 - http://www.gnu.org/licenses -""" -__docformat__ = "restructuredtext en" - -from warnings import warn -warn('this module is deprecated and will disappear in a near release', - DeprecationWarning, stacklevel=1) - -import threading -import SocketServer -import traceback -import code -import sys -import time - -# NOTES: ce module étant utilisé pour l'introspection, il peut -# être utile de fournir dans les locales de l'interpreteur des -# objets déjà initialisés (par exemple le module __main__ ou -# bien __main__.*) ou encore des objets servant à l'introspection -# comme on en trouve dans pymonitor (qui prend la liste des objets -# maintenus par le garbage collector) ou a des statistiques -# pour faire des opérations du style: -# inspector.count_types( MyClass ) -# inspector.list_types( MyClass ) etc... - -class MonitorInterpreter(code.InteractiveConsole): - """Subclasses InteractiveConsole so that all inputs - and outputs are done through a socket""" - def __init__(self, rfile, wfile ): - code.InteractiveConsole.__init__(self) - self.wfile = wfile - self.rfile = rfile - sys.stdout = self.wfile - sys.stderr = self.wfile - - def write(self, data): - """replace stderr output by writing to wfile""" - self.wfile.write( data ) - self.wfile.flush() - - def raw_input( self, prompt = None ): - """Provides reading lines through the network""" - if prompt is not None: - self.wfile.write(prompt) - self.wfile.flush() - line = self.rfile.readline() - if line.endswith("\r\n"): - line = line[:-2] - elif line.endswith("\n"): - line = line[:-1] - return line - - -class MonitorRequestHandler(SocketServer.BaseRequestHandler): - """Request handler for remote interpreter""" - def __init__(self, request, clientaddress, server ): - self.locals = {} - self.globals = globals().copy() - self.wfile = request.makefile("w") - self.rfile = request.makefile("r") - SocketServer.BaseRequestHandler.__init__(self, request, clientaddress, - server ) - - def handle(self): - """handle on request, through MonitorInterpreter""" - saved_stdout = sys.stdout - saved_stderr = sys.stderr - interpreter = MonitorInterpreter(self.rfile, self.wfile) - try: - interpreter.interact() - except KeyboardInterrupt: - self.server.exit = True - except: - sys.stdout = saved_stdout - sys.stderr = saved_stderr - traceback.print_exc() - print "Monitor handler exited" - -class Monitor(threading.Thread): - """Monitor server. monothreaded we only - allow one client at a time""" - def __init__(self, host, port): - threading.Thread.__init__(self) - self.host = host - self.port = port - self.exit = False - - - def run(self): - """run the server loop""" - server = SocketServer.TCPServer( (self.host, self.port), - MonitorRequestHandler ) - while not self.exit: - server.handle_request() - - - -def demo_forever(): - """sample demo server that outputs - numbers on screen""" - cnt = 1 - while 1: - print cnt - time.sleep(2) - cnt += 1 - -if __name__ == "__main__": - listen_port = int(sys.argv[1]) - mon = Monitor( "", listen_port ) - mon.start() - try: - demo_forever() - except Exception: - traceback.print_exc() - mon.exit = True - mon.join() |