Beispiel #1
0
 def test_enable_logging(self):
     tftpy.log.addHandler = MagicMock()
     logging.FileHandler = MagicMock()
     tftpy.setLogLevel(0)
     self.assertEqual(tftpy.log.level, 0)
     self.client.enable_logging()
     self.assertEqual(tftpy.log.level, 20)
     tftpy.setLogLevel(0)
Beispiel #2
0
    def __init__(self, ip_address, port=69, verbose=False):
        """Default constructor for this the ExternalTftp class."""
        self.ip_address = ip_address
        self.port = port
        self.verbose = verbose

        if not self.verbose:
            setLogLevel(logging.CRITICAL)
Beispiel #3
0
    def __init__(self, ip_address, port=69, verbose=False):
        """Default constructor for this the ExternalTftp class."""
        self.ip_address = ip_address
        self.port = port
        self.verbose = verbose

        if not self.verbose:
            setLogLevel(logging.CRITICAL)
Beispiel #4
0
 def test_set_logging(self):
     tftpy.log.addHandler = MagicMock()
     logging.FileHandler = MagicMock()
     tftpy.setLogLevel(0)
     self.assertEqual(tftpy.log.level, 0)
     Server.set_logging(os.getcwd(), 'ERROR')
     self.assertEqual(tftpy.log.level, 40)
     tftpy.setLogLevel(0)
Beispiel #5
0
 def enable_logging():
     """
         Enables logging for the tftpy module.
     """
     tftpy.setLogLevel('INFO')
     fh = logging.FileHandler(os.getcwd() + '/logging/log_client_' +
                              time.strftime('%d-%m-%Y_%H:%M:%S'))
     formatter = logging.Formatter(
         '%(asctime)s - %(levelname)s - %(message)s')
     fh.setFormatter(formatter)
     tftpy.log.addHandler(fh)
Beispiel #6
0
def main():
    usage=""
    parser = OptionParser(usage=usage)
    parser.add_option('-i',
                      '--ip',
                      type='string',
                      help='ip address to bind to (default: INADDR_ANY)',
                      default="")
    parser.add_option('-p',
                      '--port',
                      type='int',
                      help='local port to use (default: 69)',
                      default=69)
    parser.add_option('-r',
                      '--root',
                      type='string',
                      help='path to serve from',
                      default=None)
    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      default=False,
                      help='upgrade logging from info to debug')
    options, args = parser.parse_args()

    if options.debug:
        tftpy.setLogLevel(logging.DEBUG)
    else:
        tftpy.setLogLevel(logging.INFO)

    if not options.root:
        parser.print_help()
        sys.exit(1)

    server = tftpy.TftpServer(options.root)
    try:
        server.listen(options.ip, options.port)
    except tftpy.TftpException as err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
    except KeyboardInterrupt:
        pass
Beispiel #7
0
def main():
    usage = ""
    parser = OptionParser(usage=usage)
    parser.add_option('-i',
                      '--ip',
                      type='string',
                      help='ip address to bind to (default: INADDR_ANY)',
                      default="")
    parser.add_option('-p',
                      '--port',
                      type='int',
                      help='local port to use (default: 69)',
                      default=69)
    parser.add_option('-r',
                      '--root',
                      type='string',
                      help='path to serve from',
                      default=None)
    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      default=False,
                      help='upgrade logging from info to debug')
    options, args = parser.parse_args()

    if options.debug:
        tftpy.setLogLevel(logging.DEBUG)
    else:
        tftpy.setLogLevel(logging.INFO)

    if not options.root:
        parser.print_help()
        sys.exit(1)

    server = tftpy.TftpServer(options.root)
    try:
        server.listen(options.ip, options.port)
    except tftpy.TftpException, err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
Beispiel #8
0
 def run(self):
     """ Run the server. Listens indefinitely. """
     if not self.verbose:
         setLogLevel(logging.CRITICAL)
     self.server.listen(listenport=self.port)
Beispiel #9
0
def set_log_level(level):
    tftpy.setLogLevel(level)
Beispiel #10
0
 def run(self):
     """ Run the server. Listens indefinitely. """
     if not self.verbose:
         setLogLevel(logging.CRITICAL)
     self.server.listen(listenport=self.port)
