root/imbot/Log.py

Revision 107, 1.7 kB (checked in by pantley2, 3 years ago)

IMBOT: various fixes (listed below)

Ask.py: ask() takes a tuple'd sentence now instead of a string sentence

Cleaner.py: added two functions to check for garbage input

Commands.py: commands are now only accepted by Darin, Nikhil, and Felix (to prevent EOH users from causing chaos)

Filters/translate html to english.yml: updated to include ampersands in regexp replacing

Log.py: added error catching to SABBrain.txt deletion, because multiple threads can attempt to delete it at the same time (it was crashing, so I assume that's the cause)

MessageQueue.py: uses the new bad-input detectors from the end of Cleaner.py

SABBrain.py:
* put a try/except around is_word_nva() because something is passing it bad input (a period and a quesiton mark instead of a tuple)
* added some logging to compute_sentence_weight() in an attempt to determine if it penalizes repeated sentences correctly
* replaced "error!!!" with "lol", in case it pops up in a real conversation
* the diff says generate_reply() is completely changed, but I'm not sure why... hopefully I'm committing a better version and not an older version

sigartbot.py: now sends typing notifications, but I don't think they actually work

Line 
1 # modules that come with Python
2 import os, re, sys
3
4 class Log:
5         def __init__(self, enabled=False):
6                 self.filename = 'Debug/' + re.sub(r'.*\\', '', sys._getframe(1).f_code.co_filename)[:-3] + '.txt'
7                 self.indent = 0
8                 self.enabled = enabled
9                 self.level = 100
10        
11         def enter(self, name=None, text="", locals=None):
12                 '''Increase the indentation level, print a debug message, and print any arguments'''
13                 name = name if name is not None else sys._getframe(1).f_code.co_name
14                 self.write("[%s] %s" % (name, text))
15                 if locals != None:
16                         self.args(locals)
17                 elif name == None:
18                         self.write("no arguments were passed to this function")
19                 self.indent += 1
20        
21         def args(self, locals):
22                 '''Print a function's arguments'''
23                 self.indent += 1
24                 self.enter("ARGUMENTS")
25                 for name, value in locals.iteritems():
26                         self.write("%s <%s> %s" % (name, str(type(value))[7:-2], value))
27                 self.leave()
28                 self.indent -= 1
29        
30         def add(self, text=""):
31                 '''Append 'text' to the log'''
32                 self.write(text)
33        
34         def leave(self, text=""):
35                 '''Decrease the indentation level, print a debug message, and insert a blank line'''
36                 self.write((len(str(text)) > 0) * ("%s\n" % text))
37                 self.indent -= 1
38        
39         def write(self, text=""):
40                 '''Write 'text' to self.filename'''
41                 if not self.enabled:
42                         return
43                 else:
44                         try:
45                                 myfile = file(self.filename, "a")
46                                 myfile.write("%s%s\n" % ("\t" * self.indent, str(text)))
47                                 myfile.close()
48                         except IOError:
49                                 print "Logging Error (%s): couldn't save %s" % (self.filename, str(text))
50                                 return
51        
52         def delete(self):
53                 '''Delete this log file from disk'''
54                 try:
55                         if os.path.exists(self.filename):
56                                 os.remove(self.filename)
57                 except:
58                         print "ERROR: CANNOT os.remote(%s)" % self.filename
59
60
Note: See TracBrowser for help on using the browser.