Skip to content

Commit

Permalink
started a revision of the logging wrapping print() into printlog() to…
Browse files Browse the repository at this point in the history
… add timestamp for all messages and

then introduce in future a conditional approach to skip some logging both for performance and readability
  • Loading branch information
maurizioandreotti committed Jun 26, 2020
1 parent e870af1 commit 8a3b651
Show file tree
Hide file tree
Showing 40 changed files with 830 additions and 633 deletions.
11 changes: 8 additions & 3 deletions d-rats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import traceback
import gtk

#importing print() wrapper
from d_rats.debug import printlog

sys.path.insert(0, os.path.join("/usr/share", "d-rats"))

#import module to have spelling correction in chat and email applications
Expand All @@ -51,7 +54,7 @@ def handle_exception(exctyp, value, tb):
_trace = traceback.format_exception(exctyp, value, tb)
trace = os.linesep.join(_trace)

print(("---- GUI Exception ----\n%s\n---- End ----\n" % trace))
printlog("---- GUI Exception ----\n%s\n---- End ----\n" % trace)

msg = """
<b><big>D-RATS has encountered an error.</big></b>
Expand Down Expand Up @@ -120,7 +123,7 @@ def ignore_exception(exctyp, value, tb):
from d_rats import dplatform

if opts.config:
print("D-Rats : re-config option found -- Reconfigure D-rats")
printlog("D-Rats : re-config option found -- Reconfigure D-rats")
dplatform.get_platform(opts.config)

# import the D-Rats main application
Expand All @@ -134,10 +137,12 @@ def ignore_exception(exctyp, value, tb):

# create the mainapp with the basic options
app = mainapp.MainApp(safe=opts.safe)


printlog("D-Rats : reloading app\n\n")
# finally let's open the default application triggering it differently if we
# want to profile it (which is running the app under profile control to see what happens)
if opts.profile :
printlog("D-Rats : Executing with cprofile")
import cProfile
cProfile.run('app.main()')
else:
Expand Down
21 changes: 12 additions & 9 deletions d_rats/agw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import absolute_import
from __future__ import print_function
#importing printlog() wrapper
from .debug import printlog

import struct
from . import utils
import sys
Expand Down Expand Up @@ -155,7 +158,7 @@ def recv_frame_type(self, kind, poll=False):
f = self.__recv_frame()
self.__lock.release()
if f:
print(("Agw : Got %s frame while waiting for %s" % (chr(f.kind), kind)))
printlog(("Agw : Got %s frame while waiting for %s" % (chr(f.kind), kind)))
self._framebuf[f.kind].insert(0, f)
elif not poll:
return None
Expand Down Expand Up @@ -186,15 +189,15 @@ def connect(self, tocall):
self._agw.send_frame(cf)

f = self._agw.recv_frame_type("C", True)
print(("Agw : %s" % f.get_payload()))
printlog(("Agw : %s" % f.get_payload()))

def disconnect(self):
df = AGWFrame_d()
df.set_from(self._mycall)
self._agw.send_frame(df)

f = self._agw.recv_frame_type("d", True)
print(("Agw : %s" % f.get_payload()))
printlog(("Agw : %s" % f.get_payload()))

def send(self, data):
df = AGWFrame_D()
Expand Down Expand Up @@ -232,10 +235,10 @@ def agw_recv_frame(s):
f.unpack(data)
data = ""
except Exception as e:
#print("Failed: %s" % e)
#printlog("Failed: %s" % e)
continue
prin("Agw : %s -> %s [%s]" % (f.get_from(), f.get_to(), chr(f.kind)))
utils.hexprint(f.get_payload())
utils.hexprintlog(f.get_payload())
return

def test_raw_recv(s):
Expand Down Expand Up @@ -264,17 +267,17 @@ def test_class_connect():
agw = AGWConnection("127.0.0.1", 8000, 0.5)
axc = AGW_AX25_Connection(agw, "KK7DS")
axc.connect("N7AAM-11")
print(("Agw : %s" % axc.recv_text()))
printlog(("Agw : %s" % axc.recv_text()))

while True:
print("Agw : packet> ")
printlog("Agw : packet> ")
l = sys.stdin.readline().strip()
if len(l) > 0:
axc.send(l + "\r")
r = True
while r:
r = axc.recv_text()
print(("Agw : %s" % r))
printlog(("Agw : %s" % r))

axc.disconnect()

Expand Down Expand Up @@ -337,7 +340,7 @@ def transmit_data(conn, dcall, spath, data):
0xF0) # PID: No layer 3
d += data

utils.hexprint(d)
utils.hexprintlog(d)

f = AGWFrame_K()
f.set_payload(d)
Expand Down
17 changes: 10 additions & 7 deletions d_rats/ax25.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import absolute_import
from __future__ import print_function
#importing printlog() wrapper
from .debug import printlog

from six.moves import range
bstr_pos = lambda n: n>0 and bstr_pos(n>>1)+str(n&1) or ''

Expand All @@ -21,15 +24,15 @@ def _store_bit(self, bit):
self.ones += 1
else:
self.ones = 0
print(("Register: %s" % bstr_pos(self.register)))
printlog(("Register: %s" % bstr_pos(self.register)))
self.bits += 1
if self.bits == 8:
print("Ax25 : Pushing")
printlog("Ax25 : Pushing")
self.push()

def store_bit(self, bit):
if bit and self.ones == 5:
print("Stuffing!")
printlog("Stuffing!")
self._store_bit(0)
self._store_bit(bit)

Expand All @@ -53,8 +56,8 @@ def bitstuff(data):

data = "\xFF\xFF\xFF"

print("Start:")
hexprint(data)
printlog("Start:")
hexprintlog(data)

print("\nStuffed:")
hexprint(bitstuff(data))
printlog("\nStuffed:")
hexprintlog(bitstuff(data))
11 changes: 7 additions & 4 deletions d_rats/cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

from __future__ import absolute_import
from __future__ import print_function
#importing printlog() wrapper
from .debug import printlog

import libxml2
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
import tempfile
Expand All @@ -25,7 +28,7 @@
try:
from hashlib import md5
except ImportError:
print("Installing hashlib replacement hack")
printlog("Installing hashlib replacement hack")
from .utils import ExternalHash as md5

def ev_cmp_exp(ev1, ev2):
Expand Down Expand Up @@ -114,7 +117,7 @@ def __init__(self, filename):
hashes.append(hash.digest())

except Exception as e:
print(("Unable to parse CAP node: %s (%s)" % (child.name, e)))
printlog(("Unable to parse CAP node: %s (%s)" % (child.name, e)))

child = child.next

Expand Down Expand Up @@ -156,8 +159,8 @@ def __init__(self, url):

c = 0
for i in cp.events_expiring_after(epoch):
print((i.report()))
printlog((i.report()))
c += 1

print(("%i events" % c))
printlog(("%i events" % c))

Loading

0 comments on commit 8a3b651

Please sign in to comment.