Beispiel #11
0
def main():
    usage = ""
    parser = OptionParser(usage=usage)
    parser.add_option('-H',
                      '--host',
                      action='store',
                      dest='host',
                      help='remote host or ip address')
    parser.add_option('-p',
                      '--port',
                      action='store',
                      dest='port',
                      help='remote port to use (default: 69)',
                      default=69)
    parser.add_option('-f',
                      '--filename',
                      action='store',
                      dest='filename',
                      help='filename to fetch')
    parser.add_option('-b',
                      '--blocksize',
                      action='store',
                      dest='blocksize',
                      help='udp packet size to use (default: 512)',
                      default=512)
    parser.add_option('-o',
                      '--output',
                      action='store',
                      dest='output',
                      help='output file (default: same as requested filename)')
    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      dest='debug',
                      default=False,
                      help='upgrade logging from info to debug')
    parser.add_option('-q',
                      '--quiet',
                      action='store_true',
                      dest='quiet',
                      default=False,
                      help="downgrade logging from info to warning")
    options, args = parser.parse_args()
    if not options.host or not options.filename:
        sys.stderr.write("Both the --host and --filename options "
                         "are required.\n")
        parser.print_help()
        sys.exit(1)

    if options.debug and options.quiet:
        sys.stderr.write("The --debug and --quiet options are "
                         "mutually exclusive.\n")
        parser.print_help()
        sys.exit(1)

    if not options.output:
        options.output = os.path.basename(options.filename)

    class Progress(object):
        def __init__(self, out):
            self.progress = 0
            self.out = out

        def progresshook(self, pkt):
            self.progress += len(pkt.data)
            self.out("Downloaded %d bytes" % self.progress)

    if options.debug:
        tftpy.setLogLevel(logging.DEBUG)
    elif options.quiet:
        tftpy.setLogLevel(logging.WARNING)
    else:
        tftpy.setLogLevel(logging.INFO)

    progresshook = Progress(tftpy.logger.info).progresshook

    tftp_options = {}
    if options.blocksize:
        tftp_options['blksize'] = int(options.blocksize)

    tclient = tftpy.TftpClient(options.host, int(options.port), tftp_options)

    tclient.download(options.filename, options.output, progresshook)
Beispiel #12
0
import logging
import struct
import time
import tftpy
from StringIO import StringIO

from transport import Transport

__author__ = 'jackh'
__date__ = 'June 2017'

LOGGER = logging.getLogger(__name__)
tftpy.setLogLevel(logging.ERROR)

def set_log_level(level):
    tftpy.setLogLevel(level)

def get_log_level():
    return tftpy.log.level

def get_core_info_payload(payload_str):
    x = struct.unpack('>LLB', payload_str)
    rw      = x[0] & 0x3
    addr    = x[0] & 0xfffffffa
    size    = x[1]
    typenum = x[2]
    return {'rw' : rw, 'addr' : addr, 'size' : size, 'typenum' : typenum}


def decode_csl_pl(csl):
    OFFSET = 2 # ???
Beispiel #13
0
        error("Switch", ip,
              "does not match regexp, invalid option 82? Received ", option82,
              " as option 82")
        return None

    f = tempfile.TemporaryFile()
    if context.file_to_transfer.lower().endswith("-confg"):
        log("Generating config for", ip, "config =", switch)
        if generate(f, ip, switch) == None:
            return None
    else:
        error("Switch", ip, "config =", switch, "tried to get file",
              context.file_to_transfer)
        f.close()
        return None

    f.seek(0)
    return f


log("swtftpd started")
tftpy.setLogLevel(logging.WARNING)
server = tftpy.TftpServer(file_callback)
try:
    server.listen("10.0.13.2", 69)
except tftpy.TftpException, err:
    sys.stderr.write("%s\n" % str(err))
    sys.exit(1)
except KeyboardInterrupt:
    pass
Beispiel #14
0
 def setUp(self):
     tftpy.setLogLevel(logging.DEBUG)
Beispiel #15
0
import gtk
import math
import time
from gtk import gdk
import cairo   

# CORBA related libraries
import CORBA
import CosNaming

# IDL generated library
import RenderFarm
import RenderFarm__POA

# GLOBALS
tftpy.setLogLevel(logging.INFO)
PATH_TO_BLENDER = 'c:\\temp\\blender'

###############################################################################
# Class : GUI_RenderClient
# This class is responsible for creating and handling the GUI for the 
# RenderClient.
###############################################################################

gtk.gdk.threads_init()
	
class GUI_RenderClient( ):
	
	##
	# Constructor. Creates the widgets for the GUI of the RenderClient. 
	# @param	oRenderServer	RenderServer object that is controlling the renderfarm
Beispiel #16
0
 def setUp(self):
     tftpy.setLogLevel(logging.DEBUG)
