예제 #1
0
 def setUp(self):
     self.log = Log()
     self.log.verbosity=10
     self.log.cacheflag=True
     self.log.logdir=LOGDIR,
     self.log.pidlogname=False
     self.log.proclogname=False
     self.log.pad=False
예제 #2
0
   def setUp(self):        
       self.log = Log()
       self.log.pidlogname=True
       self.log.proclogname=True  
       self.log.startlog()
       #super(Test_Log_Names,self).setUp()
 
       
       @logger(self.log)
       def func1(*args,**kwargs):
           return(100)
       
       self.func1  = func1
예제 #3
0
class Test_Log_LineNumber(Test_Log_Base):
    def setUp(self):
        self.log = Log()
        self.log.config = OrderedDict([('linenum',5)]) 
        self.log.cacheflag=True
        self.log.startlog()
    
    def test_(self):
        def myfunc(arg1,arg2):
            self.log.log(PRIORITY.SUCCESS,msg="this is a test")            
        myfunc('foo','bar')
        
        # not testing for a specific line number as it will be too brittle a test
        self.assertTrue(isint(self.log.cache[0][0]))
예제 #4
0
class Test_Log_Base(unittest.TestCase):
    def setUp(self):
        self.log = Log()
        self.log.verbosity=10
        self.log.cacheflag=True
        self.log.logdir=LOGDIR,
        self.log.pidlogname=False
        self.log.proclogname=False
        self.log.pad=False
    
    def tearDown(self):
        logfullpath = self.log.logfullpath
        self.log.close()
        self.log.reset()
        self.log.cache=[]
        os_file_delete(logfullpath)
예제 #5
0
class Test_Log_Names(Test_Log_Base):
    def setUp(self):        
        self.log = Log()
        self.log.pidlogname=True
        self.log.proclogname=True  
        self.log.startlog()
        #super(Test_Log_Names,self).setUp()
  
        
        @logger(self.log)
        def func1(*args,**kwargs):
            return(100)
        
        self.func1  = func1
        
    def test_(self):
        
        logname = os.path.basename(self.log.logname).split(".")
        self.assertEquals(logname[3],'test_misc_utils_log')
예제 #6
0
class Test_Log(unittest.TestCase):
    
    def setUp(self):
        self.logdir = "/tmp/log"
        self.log = Log(verbosity=10,
                       cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="") # this forces the singleton to allow a new instance

    def test_debug(self):
        self.log.log(thisfuncname(),7)
        
        logfile = os_file_to_list(self.log.logpath)
        
        self.assertEquals(logfile[0].split("|")[2].strip(),"DEBUG")
        
    def test_extra_msg(self): 
        self.log.log(thisfuncname(),3,foobar='barfoo')
        expected_results = "[('foobar','barfoo')]"
        logfile = os_file_to_list(self.log.logpath)
        
        self.assertEquals(logfile[0].split("|")[9].strip(),expected_results)
        
    def tearDown(self):
        self.log.log_clean()
        pass
예제 #7
0
 def setUp(self):
     
     self.logdir = "/tmp/log"
     self.log = Log(verbosity=10,
                    cacheflag=True,logdir="/tmp/log",
                    pidlogname=False,proclogname=False,
                    reset="")
     
     @logger(self.log)
     def func1(*args,**kwargs):
         return(100)
     
     self.func1  = func1
예제 #8
0
class Test_Misc(unittest.TestCase):
    
    def setUp(self):
        self.logdir = "/tmp/log"
        self.log = Log(verbosity=10,
                       cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="") # this forces the singleton to allow a new instance
        
    def test_func_arg(self):
        
        from database_table_util import tbl_col_add
        self.log.log(self,4,func=tbl_col_add,current_value="aaa",new_value="bbb")
        
        logfile = os_file_to_list(self.log.logpath)
        
        expected_results = "[('current_value','aaa'),('new_value','bbb'),('func','tbl_col_add')]"

        self.assertEquals(logfile[0].split("|")[9].strip(),expected_results)
        
    def tearDown(self):
        #self.log.log_clean()
        pass
예제 #9
0
 def setUp(self):
     
     self.logdir = "/tmp/log"
     self.log = Log(cacheflag=True,logdir="/tmp/log",
                    pidlogname=False,proclogname=False,
                    reset="")
    
     @logger(self.log)
     def func_1sec(*args,**kwargs):
         sleep(1)
         return(100)
     
     @logger(self.log)
     def func1(*args,**kwargs):
         return(100)
     
     self.func1 = func1
     self.func_1sec = func_1sec
