def __init__(self, path, recursive=False, debug=False):
        self.path      = path
        self.recursive = recursive
        self.filelist  = []

        if debug is True:
            log.setLevel(log.DEBUG)

        log.debug("path: %s" % (self.path))
        log.debug("recursive: %s" % (str(self.recursive)))
Пример #2
0
    def __init__(self, path, recursive=False, debug=False):
        self.path      = path
        self.recursive = recursive
        self.filelist  = []

        if debug is True:
            log.setLevel(log.DEBUG)

        log.debug("path: %s" % (self.path))
        log.debug("recursive: %s" % (str(self.recursive)))
Пример #3
0
 def get_logger(self, logger_name, filename):
     log = logging.getLogger(logger_name)
     log.setLevel(self.verbosity_map.get(self.verbosity, logging.INFO))
     
     if self.logfile:
         handler = RotatingFileHandler(filename, maxBytes=1024*1024, backupCount=2)
         handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
         log.addHandler(handler)
     
     if self.verbosity == 2 or not self.logfile:
         stream_handler = logging.StreamHandler()
         stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
         log.addHandler(stream_handler)
     
     return log
Пример #4
0
    def __init__(self, host, port, username, dbname, on_error_stop=False, debug=False):
        if debug is True:
            log.setLevel(log.DEBUG)

        self.host     = host     or os.getenv("PGHOST")     or "localhost"
        self.port     = int(port or os.getenv("PGPORT")     or 5432)
        self.username = username or os.getenv("PGUSER")     or os.getenv("USER")
        self.dbname   = dbname   or os.getenv("PGDATABASE") or self.username

        log.debug("host:   %r", self.host)
        log.debug("port:   %r", self.port)
        log.debug("user:   %r", self.username)
        log.debug("dbname: %r", self.dbname)

        self.on_error_stop = on_error_stop
Пример #5
0
    def __init__(self, host, port, username, dbname, on_error_stop=False, debug=False):
        if debug is True:
            log.setLevel(log.DEBUG)

        self.host     = get_host(host)
        self.port     = get_port(port)
        self.username = get_username(username)
        self.dbname   = get_dbname(dbname, self.username)

        log.debug("host: " + self.host)
        log.debug("port: " + str(self.port))
        log.debug("user: "******"dbname: " + self.dbname)

        self.on_error_stop = on_error_stop
Пример #6
0
    def __init__(self,
                 host=None,
                 port=None,
                 interface=None,
                 inputfile=None,
                 debug=None):
        if debug is True:
            log.setLevel(log.DEBUG)

        self.host = host
        self.port = port
        self.iface = interface
        self.inputfile = inputfile
        self.debug = debug

        if self.port is None:
            self.port = "5432"

        if self.iface is None:
            self.iface = "any"

        self.tcpdump = "tcpdump -tttt"

        if self.inputfile is not None:
            self.tcpdump = self.tcpdump + " -r " + self.inputfile

        self.tcpdump = self.tcpdump + " -l -i " + self.iface + " -s 0 -X -p tcp port " + str(
            self.port)

        if self.host is not None:
            self.tcpdump = self.tcpdump + " and host " + self.host

        log.info(self.tcpdump)

        self.process = subprocess.Popen([self.tcpdump],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        shell=True,
                                        bufsize=0)

        # header
        self.p1 = re.compile('^([\d-]+) ([\d:\.]+) IP (.*) > (.*): Flags')
        # data
        self.p2 = re.compile('^\t+0x(.+):  (.+)  ')
