Added/fixed debug dumping of top key tuple.
diff --git a/infocalypse/requestingbundles.py b/infocalypse/requestingbundles.py --- a/infocalypse/requestingbundles.py +++ b/infocalypse/requestingbundles.py @@ -36,7 +36,7 @@ from choose import get_update_edges, dum from statemachine import RetryingRequestList, CandidateRequest -from topkey import dump_top_key_tuple +#from topkey import dump_top_key_tuple from chk import clear_control_bytes # REDFLAG: Make sure that you are copying lists. eg. updates @@ -296,8 +296,8 @@ class RequestingBundles(RetryingRequestL if self.top_key_tuple is None: raise Exception("No top key data.") - if self.parent.params.get('DUMP_TOP_KEY', False): - dump_top_key_tuple(top_key_tuple) + #if self.parent.params.get('DUMP_TOP_KEY', False): + # dump_top_key_tuple(top_key_tuple) updates = self.top_key_tuple[1] diff --git a/infocalypse/topkey.py b/infocalypse/topkey.py --- a/infocalypse/topkey.py +++ b/infocalypse/topkey.py @@ -123,16 +123,21 @@ def bytes_to_top_key_tuple(bytes): return (tuple(graph_chks), tuple(updates)) -def dump_top_key_tuple(top_key_tuple): +def default_out(text): + if text.endswith('\n'): + text = text[:-1] + print text + +def dump_top_key_tuple(top_key_tuple, out_func=default_out): """ Debugging function to print a top_key_tuple. """ - print "---top key tuple---" + out_func("---top key tuple---\n") for index, chk in enumerate(top_key_tuple[0]): - print "graph_%s:%s" % (chr(ord('a') + index), chk) + out_func("graph_%s:%s\n" % (chr(ord('a') + index), chk)) for index, update in enumerate(top_key_tuple[1]): - print "update[%i]" % index - print " length : %i" % update[0] - print " parent_rev: %s" % update[1] - print " latest_rev: %s" % update[2] + out_func("update[%i]\n" % index) + out_func(" length : %i\n" % update[0]) + out_func(" parent_rev: %s\n" % update[1]) + out_func(" latest_rev: %s\n" % update[2]) for index, chk in enumerate(update[3]): - print " CHK[%i]:%s" % (index, chk) - print "---" + out_func(" CHK[%i]:%s\n" % (index, chk)) + out_func("---\n") diff --git a/infocalypse/updatesm.py b/infocalypse/updatesm.py --- a/infocalypse/updatesm.py +++ b/infocalypse/updatesm.py @@ -40,7 +40,8 @@ from graph import INSERT_NORMAL, INSERT_ minimal_update_graph, graph_to_string, \ FREENET_BLOCK_LEN, has_version, pull_bundle, parse_graph, hex_version -from topkey import bytes_to_top_key_tuple, top_key_tuple_to_bytes +from topkey import bytes_to_top_key_tuple, top_key_tuple_to_bytes, \ + dump_top_key_tuple from statemachine import StatefulRequest, RequestQueueState, StateMachine, \ Quiescent, Canceling, RetryingRequestList, CandidateRequest, \ @@ -526,6 +527,9 @@ class InsertingUri(StaticRequestList): assert not self.parent.ctx['INSERT_URI'] is None top_key_tuple = from_state.get_top_key_tuple() + if self.parent.params.get('DUMP_TOP_KEY', False): + dump_top_key_tuple(top_key_tuple, + self.parent.ctx.ui_.status) salt = {0:0x00, 1:0xff} # grrr.... less code. insert_uris = make_frozen_uris(self.parent.ctx['INSERT_URI'], @@ -623,6 +627,10 @@ class RequestingUri(StaticRequestList): # Allow pending requests to run to completion. self.parent.ctx.orphan_requests(self) + if self.parent.params.get('DUMP_TOP_KEY', False): + dump_top_key_tuple(self.get_top_key_tuple(), + self.parent.ctx.ui_.status) + def get_top_key_tuple(self): """ Get the python rep of the data in the URI. """