Beispiel #17
0
def main():
    usage = ""
    parser = OptionParser(usage=usage)
    parser.add_option('-H', '--host', help='remote host or ip address')
    parser.add_option('-p',
                      '--port',
                      help='remote port to use (default: 69)',
                      default=69)
    parser.add_option('-f',
                      '--filename',
                      help='filename to fetch (deprecated, use download)')
    parser.add_option('-D', '--download', help='filename to download')
    parser.add_option('-u', '--upload', help='filename to upload')
    parser.add_option('-b',
                      '--blksize',
                      help='udp packet size to use (default: 512)')
    parser.add_option(
        '-o',
        '--output',
        help='output file, - for stdout (default: same as download)')
    parser.add_option('-i',
                      '--input',
                      help='input file, - for stdin (default: same as upload)')
    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      default=False,
                      help='upgrade logging from info to debug')
    parser.add_option('-q',
                      '--quiet',
                      action='store_true',
                      default=False,
                      help="downgrade logging from info to warning")
    parser.add_option('-t',
                      '--tsize',
                      action='store_true',
                      default=False,
                      help="ask client to send tsize option in download")
    parser.add_option('-l',
                      '--localip',
                      action='store',
                      dest='localip',
                      default="",
                      help='local IP for client to bind to (ie. interface)')
    options, args = parser.parse_args()
    # Handle legacy --filename argument.
    if options.filename:
        options.download = options.filename
    if not options.host or (not options.download and not options.upload):
        sys.stderr.write("Both the --host and --filename options "
                         "are required.\n")
        parser.print_help()
        sys.exit(1)

    if options.debug and options.quiet:
        sys.stderr.write("The --debug and --quiet options are "
                         "mutually exclusive.\n")
        parser.print_help()
        sys.exit(1)

    class Progress(object):
        def __init__(self, out):
            self.progress = 0
            self.out = out

        def progresshook(self, pkt):
            if isinstance(pkt, tftpy.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)
    elif options.quiet:
        tftpy.setLogLevel(logging.WARNING)
    else:
        tftpy.setLogLevel(logging.INFO)

    progresshook = Progress(tftpy.log.info).progresshook

    tftp_options = {}
    if options.blksize:
        tftp_options['blksize'] = int(options.blksize)
    if options.tsize:
        tftp_options['tsize'] = 0

    tclient = tftpy.TftpClient(options.host, int(options.port), tftp_options,
                               options.localip)
    try:
        if options.download:
            if not options.output:
                options.output = os.path.basename(options.download)
            tclient.download(options.download, options.output, progresshook)
        elif options.upload:
            if not options.input:
                options.input = os.path.basename(options.upload)
            tclient.upload(options.upload, options.input, progresshook)
    except tftpy.TftpException, err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
Beispiel #18
0
def main():
    usage=""
    parser = OptionParser(usage=usage)
    parser.add_option('-H',
                      '--host',
                      action='store',
                      dest='host',
                      help='remote host or ip address')
    parser.add_option('-p',
                      '--port',
                      action='store',
                      dest='port',
                      help='remote port to use (default: 69)',
                      default=69)
    parser.add_option('-f',
                      '--filename',
                      action='store',
                      dest='filename',
                      help='filename to fetch')
    parser.add_option('-b',
                      '--blocksize',
                      action='store',
                      dest='blocksize',
                      help='udp packet size to use (default: 512)',
                      default=512)
    parser.add_option('-o',
                      '--output',
                      action='store',
                      dest='output',
                      help='output file (default: same as requested filename)')
    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      dest='debug',
                      default=False,
                      help='upgrade logging from info to debug')
    parser.add_option('-q',
                      '--quiet',
                      action='store_true',
                      dest='quiet',
                      default=False,
                      help="downgrade logging from info to warning")
    options, args = parser.parse_args()
    if not options.host or not options.filename:
        sys.stderr.write("Both the --host and --filename options "
                         "are required.\n")
        parser.print_help()
        sys.exit(1)

    if options.debug and options.quiet:
        sys.stderr.write("The --debug and --quiet options are "
                         "mutually exclusive.\n")
        parser.print_help()
        sys.exit(1)

    if not options.output:
        options.output = os.path.basename(options.filename)

    class Progress(object):
        def __init__(self, out):
            self.progress = 0
            self.out = out
        def progresshook(self, pkt):
            self.progress += len(pkt.data)
            self.out("Downloaded %d bytes" % self.progress)

    if options.debug:
        tftpy.setLogLevel(logging.DEBUG)
    elif options.quiet:
        tftpy.setLogLevel(logging.WARNING)
    else:
        tftpy.setLogLevel(logging.INFO)

    progresshook = Progress(tftpy.logger.info).progresshook

    tftp_options = {}
    if options.blocksize:
        tftp_options['blksize'] = int(options.blocksize)

    tclient = tftpy.TftpClient(options.host,
                               int(options.port),
                               tftp_options)

    tclient.download(options.filename,
                     options.output,
                     progresshook)