예제 #10
0
class Test_Log_Multiple_Entries(unittest.TestCase):
    
    def setUp(self):
        
        self.logdir = "/tmp/log"
        self.log = Log(verbosity=10,
                       cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="")
        
        @logger(self.log)
        def func1(*args,**kwargs):
            return(100)
        
        self.func1  = func1
        
    
    def test_1000msg(self):
        
        for i in range(1000):
            self.log.log(thisfuncname(),7,)
            
        self.assertEqual(len(self.log.cache),1000)
        
        self.log.logfile.close()
        
        self.assertEqual(self.log.log_file_length(),999)
        self.log.log_clean()
        

    def test_1000msg_logger(self):
        
        for i in range(1000):
            self.func1()
        
        
        pid = os.getpid()
        self.assertEqual(self.log.stats[str(pid)]['func1']['no'],1000)
        self.log.log_clean()
예제 #11
0
class Test_Logger_Member_Function(unittest.TestCase):
    def setUp(self):
        
        self.logdir = "/tmp/log"
        self.log = Log(cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="")
       
        @logger(self.log)
        def func_1sec(*args,**kwargs):
            sleep(1)
            return(100)
        
        @logger(self.log)
        def func1(*args,**kwargs):
            return(100)
        
        self.func1 = func1
        self.func_1sec = func_1sec
        

    def test_args(self):
        self.func1("xyz",123,list())
        
        logfile = os_file_to_list(self.log.logpath)
        expected_results = "xyz,123,[]".ljust(20) # 20 is size of field

        results = logfile[0].split("|")[7] 
        self.assertEqual(results,expected_results)

    def test_args_kwargs(self):
        self.func1("xyz",123,list(),abc="xyz")
        
        logfile = os_file_to_list(self.log.logpath)
        
        expected_results = "xyz,123,[]".ljust(20) # 20 is size of field

        results = logfile[0].split("|")[7] 
        self.assertEqual(results,expected_results)  
        
        expected_results = "[(\'abc\',\'xyz\')]".ljust(20) # 20 is size of field
        results = logfile[0].split("|")[8]
        self.assertEqual(results,expected_results)  
        
    def tearDown(self):
        self.log.log_clean()
        pass
        
    def test_noargs(self):
        self.func1()
        
        logfile = os_file_to_list(self.log.logpath)
        
        self.assertEquals(logfile[0].split("|")[2].strip(),"INFUNC")
        self.assertEquals(logfile[1].split("|")[2].strip(),"OUTFUNC")
        
    def test_kwargs(self):
        self.func1(abc="xyz")
        
        logfile = os_file_to_list(self.log.logpath)
        expected_results = "[(\'abc\',\'xyz\')]".ljust(20) # 20 is size of field

        results = logfile[0].split("|")[8]
        
        self.assertEqual(results,expected_results)  


    def test_userclassobj_args(self):
        
        class myclass(object):
            pass
        
        self.func1(myclass())
        
        logfile = os_file_to_list(self.log.logpath)
        expected_results = "myclass".ljust(20) # 20 is size of field

        results = logfile[0].split("|")[7] 
        self.assertEqual(results,expected_results)
        
    def test_etime(self):
        self.func_1sec()
        logfile = os_file_to_list(self.log.logpath)
        
        self.assertAlmostEqual(round(float(logfile[1].split("|")[5].strip()),0),1)

    def tearDown(self):
        self.log.log_clean()
        pass
예제 #12
0
import os
from os import path as ospath
from misc_utils import nxnarraycreate

from database_table_util import tbl_query, tbl_rows_update, tbl_rows_get, tbl_exists, tbl_create, tbl_rows_insert, \
     DBException, dbtblfactory, _gencoldefn, _quotestrs
from database_util import Database
from collections import OrderedDict
from misc_utils_log import Log, logger
from misc_utils import thisfuncname

from shutil import copyfile

from sswizard_query_utils import _sessionenum, _maxlessonenum, _maxsessionenum

log = Log(cacheflag=True,logdir="/tmp/log",pidlogname=False,proclogname=False)

def _updaterecordval(record, new_value,obj_type,cols):
    _idx = cols.index(obj_type)
    record.pop(_idx)
    record.insert(_idx,new_value) 
    return(record)

def update_callback(ui,widget,new_value):        
    ''' via BaseTk class; all entry widgets assign a callback to the change event
    to call this function if it exists '''
    
    #put event on here too
    if str(widget.current_value) <> str(new_value):
        
        widget.version += 1
예제 #13
0
from misc_utils_log import Log, logger, PRIORITY
from collections import OrderedDict
from types import DictionaryType
from tcxParser import TcxParser
import datetime

import sys

if sys.platform == "win32":
    LOGDIR = "./"
else:
    LOGDIR = "/tmp/log"

log = Log(cacheflag=False,
          logdir=LOGDIR,
          verbosity=5,
          pidlogname=True,
          proclogname=False)