Пример #7
0
    def get_logger(self, logger_name, filename):
        log = logging.getLogger(logger_name)
        log.setLevel(self.verbosity_map.get(self.verbosity, logging.INFO))

        if self.logfile:
            handler = RotatingFileHandler(filename,
                                          maxBytes=1024 * 1024,
                                          backupCount=2)
            handler.setFormatter(
                logging.Formatter(
                    '%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
            log.addHandler(handler)

        if self.verbosity == 2 or not self.logfile:
            stream_handler = logging.StreamHandler()
            stream_handler.setFormatter(
                logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
            log.addHandler(stream_handler)

        return log
Пример #8
0
    def __init__(self,
                 host,
                 port,
                 username,
                 dbname,
                 on_error_stop=False,
                 debug=False):
        if debug is True:
            log.setLevel(log.DEBUG)

        self.host = get_host(host)
        self.port = get_port(port)
        self.username = get_username(username)
        self.dbname = get_dbname(dbname, self.username)

        log.debug("host: " + self.host)
        log.debug("port: " + str(self.port))
        log.debug("user: "******"dbname: " + self.dbname)

        self.on_error_stop = on_error_stop
Пример #9
0
    def __init__(self,
                 host,
                 port,
                 username,
                 dbname,
                 on_error_stop=False,
                 debug=False):
        if debug is True:
            log.setLevel(log.DEBUG)

        self.host = host or os.getenv("PGHOST") or "localhost"
        self.port = int(port or os.getenv("PGPORT") or 5432)
        self.username = username or os.getenv("PGUSER") or os.getenv("USER")
        self.dbname = dbname or os.getenv("PGDATABASE") or self.username

        log.debug("host:   %r", self.host)
        log.debug("port:   %r", self.port)
        log.debug("user:   %r", self.username)
        log.debug("dbname: %r", self.dbname)

        self.on_error_stop = on_error_stop
Пример #10
0
    def __init__(self, host=None, port=None, interface=None, inputfile=None, debug=None):
        if debug is True:
            log.setLevel(log.DEBUG)

        self.host      = host
        self.port      = port
        self.iface     = interface
        self.inputfile = inputfile
        self.debug     = debug

        if self.port is None:
            self.port = "5432"

        if self.iface is None:
            self.iface = "any"

        self.tcpdump = "tcpdump -tttt"

        if self.inputfile is not None:
            self.tcpdump = self.tcpdump + " -r " + self.inputfile

        self.tcpdump = self.tcpdump + " -l -i " + self.iface + " -s 0 -X -p tcp port " + str(self.port)

        if self.host is not None:
            self.tcpdump = self.tcpdump + " and host " + self.host

        log.info(self.tcpdump)

        self.process = subprocess.Popen([self.tcpdump],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        shell=True,
                                        bufsize=0)

        # header
        self.p1 = re.compile('^([\d-]+) ([\d:\.]+) IP (.*) > (.*): Flags')
        # data
        self.p2 = re.compile('^\t+0x(.+):  (.+)  ')
Пример #11
0
 def testSetLevel001(self):
     log.setLevel(log.INFO)
Пример #12
0
import sys
from zirc.test import TestCase
import log as logging
import utils
import commands
import config

logging.setLevel(30)

class botTest(TestCase):
    def __init__(self):
        self.config = {}
        self.config['nickname'] = 'zIRC-test'

    def on_privmsg(self, event, irc, arguments):
        if " ".join(arguments).startswith(config.commandChar):
            utils.call_command(self, event, irc, arguments)

    @staticmethod
    def on_kick(event, irc):
        nick = event.raw.split(" ")[3]
        if nick == 'zIRC-test':
            irc.join(event.target)

    @staticmethod
    def on_join(event, irc):
        irc.send("WHO {0} nuhs%nhua".format(event.target))

    @staticmethod
    def on_invite(event, irc):
        if utils.checkPerms(event.source.host, trusted=True):
Пример #13
0
    def quit(self):
        self.xprop_listener.terminate()


fp = None

if __name__ == '__main__':
    parser = argparse.ArgumentParser()

    parser.add_argument("-c",
                        "--config",
                        type=str,
                        help="Config file",
                        required=False,
                        default="config.toml")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="Verbosity increase")

    args = parser.parse_args()
    if (args.verbose):
        log.setLevel(log.DEBUG)

    try:
        fp = FocusProtector(args.config)
        fp.mainloop()
    except KeyboardInterrupt as e:
        fp.quit()
        # raise e
Пример #14
0
from os 	 import makedirs
from shutil  import copy   as copy_file
from os.path import join   as join_filename
from os.path import exists
from os.path import dirname
import os
from xml.dom.minidom import Element

from filenamer import Filenamer

from cStringIO import StringIO
from subprocess import Popen, PIPE, STDOUT
#from isaac_link import Isaac_link


log.setLevel(logging.DEBUG)


log.set_udp_destination('192.168.2.3')
log.set_udp_destination('129.123.189.171')
log.set_udp_destination('10.0.0.8')#Home connection
#log.set_udp_destination('estimated.local')
#log.set_udp_destination('localhost')



class watermeter():
    def __init__(self, data_directory):

        logging.debug(data_directory)
Пример #15
0
def main():
    args = parser.parse_args()

    # configure verbosity
    default = tf.logging.WARN
    verbosity = max(tf.logging.DEBUG,
                    default - args.verbose * tf.logging.DEBUG)
    tf.logging.set_verbosity(verbosity)
    log.setLevel(verbosity)

    database = data.Database()
    model = cnn_model.Model()
    estimator = model.get_estimator()

    if args.gui:
        logger.info('Using CPU only for better performance in GUI mode')
        os.environ['CUDA_VISIBLE_DEVICES'] = ''
        gui.runApp(estimator)

    def train_input_fn(repeats):
        return lambda: database.get_train_dataset().shuffle(10000).batch(
            args.batch_size).repeat(repeats).prefetch(3)

    def eval_input_fn():
        return lambda: database.get_test_dataset().batch(args.batch_size
                                                         ).prefetch(3)

    def predict_input_fn(files):
        return lambda: database.from_files(files).batch(args.batch_size)

    if args.development_main:
        development_main(args)
        return

    if args.train:
        info_epochs = lambda _from, _to: logger.info('EPOCHS from {} to {}:'.
                                                     format(_from, _to))
        info_time = lambda time, n_epochs: logger.info(
            'Time per epoch: {:.2f} sec = {:.2f} min'.format(
                time / n_epochs, time / n_epochs / 60))
        if args.eval_each_n:
            n_full = args.epochs // args.eval_each_n if args.eval_each_n is not None else 0
            for i in range(n_full):
                info_epochs(i * args.eval_each_n + 1,
                            (i + 1) * args.eval_each_n)
                start = time.time()
                estimator.train(train_input_fn(args.eval_each_n))
                info_time(time.time() - start, args.eval_each_n)
                results = estimator.evaluate(eval_input_fn())
                logger.info('Test data accuracy: %.3f' % results['accuracy'])
            remaining_epochs = args.epochs - n_full * args.eval_each_n
            if remaining_epochs > 0:
                info_epochs(n_full * args.eval_each_n + 1, args.epochs)
                start = time.time()
                estimator.train(train_input_fn(remaining_epochs))
                info_time(time.time() - start, remaining_epochs)
        else:
            info_epochs(1, args.epochs)
            start = time.time()
            estimator.train(train_input_fn(args.epochs))
            info_time(time.time() - start, args.epochs)

    if args.eval:
        start = time.time()
        results = estimator.evaluate(eval_input_fn())
        logger.info('Test data accuracy: %.3f (eval in %.2f sec)' %
                    (results['accuracy'], time.time() - start))

    if args.predict:
        predictions = estimator.predict(predict_input_fn(args.predict))
        common_path = os.path.split(os.path.commonprefix(args.predict))[0]
        filenames = [
            os.path.relpath(path, start=common_path) for path in args.predict
        ]
        max_filename_len = max(len(name) for name in filenames)

        logger.info('Predictions:')
        for filename, prediction_dict in zip(filenames, predictions):
            pi = prediction_dict['predictions']
            label = database.CLASSES[pi]
            probability = prediction_dict['probabilities'][pi]
            logger.info('{name:>{nlen}}: {lab} ({prob:6.2f} %)'.format(
                name=filename,
                nlen=max_filename_len,
                lab=label,
                prob=probability * 100))

    if args.show:
        model.visualize_activations(predict_input_fn(args.show))
Пример #16
0
 def testSetLevel001(self):
     log.setLevel(log.INFO)