Beispiel #19
0
import logging
import struct
import time
import tftpy
from StringIO import StringIO
import zlib
import hashlib

from transport import Transport

__author__ = 'jackh'
__date__ = 'June 2017'

LOGGER = logging.getLogger(__name__)
tftpy.setLogLevel(logging.CRITICAL)


def set_log_level(level):
    tftpy.setLogLevel(level)


def get_log_level():
    return tftpy.log.level


def get_core_info_payload(payload_str):
    x = struct.unpack('>LLB', payload_str)
    rw = x[0] & 0x3
    addr = x[0] & 0xfffffffa
    size = x[1]
    typenum = x[2]
Beispiel #20
0
def main():
    usage=""
    parser = OptionParser(usage=usage)
    parser.add_option('-H',
                      '--host',
                      help='remote host or ip address')
    parser.add_option('-p',
                      '--port',
                      help='remote port to use (default: 69)',
                      default=69)
    parser.add_option('-f',
                      '--filename',
                      help='filename to fetch (deprecated, use download)')
    parser.add_option('-D',
                      '--download',
                      help='filename to download')
    parser.add_option('-u',
                      '--upload',
                      help='filename to upload')
    parser.add_option('-b',
                      '--blksize',
                      help='udp packet size to use (default: 512)')
    parser.add_option('-o',
                      '--output',
                      help='output file, - for stdout (default: same as download)')
    parser.add_option('-i',
                      '--input',
                      help='input file, - for stdin (default: same as upload)')
    parser.add_option('-d',
                      '--debug',
                      action='store_true',
                      default=False,
                      help='upgrade logging from info to debug')
    parser.add_option('-q',
                      '--quiet',
                      action='store_true',
                      default=False,
                      help="downgrade logging from info to warning")
    parser.add_option('-t',
                      '--tsize',
                      action='store_true',
                      default=False,
                      help="ask client to send tsize option in download")
    options, args = parser.parse_args()
    # Handle legacy --filename argument.
    if options.filename:
        options.download = options.filename
    if not options.host or (not options.download and not options.upload):
        sys.stderr.write("Both the --host and --filename options "
                         "are required.\n")
        parser.print_help()
        sys.exit(1)

    if options.debug and options.quiet:
        sys.stderr.write("The --debug and --quiet options are "
                         "mutually exclusive.\n")
        parser.print_help()
        sys.exit(1)

    class Progress(object):
        def __init__(self, out):
            self.progress = 0
            self.out = out
        def progresshook(self, pkt):
            if isinstance(pkt, tftpy.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)
    elif options.quiet:
        tftpy.setLogLevel(logging.WARNING)
    else:
        tftpy.setLogLevel(logging.INFO)

    progresshook = Progress(tftpy.log.info).progresshook

    tftp_options = {}
    if options.blksize:
        tftp_options['blksize'] = int(options.blksize)
    if options.tsize:
        tftp_options['tsize'] = 0

    tclient = tftpy.TftpClient(options.host,
                               int(options.port),
                               tftp_options)
    try:
        if options.download:
            if not options.output:
                options.output = os.path.basename(options.download)
            tclient.download(options.download,
                             options.output,
                             progresshook)
        elif options.upload:
            if not options.input:
                options.input = os.path.basename(options.upload)
            tclient.upload(options.upload,
                           options.input,
                           progresshook)
    except tftpy.TftpException, err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
Beispiel #21
0

#!/usr/bin/env python

import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()

import os
import sys
import threading
import argparse
import time
import tftpy

tftpy.setLogLevel(logging.WARNING)


class TClient(threading.Thread):
    def __init__(self, hostname, port, remote_filename, local_filename=None):
        logger.debug("Initializing TClient instance: hostname: '%s' port: %s "
                     "remote file: '%s' local file: '%s'",
                     hostname, port, remote_filename, local_filename)
        super(TClient, self).__init__()
        self.hostname = hostname
        self.port = port
        self.remote_filename = remote_filename
        self.local_filename = local_filename
        self.daemon = True
        if not self.local_filename:
            self.local_filename = os.devnull