diff options
Diffstat (limited to 'tester/rt/tftpy/TftpShared.py')
-rw-r--r-- | tester/rt/tftpy/TftpShared.py | 52 |
1 files changed, 8 insertions, 44 deletions
diff --git a/tester/rt/tftpy/TftpShared.py b/tester/rt/tftpy/TftpShared.py index 6252ebd..88530c3 100644 --- a/tester/rt/tftpy/TftpShared.py +++ b/tester/rt/tftpy/TftpShared.py @@ -1,10 +1,9 @@ +# vim: ts=4 sw=4 et ai: +# -*- coding: utf8 -*- """This module holds all objects shared by all other modules in tftpy.""" -from __future__ import absolute_import, division, print_function, unicode_literals -import logging -from logging.handlers import RotatingFileHandler -LOG_LEVEL = logging.NOTSET + MIN_BLKSIZE = 8 DEF_BLKSIZE = 512 MAX_BLKSIZE = 65536 @@ -16,40 +15,6 @@ DEF_TFTP_PORT = 69 # A hook for deliberately introducing delay in testing. DELAY_BLOCK = 0 -# Initialize the logger. -logging.basicConfig() - -# The logger used by this library. Feel free to clobber it with your own, if -# you like, as long as it conforms to Python's logging. -log = logging.getLogger('tftpy') - -def create_streamhandler(): - """add create_streamhandler output logging.DEBUG msg to stdout. - """ - console = logging.StreamHandler() - console.setLevel(logging.INFO) - formatter = logging.Formatter('%(levelname)-8s %(message)s') - console.setFormatter(formatter) - return console - -def create_rotatingfilehandler(path, maxbytes=10*1024*1024, count=20): - """ - add create_rotatingfilehandler record the logging.DEBUG msg to logfile. you can change the maxsize (10*1024*1024) - and amount of the logfiles - """ - Rthandler = RotatingFileHandler(path, maxbytes, count) - Rthandler.setLevel(logging.INFO) - formatter = logging.Formatter('%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s') - Rthandler.setFormatter(formatter) - return Rthandler - -def addHandler(hdlr): - """add handler methods - More details see the page: - https://docs.python.org/2/library/logging.handlers.html#module-logging.handlers - """ - log.addHandler(hdlr) - def tftpassert(condition, msg): """This function is a simple utility that will check the condition passed for a false state. If it finds one, it throws a TftpException @@ -58,12 +23,6 @@ def tftpassert(condition, msg): if not condition: raise TftpException(msg) -def setLogLevel(level): - """This function is a utility function for setting the internal log level. - The log level defaults to logging.NOTSET, so unwanted output to stdout is - not created.""" - log.setLevel(level) - class TftpErrors(object): """This class is a convenience for defining the common tftp error codes, and making them more readable in the code.""" @@ -86,3 +45,8 @@ class TftpTimeout(TftpException): """This class represents a timeout error waiting for a response from the other end.""" pass + +class TftpFileNotFoundError(TftpException): + """This class represents an error condition where we received a file + not found error.""" + pass |