log.config = OrderedDict([('now', 12), ('type', 10), ('class', 15),
                          ('funcname', 15), ('module', 20), ('msg', -1)])

DEFAULT_BUCKETS = {
    'hr': ((0, 130), (131, 140), (141, 150), (151, 160), (161, 0)),
    'watts': ((0, 220), (221, 260), (261, 300), (301, 340), (340, 0))
}


class TcxAnalyzer(object):
    def __init__(self, databasename, buckets=DEFAULT_BUCKETS):
        self.databasename = databasename
        try:
예제 #14
0
#/usr/bin/python
import os
import xml.etree.ElementTree as xmltree
import sys
from misc_utils_log import Log, logger, PRIORITY

if sys.platform == "win32":
    LOGDIR = "./"
else:
    LOGDIR = "/tmp/log"

log = Log(cacheflag=True, logdir=LOGDIR, verbosity=10)


def _getclassmethods(clsobj, inverse=False):
    ''' inverse will return anything not a class method - so a member variable'''
    from inspect import ismethod
    return ([
        key for key, obj in _getmembers(clsobj).iteritems()
        if ismethod(obj) <> inverse
    ])


def _getclasses(module, filename):
    from inspect import isclass
    from sys import modules
    from os.path import splitext, basename

    classes = [name for name in _dir(module) if isclass(getattr(module, name))]
    imported_sysclasses_remove(classes, filename)
    return classes
예제 #15
0
 def setUp(self):
     self.logdir = "/tmp/log"
     self.log = Log(verbosity=10,
                    cacheflag=True,logdir="/tmp/log",
                    pidlogname=False,proclogname=False,
                    reset="") # this forces the singleton to allow a new instance
예제 #16
0
import sys
from misc_utils_log import Log, logger
log = Log(cacheflag=True,logdir="/tmp/log",verbosity=20,
          pidlogname=True,proclogname=False)

from misc_utils_process import *
from misc_utils_enum import enum
from misc_utils import nxnarraycreate, thisfuncname

from type_utils import SetMemberPartial, DBSetMember, TextAlphaNumRO
from ui_utils import TkImageLabelGrid, geometry_get_dict, geometry_get, TkGridCombobox, \
     TkCombobox, Tk3Label, _tklabel, TkNLabel, _tkbutton

from misc_utils_objectfactory import ObjFactory

import sswizard_utils
import ssviewer_utils

from sswizard_query_utils import *
from sswizard_config_utils import *
from ssviewer_utils_palette import dbformats_get, dbcolors_get

from database_util import Database, tbl_create
from database_table_util import dbtblgeneric, tbl_rows_get, tbl_query

from Tkinter import *
from ttk import *

from Tkinter import Checkbutton as _checkbutton

from collections import OrderedDict
예제 #17
0
import sys
from misc_utils_log import Log, logger

log = Log(cacheflag=True,
          logdir="/tmp/log",
          verbosity=20,
          pidlogname=True,
          proclogname=False)

from misc_utils_process import *
from misc_utils_enum import enum
from misc_utils import nxnarraycreate, thisfuncname

from type_utils import SetMemberPartial, DBSetMember, TextAlphaNumRO
from ui_utils import TkImageLabelGrid, geometry_get_dict, geometry_get, TkGridCombobox, \
     TkCombobox, Tk3Label, _tklabel, TkNLabel, _tkbutton

from misc_utils_objectfactory import ObjFactory

import sswizard_utils
import ssviewer_utils

from sswizard_query_utils import *
from sswizard_config_utils import *
from ssviewer_utils_palette import dbformats_get, dbcolors_get

from database_util import Database, tbl_create
from database_table_util import dbtblgeneric, tbl_rows_get, tbl_query

from Tkinter import *
from ttk import *
예제 #18
0
from os import path as ospath
from misc_utils import nxnarraycreate

from database_table_util import tbl_query, tbl_rows_update, tbl_rows_get, tbl_exists, tbl_create, tbl_rows_insert, \
     DBException, dbtblfactory, _gencoldefn, _quotestrs
from database_util import Database
from collections import OrderedDict
from misc_utils_log import Log, logger
from misc_utils import thisfuncname

from shutil import copyfile

from sswizard_query_utils import _sessionenum, _maxlessonenum, _maxsessionenum

log = Log(cacheflag=True,
          logdir="/tmp/log",
          pidlogname=False,
          proclogname=False)


def _updaterecordval(record, new_value, obj_type, cols):
    _idx = cols.index(obj_type)
    record.pop(_idx)
    record.insert(_idx, new_value)
    return (record)


def update_callback(ui, widget, new_value):
    ''' via BaseTk class; all entry widgets assign a callback to the change event
    to call this function if it exists '''

    #put event on here too
