-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dictionary for log messages #55
Conversation
This reverts commit dc8fc5b.
Pull Request Test Coverage Report for Build 566
💛 - Coveralls |
from .file_convertor import FileConvertor | ||
|
||
__all__ = [ | ||
"FileConvertor"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
converter vs convertor ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ug the pain when even @alan-stokes notices spelling mistakes.
Fixed
|
||
class Convertor(object): | ||
# __slots__ = [ | ||
# "_dest", "_dest_basename", "_src", "_src_basename"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Planned on doing when I stopped changing my mine and then forgot.
Fixed
# __slots__ = [ | ||
# "_dest", "_dest_basename", "_src", "_src_basename"] | ||
|
||
def __init__(self, src, dest, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs on what these params are would be useful. plus its a constructor, docs on its inputs always usful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok done!
print("Unexpected file {}".format(source)) | ||
|
||
def _get_id(self): | ||
RANGE_PER_DIR = 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic number inside function, push to class level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Picky
raise Exception("mkdir failed {}".format(destination)) | ||
|
||
def _find_common_based_on_environ(self): | ||
if 'SPINN_DIRS' not in os.environ: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make into magic_param as then if we ever change it, you only need change it in one place. this method has 2 of each already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"{} {}\n" Here I disagree with making this a CONSTANT or even a magic. Keep the line needing parameters with the code that provides them.
def run(self): | ||
self._mkdir(self._dest) | ||
with open(self._dict, 'w') as dict_f: | ||
dict_f.write("Id,Preface,Original\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create text as magic param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there called CONSTANTS
def _get_id(self): | ||
RANGE_PER_DIR = 1000 | ||
|
||
rangefile = os.path.join(RANGE_DIR, "log.ranges") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.ranges (magic name?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added CONSTANT as don't do magic
self._too_many_lines = 2 | ||
self._status = NORMAL_CODE | ||
for self._line_num, self._text in enumerate(src_f): | ||
if self._too_many_lines > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._too_many_lines not created during constructor, nor in slots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for _status, _line_num, _test, _comment_start,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added to slots. CRITICAL!
Did not add to init as I actually prefer the never created error over the null pointer error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phft to you. ill bring in rowley tomorrow and we can have a mediator on whom is right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick check shows that too_many_lines is set on line 60 then used in the next few lines within the same function. There is one reference outside the function where this variable is added to - however this addition seems to then be ignored... this seems incorrect; the variable can probably either be local or should be dealt with correctly later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_text looks lime it should be passed in to the processing functions - this makes tracing it easier and the code easier to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like _line_num can also be passed down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_comment_start looks to be write-only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too_many_lines is added to in
_write_log_method which is called from
_process_line_in_log (and others) which is called from
_process_line (and others) which is called from
inside the for loop which does skip lines in based on -_too_many_lines
but so far falls over on a TOKEN in a /* */ style comment. | ||
If needed could be altered to handle those as well. | ||
|
||
Also note that is is just a safety check and not stricktly required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strictly vs stricktly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nuked whole method
import re | ||
import sys | ||
|
||
TOKEN = chr(30) # Record Sperator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sperator vs separator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chr(40) is the ( symbol. not a record separator/TOKEN. not sure if this is a good name for what your looking for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
30 != 40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, the correct separator would be the Unit Separator, chr(31)
, as that was intended to be the separator between fields (why “unit”? I don't know…) but practically it could be anything unlikely to otherwise occur in normal output so it isn't worth changing.
assert self._status == NORMAL_CODE | ||
return self._process_line_normal_code(dest_f) | ||
|
||
def _check_token(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole method isnt used anywhere that i can find (and wouldnt work for a function definition).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nuked dead code that was confusing Alan.
return self._process_line_in_log(dest_f) | ||
|
||
def _process_line_normal_code(self, dest_f): | ||
# Fast check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont think you need the faster one. when your doing both and the second covers the first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nuked faster method as wasted more time remembering it then it will ever save
|
||
There is aslo the assumption that the start status is not COMMENT | ||
|
||
:param dest_f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fill in docs
|
||
def _write_log_method(self, dest_f, tail=""): | ||
self._message_id += 1 | ||
self._log_full = self._log_full.replace('""', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing in constructor self._log_full
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing self._log_lines in constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to slots but rather not add to init
# Writing an extra newline here so need to recover that ASAP | ||
self._too_many_lines += 1 | ||
end = tail + "\n" | ||
if (self._log_lines <= 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant brackets
self._line_num + 1, | ||
original[1:-1])) | ||
|
||
def _process_chars(self, dest_f): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is way too big, break up into status level processes.
|
||
def __init__(self, dict_pointer): | ||
self._messages = {} | ||
rest, extension = os.path.splitext(dict_pointer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extension redundant, replace with _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nuked
|
||
|
||
if __name__ == '__main__': | ||
replacer = Replacer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs filling in, wont work currently. missing parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nuked broken main not needed
logger.error("Unable to find a dictionary file at {}" | ||
.format(dict_path)) | ||
|
||
def replace(self, short): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
am yet to find whats calling this...... more a comment to chase this up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buffer extractor
changes requested done or disagreed with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a point of clarification...
self._log_full += (";") | ||
self._write_log_method(dest_f, line_num) | ||
pos = text.index(";") + 1 | ||
write_flag == pos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be write_flag = pos?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
Part of SpiNNakerManchester/spinnaker_tools#75
Does not break if merged earlier
--
Code to convert c files by replacing log_ messages
As well as code to put it back.