def testWriteMarkInLog(self): loggable = log.Loggable() log.setDebug("5") log.addLogHandler(self.handler) marker = 'test' loggable.writeMarker(marker, log.LOG) self.assertEquals(self.message, marker)
def testWriteMarkInError(self): loggable = log.Loggable() log.setDebug("4") log.addLogHandler(self.handler) marker = 'test' self.assertRaises(SystemExit, loggable.writeMarker, marker, log.ERROR) self.assertEquals(self.message, marker)
def testSet(self): old = log.getLogSettings() log.setDebug('*:5') self.assertNotEquals(old, log.getLogSettings()) log.setLogSettings(old) self.assertEquals(old, log.getLogSettings())
def checkDebugMode(self): self.debugMode = yield self.statsData.CheckDebugMode() if self.debugMode == 0: log.setDebug(False) else: log.setDebug(True) reactor.callLater(60, self.checkDebugMode)
def testWriteMarkInInfo(self): loggable = log.Loggable() log.setDebug("3") log.addLogHandler(self.handler) marker = "test" loggable.writeMarker(marker, log.INFO) self.assertEquals(self.message, marker)
def testWriteMarkInWarn(self): loggable = log.Loggable() log.setDebug("2") log.addLogHandler(self.handler) marker = "test" loggable.writeMarker(marker, log.WARN) self.assertEquals(self.message, marker)
def testFormatStrings(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) self.tester.info("%d %s", 42, 'the answer') assert self.category == 'testlog' assert self.level == log.INFO assert self.message == '42 the answer'
def testLimitedError(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) self.assertRaises(SystemExit, self.tester.error, "error") assert self.category == 'testlog' assert self.level == log.ERROR assert self.message == 'error'
def testLogHandler(self): log.setDebug("testlog:3") log.addLogHandler(self.handler) self.tester.log("visible") assert self.message == 'visible' self.tester.warning("also visible") assert self.message == 'also visible'
def render_POST(self, request): try: debugStr = request.args['debug'][0].lower() except KeyError: debugStr = '' if debugStr in ['0','false','no']: self.config.serverConfig.Debug = False elif debugStr in ['1','true','yes']: self.config.serverConfig.Debug = True log.setDebug(self.config.serverConfig.Debug) request.setHeader('Content-Type','text/xml') return '%s<debug enabled="%s" href="/home"/>' % ( XML_HEADER, self.config.serverConfig.Debug)
def testLimitInvisible(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) # log 2 we shouldn't get self.tester.log("not visible") assert not self.category assert not self.level assert not self.message self.tester.debug("not visible") assert not self.category assert not self.level assert not self.message
def testLimitedVisible(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) # log 3 we should get self.tester.info("visible") assert self.category == 'testlog' assert self.level == log.INFO assert self.message == 'visible' self.tester.warning("also visible") assert self.category == 'testlog' assert self.level == log.WARN assert self.message == 'also visible'
def testLogHandlerLimitedLevels(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) # now try debug and log again too log.setDebug("testlog:5") self.tester.debug("debug") assert self.category == 'testlog' assert self.level == log.DEBUG assert self.message == 'debug' self.tester.log("log") assert self.category == 'testlog' assert self.level == log.LOG assert self.message == 'log'
def testAdaptStandardLogging(self): # create a standard logger logger = logging.getLogger('standard.logger') # set the debug level for the "test" category log.setDebug("test:3") log.addLimitedLogHandler(self.handler) logger.warning('invisible') # should not get anything, because the std module has not been adapted assert not self.category assert not self.level assert not self.message log.adaptStandardLogging('standard.logger', 'test', 'test_log') self.assertEquals(len(logger.handlers), 1) # trying to adapt it again should be a noop log.adaptStandardLogging('standard.logger', 'test', 'test_log') self.assertEquals(len(logger.handlers), 1) logger.info('invisible') # should not get anything, because INFO translates to Flu debug 4 assert not self.category assert not self.level assert not self.message logger.warning('visible') # WARNING translates to INFO, see log.stdLevelToFluLevel assert self.category == 'test', self.category assert self.level == log.INFO assert self.message == 'visible' self.message = self.level = self.category = None # lower the debug level log.setDebug("test:2") logger.warning('visible') # should not get anything now assert not self.category assert not self.level assert not self.message
def testSetDebug(self): log.setDebug(":5") log.setDebug("*") log.setDebug("5")
import argparse from log import setDebug import time from AnalyzeInnerHTML import Analyser from Eservices_crawler import Crawler if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--username', type=str, help='username required') parser.add_argument('--password', type=str, help='password required') parser.add_argument('--mode', type=str, default='i', help='choose info mode(i) or debug mode(d)') parser.add_argument( '--executable_path', type=str, default="C:\\Users\Akira.DESKTOP-HM7OVCC\Desktop\phantomjs.exe", help='choose info mode(i) or debug mode(d)') args = parser.parse_args() if args.mode == 'd': setDebug() if args.username and args.password: spider = Crawler(args.username, args.password, args.executable_path) analyser = Analyser() spider.connect() inner = spider.to_note() analyser.analyze_notes(inner) time.sleep(10) inner = spider.to_absence() analyser.analyze_absences(inner)
def main ( ): #print '' log.setDebug( util.argv( _cmds['Debug'] ) ) actions.supress( util.argv( _cmds['Supress']) ) args = sys.argv if len(args) == 1: log.comment ("No arguments specified, listing your Gists. Try '%s help' if you need help." % util.fileName) print '' del args[0] # Delete the filename cmd = None log.debug ("Arguments " + str( args )) #-------------------------------------------- # If args[0] is a command. We remove it from the list. args now contains only the command arguments # else we keep as is and try to evaluate the command #-------------------------------------------- if _hasCmd( args ): cmd = args[0] del args[0] # Delete the command. Arguments remaining are the options for each command else: cmd = _deriveCmd( args ) log.debug ("Adjusted cmd: " + str(cmd)) log.debug ("Adjusted arguments " + str( args )) #-------------------------------------------- # Handle commands #-------------------------------------------- if cmd == None: _printNoMatch() elif cmd in (_cmds['Help']): actions.help() elif cmd in (_cmds['List']): actions.list() elif cmd in (_cmds['Token']): actions.updateCredentials() elif cmd in (_cmds['View']): if len(args) == 1: actions.view( args[0] ) elif len(args) == 2: actions.view( args[0], fileName=args[1]) elif cmd in (_cmds['Download']): if len(args) == 2: actions.get( args[0], path=args[1] ) elif len(args) == 3: actions.get( args[0], fileName=args[1], path=args[2] ) elif cmd in (_cmds['New']): # Each option will prompt for public/pvt and description. In silent mode, assumes private and no description. if len(args) == 0: actions.new() elif len(args) == 1: # create File # create Content if util.isFileOrDir(args[0]) == True: actions.new( filename = args[0] ) else: actions.new( content = args[0] ) elif len(args) == 2: # create Boolean and File # create Boolean and Content # create Description and File # create Description and Content if util.parseBool( args[0] ) != None: if util.isFileOrDir(args[1]) == True: actions.new( public=util.parseBool( args[0] ), filename=args[1] ) else: actions.new( public=util.parseBool( args[0] ), content=args[1] ) else: if util.isFileOrDir(args[1]) == True: actions.new( description=args[0], filename=args[1] ) else: actions.new( description=args[0], content=args[1] ) elif len(args) == 3 and util.parseBool( args[0] ) != None: # create Boolean, Description and File # create Boolean, Description and Content if util.isFileOrDir(args[2]) == True: actions.new( public=util.parseBool( args[0] ), description=args[1], filename=args[2] ) else: actions.new( public=util.parseBool( args[0] ), description=args[1], content=args[2] ) else: _printNoMatch() elif cmd in (_cmds['Append']): # Each option will prompt for public/pvt and description. if len(args) == 0: _printNoMatch() elif len(args) == 2: # append: id File # append: id Content if util.isFileOrDir(args[1]) == True: actions.append( args[0], filename=args[1] ) else: actions.append( args[0], content=args[1] ) elif len(args) == 3: # append: id Description File # append: id Description Content if util.isFileOrDir(args[2]) == True: actions.append( args[0], description=args[1], filename=args[2] ) else: actions.append( args[0], description=args[1], content=args[2] ) else: actions.append( args[0] ) elif cmd in (_cmds['Update']): # Each option will prompt for public/pvt and description. if len(args) == 0: _printNoMatch() elif len(args) == 2: # append: id File # append: id Content if util.isFileOrDir(args[1]) == True: actions.update( args[0], filename=args[1] ) else: actions.update( args[0], content=args[1] ) elif len(args) == 3: # append: id Description File # append: id Description Content if util.isFileOrDir(args[2]) == True: actions.update( args[0], description=args[1], filename=args[2] ) else: actions.update( args[0], description=args[1], content=args[2] ) else: actions.update( args[0] ) elif cmd in (_cmds['Delete']): actions.delete( args[0] ) elif cmd in (_cmds['Backup']): _printNoImpl() actions.backup( ) elif cmd in (_cmds['Search']): _printNoImpl() actions.search( ) else: _printNoMatch() log.debug ("Done.") print ''
def testOwnLogHandlerLimited(self): log.setDebug("testlog:3") log.addLogHandler(self.handler) self.tester.log("visible") assert self.message == 'override visible'
def main(): #print '' log.setDebug(util.argv(_cmds['Debug'])) actions.supress(util.argv(_cmds['Supress'])) args = sys.argv if len(args) == 1: log.comment( "No arguments specified, listing your Gists. Try '%s help' if you need help." % util.fileName) print('') del args[0] # Delete the filename cmd = None log.debug("Arguments " + str(args)) #-------------------------------------------- # If args[0] is a command. We remove it from the list. args now contains only the command arguments # else we keep as is and try to evaluate the command #-------------------------------------------- if _hasCmd(args): cmd = args[0] del args[ 0] # Delete the command. Arguments remaining are the options for each command else: cmd = _deriveCmd(args) log.debug("Adjusted cmd: " + str(cmd)) log.debug("Adjusted arguments " + str(args)) #-------------------------------------------- # Handle commands #-------------------------------------------- if cmd == None: _printNoMatch() elif cmd in (_cmds['Help']): actions.help() elif cmd in (_cmds['List']): actions.list() elif cmd in (_cmds['Token']): actions.updateCredentials() elif cmd in (_cmds['Open']): if len(args) == 1: actions.open(args[0]) else: _printNoMatch() elif cmd in (_cmds['View']): if len(args) == 1: actions.view(args[0]) elif len(args) == 2: actions.view(args[0], fileName=args[1]) elif cmd in (_cmds['Download']): if len(args) == 2: actions.get(args[0], path=args[1]) elif len(args) == 3: actions.get(args[0], fileName=args[1], path=args[2]) elif cmd in (_cmds['New']): # Each option will prompt for public/pvt and description. In silent mode, assumes private and no description. if len(args) == 0: actions.new() elif len(args) == 1: # create File # create Content if util.isFileOrDir(args[0]) == True: actions.new(filename=args[0]) else: actions.new(content=args[0]) elif len(args) == 2: # create Boolean and File # create Boolean and Content # create Description and File # create Description and Content if util.parseBool(args[0]) != None: if util.isFileOrDir(args[1]) == True: actions.new(public=util.parseBool(args[0]), filename=args[1]) else: actions.new(public=util.parseBool(args[0]), content=args[1]) else: if util.isFileOrDir(args[1]) == True: actions.new(description=args[0], filename=args[1]) else: actions.new(description=args[0], content=args[1]) elif len(args) == 3 and util.parseBool(args[0]) != None: # create Boolean, Description and File # create Boolean, Description and Content if util.isFileOrDir(args[2]) == True: actions.new(public=util.parseBool(args[0]), description=args[1], filename=args[2]) else: actions.new(public=util.parseBool(args[0]), description=args[1], content=args[2]) else: _printNoMatch() elif cmd in (_cmds['Append']): # Each option will prompt for public/pvt and description. if len(args) == 0: _printNoMatch() elif len(args) == 2: # append: id File # append: id Content if util.isFileOrDir(args[1]) == True: actions.append(args[0], filename=args[1]) else: actions.append(args[0], content=args[1]) elif len(args) == 3: # append: id Description File # append: id Description Content if util.isFileOrDir(args[2]) == True: actions.append(args[0], description=args[1], filename=args[2]) else: actions.append(args[0], description=args[1], content=args[2]) else: actions.append(args[0]) elif cmd in (_cmds['Update']): # Each option will prompt for public/pvt and description. if len(args) == 0: _printNoMatch() elif len(args) == 2: # append: id File # append: id Content if util.isFileOrDir(args[1]) == True: actions.update(args[0], filename=args[1]) else: actions.update(args[0], content=args[1]) elif len(args) == 3: # append: id Description File # append: id Description Content if util.isFileOrDir(args[2]) == True: actions.update(args[0], description=args[1], filename=args[2]) else: actions.update(args[0], description=args[1], content=args[2]) else: actions.update(args[0]) elif cmd in (_cmds['Delete']): actions.delete(args[0]) elif cmd in (_cmds['Backup']): _printNoImpl() actions.backup() elif cmd in (_cmds['Search']): _printNoImpl() actions.search() else: _printNoMatch() log.debug("Done.") print('')