예제 #19
0
import sys
from misc_utils_log import Log, logger, PRIORITY
from os.path import basename
from os import listdir, remove
from shutil import move, copy
from collections import OrderedDict

if sys.platform == "win32":
    LOGDIR = "./"
else:
    LOGDIR = "/tmp/log"

log = Log(cacheflag=False,
          logdir=LOGDIR,
          verbosity=5,
          pidlogname=True,
          proclogname=False,
          config=OrderedDict([('now', 12), ('type', 10), ('class', 15),
                              ('funcname', 15), ('module', 20), ('msg', -1)]))


class MoveFiles(object):
    ''' subclass need to overwrite _target_conv and _source_conv for there specific filename
    convertion functions (see trainerroad implementation)'''
    def __init__(self, sourcedir, targetdir, prefix="", moveflag=False):
        self.sourcedir = sourcedir
        self.targetdir = targetdir
        self.prefix = prefix
        self.moveflag = moveflag
        log.log(PRIORITY.INFO, msg="moveflag set to [" + str(moveflag) + "]")
        log.log(PRIORITY.INFO,
예제 #20
0
    'ns3': 'http://www.garmin.com/xmlschemas/ActivityExtension/v2'
}

__version__ = '0.1'
DOWNLOAD_DIR = "C:\\Users\\burtnolej\\Downloads"
#INPUT_FILE_DIR = environ["PYTHONAPPS"] + "\\apps\\trainerroad\\tcx_files"
INPUT_FILE_DIR = "C:\\Users\\burtnolej\\Documents\\GitHub\\hungrycrayon\\apps\\traineroad\\tcx_files"

if sys.platform == "win32":
    LOGDIR = "./"
else:
    LOGDIR = "/tmp/log"

log = Log(cacheflag=False,
          logdir=LOGDIR,
          verbosity=5,
          pidlogname=True,
          proclogname=False)
log.config = OrderedDict([('now', 12), ('type', 10), ('class', 15),
                          ('funcname', 15), ('module', 20), ('msg', -1)])


class TcxParser(object):
    def __init__(self,
                 input_files_dir,
                 databasename="trainerroad",
                 tablename="trainerroad",
                 verbosity=5):
        self.files = {}
        self.input_files_dir = input_files_dir
        self.databasename = databasename
예제 #21
0
 def setUp(self):
     self.log = Log()
     self.log.config = OrderedDict([('linenum',5)]) 
     self.log.cacheflag=True
     self.log.startlog()
예제 #22
0
import sys
from misc_utils_log import Log, logger
log = Log(cacheflag=True,logdir="/tmp/log",verbosity=10,
          pidlogname=True,proclogname=False)

from type_utils import SetMemberPartial, DBSetMember, TextAlphaNum, \
     TextAlphaNumRO, TrueFalse
from ui_utils import TkImageLabelGrid, geometry_get_dict, geometry_get, TkGridEntry
from misc_utils import nxnarraycreate, thisfuncname


import sswizard_utils

from database_util import Database, tbl_create
from database_table_util import dbtblgeneric, tbl_rows_get, \
     tbl_rows_update, dbtblfactory, tbl_col_update, tbl_col_add,tbl_row_delete

from collections import OrderedDict
from Tkinter import *
from ttk import *
import tkFont

class DBTableUI(Tk):
    def __init__(self,maxentrycols=18,maxentryrows=12,
                 maxnewrowcols=16,maxnewrowrows=3):
        
        Tk.__init__(self)

        self.lastsaveversion=0
        
        # any children that change update this 
예제 #23
0
    'rideListName': "//div[contains(@class,'ride-list-name')]",
    'downloadRide': "//a[contains(@class,'downloadRide')]",
    'loadMore': "//a[@id='loadMore']",
    'rideListDate': "//p[contains(@class,'gray-light')]/span",
    'rideTitle': "//h1[contains(@class,'mb0')]/a",
    'notes': "//textarea[contains(@class,'form-control')]",
}

if sys.platform == "win32":
    LOGDIR = "./"
else:
    LOGDIR = "/tmp/log"

log = Log(cacheflag=False,
          logdir=LOGDIR,
          verbosity=5,
          pidlogname=True,
          proclogname=False)
log.config = OrderedDict([('now', 12), ('type', 10), ('class', 15),
                          ('funcname', 15), ('module', 20), ('msg', -1)])


class DownloadTrainerRoadTcx(object):
    def __init__(self, databasename="trainerroad", tablename="metadata"):
        self.databasename = databasename
        self.tablename = tablename
        log.log(PRIORITY.INFO,
                msg="DownloadTrainerRoadTcx instance created [db=" +
                databasename + "] [tablename=" + tablename + "]")

    @classmethod