summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMichael P. Soulier <msoulier@digitaltorque.ca>2018-05-15 11:58:51 -0400
committerMichael P. Soulier <msoulier@digitaltorque.ca>2018-05-15 11:58:51 -0400
commited6b6f1f66c99f04ba15a3eaa59b23f7cbf4fe3d (patch)
treed39e807a116641e301188ec05ebfed4e6ea59fbb /bin
parent57f9b0dc9da435f63fcb9ed3b9b050dc6717fa3e (diff)
downloadtftpy-ed6b6f1f66c99f04ba15a3eaa59b23f7cbf4fe3d.tar.gz
Rationalized module includes and logging.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tftpy_client.py31
-rwxr-xr-xbin/tftpy_server.py21
2 files changed, 35 insertions, 17 deletions
diff --git a/bin/tftpy_client.py b/bin/tftpy_client.py
index 2e3b92d..ab7d0b5 100755
--- a/bin/tftpy_client.py
+++ b/bin/tftpy_client.py
@@ -4,7 +4,15 @@ import sys, logging, os
from optparse import OptionParser
import tftpy
-logging.basicConfig()
+log = logging.getLogger('tftpy')
+log.setLevel(logging.INFO)
+
+# console handler
+handler = logging.StreamHandler()
+handler.setLevel(logging.DEBUG)
+default_formatter = logging.Formatter('[%(asctime)s] %(message)s')
+handler.setFormatter(default_formatter)
+log.addHandler(handler)
def main():
usage=""
@@ -77,20 +85,21 @@ def main():
self.out = out
def progresshook(self, pkt):
- if isinstance(pkt, tftpy.TftpPacketDAT):
+ if isinstance(pkt, tftpy.TftpPacketTypes.TftpPacketDAT):
self.progress += len(pkt.data)
self.out("Transferred %d bytes" % self.progress)
elif isinstance(pkt, tftpy.TftpPacketOACK):
self.out("Received OACK, options are: %s" % pkt.options)
if options.debug:
- tftpy.setLogLevel(logging.DEBUG)
+ log.setLevel(logging.DEBUG)
+ # increase the verbosity of the formatter
+ debug_formatter = logging.Formatter('[%(asctime)s%(msecs)03d] %(levelname)s [%(name)s:%(lineno)s] %(message)s')
+ handler.setFormatter(debug_formatter)
elif options.quiet:
- tftpy.setLogLevel(logging.WARNING)
- else:
- tftpy.setLogLevel(logging.INFO)
+ log.setLevel(logging.WARNING)
- progresshook = Progress(tftpy.log.info).progresshook
+ progresshook = Progress(log.info).progresshook
tftp_options = {}
if options.blksize:
@@ -98,10 +107,10 @@ def main():
if options.tsize:
tftp_options['tsize'] = 0
- tclient = tftpy.TftpClient(options.host,
- int(options.port),
- tftp_options,
- options.localip)
+ tclient = tftpy.TftpClient.TftpClient(options.host,
+ int(options.port),
+ tftp_options,
+ options.localip)
try:
if options.download:
if not options.output:
diff --git a/bin/tftpy_server.py b/bin/tftpy_server.py
index 89abb1e..d09d29f 100755
--- a/bin/tftpy_server.py
+++ b/bin/tftpy_server.py
@@ -4,7 +4,15 @@ import sys, logging
from optparse import OptionParser
import tftpy
-logging.basicConfig()
+log = logging.getLogger('tftpy')
+log.setLevel(logging.INFO)
+
+# console handler
+handler = logging.StreamHandler()
+handler.setLevel(logging.DEBUG)
+default_formatter = logging.Formatter('[%(asctime)s] %(message)s')
+handler.setFormatter(default_formatter)
+log.addHandler(handler)
def main():
usage=""
@@ -37,17 +45,18 @@ def main():
options, args = parser.parse_args()
if options.debug:
- tftpy.setLogLevel(logging.DEBUG)
+ log.setLevel(logging.DEBUG)
+ # increase the verbosity of the formatter
+ debug_formatter = logging.Formatter('[%(asctime)s%(msecs)03d] %(levelname)s [%(name)s:%(lineno)s] %(message)s')
+ handler.setFormatter(debug_formatter)
elif options.quiet:
- tftpy.setLogLevel(logging.WARN)
- else:
- tftpy.setLogLevel(logging.INFO)
+ log.setLevel(logging.WARN)
if not options.root:
parser.print_help()
sys.exit(1)
- server = tftpy.TftpServer(options.root)
+ server = tftpy.TftpServer.TftpServer(options.root)
try:
server.listen(options.ip, options.port)
except tftpy.TftpException as err: