/
reqboxfileparse.py
759 lines (664 loc) · 27.4 KB
/
reqboxfileparse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
# -*- coding: utf-8 -*-
#!/usr/bin/python3.1
# Project: SIGA
# Component Name: reqboxfileparse
# Language: Python
#
# License: GNU Public License
# This file is part of the project.
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# <http://www.gnu.org/licenses/>
#
# Author: Albert De La Fuente (www.albertdelafuente.com)
# E-Mail: http://www.google.com/recaptcha/mailhide/d?k=01eb_9W_IYJ4Pm_Y9ALRIPug==&c=L15IEH_kstH8WRWfqnRyeW4IDQuZPzNDRB0KCzMTbHQ=
#
# Description: This script will parse tags within a utf8 converted
# doc file. It is mainly to be used by reqboxmodel.py
#
# Limitations: Error handling is not correctly implemented, time constraints
# The code is not clean and elegant as it should, again, time constraints
# Database tables used: None
# Thread Safe: No
# Extendable: No
# Platform Dependencies: Linux (openSUSE used)
# Compiler Options:
"""
Create a CSV file with the wireframe data based on a hierarchy.
Command Line Usage:
reqbox-fileparse {<option> <argument>}
Options:
-h, --help Print this help and exit.
Examples:
"""
import logging, sys, mmap, shutil, contextlib, codecs, re
from vlog import vlogger
import reqboxmodel as model
#sys.setdefaultencoding('utf-8')
#---- exceptions
#---- global data
VERB_NON = 0
VERB_MIN = 1
VERB_MED = 2
VERB_MAX = 3
PARSETYPE = 'utf8-win'
#PARSETYPE = 'utf8-win-crlf'
def utf8(s):
return s.encode('utf-8')
# return unicode(s, "utf-8")
def safe_unicode(obj, *args):
""" return the unicode representation of obj """
try:
return unicode(obj, *args)
except UnicodeDecodeError:
# obj is byte string
ascii_text = str(obj).encode('string_escape')
return unicode(ascii_text)
def safe_str(obj):
""" return the byte string representation of obj """
try:
return str(obj)
except UnicodeEncodeError:
# obj is unicode
return unicode(obj).encode('unicode_escape')
class tagstruc():
def __init__(self):
# Public
pass
class funstruc():
def __init__(self):
# Public
pass
class reqboxfileparser():
""" Requirements doc file parsing
Attributes:
- file: string
"""
def __init__(self):
# Public
self.filename = ''
self.funlist = []
self.fundict = {}
# Init vlogger
self.__verbosity = VERB_MAX
self.vlog = vlogger(self.__verbosity, sys.stdout)
#self.vlog = self.__log()
# Init mmap
self.__file = None
self.__f = None
pass
def parsefile(self, filename):
# Public
self.filename = filename
# Init mmap
self.__file = codecs.open(filename, encoding='utf-8', mode='r') # open(filename, 'r')
self.vlog(VERB_MIN, "opening file: %s" % filename)
self.__f = mmap.mmap(self.__file.fileno(), 0, access=mmap.ACCESS_READ)
self.__f.seek(0) # rewind
# Parsing stuff
self.getfunlist()
#self.vlog(VERB_MED, "fun = %s" % (self.funstr))
self.vlog(VERB_MED, "len(fun) = %d" % (len(self.funlist)))
self.getfundict()
self.vlog(VERB_MED, "fundict = %s" % (self.fundict))
pass
def __del__(self):
self.fundict.clear()
if self.__f:
self.__f.close()
if self.__file:
self.__file.close()
del self.funlist
del self.fundict
del self.__f
del self.__file
pass
#---- internal support stuff
def parsingasutf8_win(self):
return PARSETYPE == 'utf8-win'
def parsingasutf8_win_crlf(self):
return PARSETYPE == 'utf8-win-crlf'
def __cleanfunfromindex_oo(self, s):
"""
Returns a clean string from unwanted things at the index, ex:
s = '183.Gerar Relatório de Arquivo de Retorno (Bancos) 67'
result = 'Gerar Relatório de Arquivo de Retorno (Bancos)'
Args:
s -- the string
"""
result = s.strip()
result = result.split(utf8("\t"))[0]
if result is not utf8(""):
result = result.split(utf8("."))[1]
result = result.rstrip() # Trim leading spaces (Ex: FUN 43)
result = result.lstrip()
return result
def __cleanfunfromindex_utf8_win(self, s):
"""
Returns a clean string from unwanted things at the index, ex:
s = '4. Manter Plano de Contas Padrão 6'
result = 'Manter Plano de Contas Padrão'
Args:
s -- the string
"""
result = s.strip()
if len(result.split(utf8("\t"))) > 1:
result = result.split(utf8("\t"))[1]
if result is not utf8(""):
result = result.strip()
return result
def __cleanfunfromindex_msw(self, s):
"""
Returns a clean string from unwanted things at the index, ex:
s = '183.Gerar Relatório de Arquivo de Retorno (Bancos) 67'
result = 'Gerar Relatório de Arquivo de Retorno (Bancos)'
Args:
s -- the string
"""
result = s.strip()
#result = result.rstrip() # Trim leading spaces (Ex: FUN 43)
#result = result.lstrip()
if result is not utf8(""):
self.vlog(VERB_MED, "len = '%d'" % len(result.split(utf8("\t"))))
self.vlog(VERB_MED, "result = '%s'" % result)
if result != b'\xe2\x80\x83':
result = result.split(utf8("\t"))[1]
self.vlog(VERB_MED, "RESULT IS CRAP = '%s'" % result)
#result = result.split(".")[1]
result = result.rstrip() # Trim leading spaces (Ex: FUN 43)
result = result.lstrip()
return result
def __cleanfunfromindex(self, s):
if self.parsingasutf8_win_crlf():
return self.__cleanfunfromindex_msw(s)
elif self.parsingasutf8_win():
return self.__cleanfunfromindex_utf8_win(s)
else:
return self.__cleanfunfromindex_oo(s)
def __cleanfunfrombody_oo(self, s):
"""
Returns a clean string from unwanted things at the body, ex:
s = '183. Gerar Relatório de Arquivo de Retorno (Bancos)'
result = 'Gerar Relatório de Arquivo de Retorno (Bancos)'
Args:
s -- the string
"""
result = self.__cleanfunfromindex(s)
result = result.strip()
#result = result.split("\n")[0]
#if result is not "":
# result = result.split(".")[1]
return result
def __cleanfunfrombody_msw(self, s):
"""
Returns a clean string from unwanted things at the body, ex:
s = '183. Gerar Relatório de Arquivo de Retorno (Bancos)'
result = 'Gerar Relatório de Arquivo de Retorno (Bancos)'
Args:
s -- the string
"""
#result = self.__cleanfunfromindex(s)
result = s.strip()
#result = result.split("\n")[0]
if result is not utf8(""):
#result = result.split(utf8(".\t"))[1]
result = result.split(utf8(".\t"))[1]
return result
def __cleanfunfrombody(self, s):
if self.parsingasutf8_win_crlf():
return self.__cleanfunfrombody_msw(s)
else:
return self.__cleanfunfrombody_oo(s)
def __getfunid(self, s):
"""
Returns the index of a funstr s, ex:
s = '183. Gerar Relatório de Arquivo de Retorno (Bancos) 67'
result = '183'
Args:
s -- the string
"""
result = s.split(utf8("."))[0]
result = result.strip()
return result
def __getfunname(self, s):
"""
Returns the index of a funstr s, ex:
s = 'RFI227. MANTER REMESSA DE CARTÃO DE IDENTIFICAÇÃO'
result = 'MANTER REMESSA DE CARTÃO DE IDENTIFICAÇÃO'
Args:
s -- the string
"""
result = s.split(utf8("."))[1]
result = result.strip()
return result
def bodystartloc(self):
# Find the position of the begining tag
self.__f.seek(0)
begintag = utf8("Lista Completa de Funcionalidades")
beginloc = self.__f.find(begintag)
# Find the position of the end tag
endtag = "Lista Completa de Funcionalidades"
if self.parsingasutf8_win_crlf() or self.parsingasutf8_win():
endtag = endtag.upper() #"LISTA COMPLETA DE FUNCIONALIDADES"
endtag = utf8(endtag)
endloc = self.__f.find(endtag, beginloc+1)
# Set the cursor at the begining tag & skip the first line
self.__f.seek(endloc)
#self.__f.readline()
#loc = self.__f.tell()
return endloc
def getfunlist(self):
"""
Fills the funlist list with all the parsed functionalities based on the index.
"""
self.vlog(VERB_MED, "-> %s" % __name__)
# Find the position of the begining tag
#begintag = "Lista Completa de Funcionalidades"
#beginloc = self.__f.find(begintag)
## Find the position of the end tag
#endtag = "LISTA COMPLETA DE FUNCIONALIDADES"
#endloc = self.__f.find(endtag, beginloc+1)
## Set the cursor at the begining tag & skip the first line
#self.__f.seek(beginloc)
self.__f.seek(0)
begintag = utf8("Lista Completa de Funcionalidades")
beginloc = self.__f.find(begintag)
endloc = self.bodystartloc()
self.__f.seek(beginloc)
self.__f.readline()
loc = self.__f.tell()
#self.vlog(VERB_MAX, "beginloc = %d" % beginloc)
#self.vlog(VERB_MAX, "endloc = %d" % endloc)
self.funlist = []
count = 0
while (loc < endloc):
line = self.__f.readline()
loc = self.__f.tell()
self.vlog(VERB_MAX, "reading line '%s' bytes = %d" % (line, loc))
line = self.__cleanfunfromindex(line)
self.vlog(VERB_MAX, "cleaned line '%s'" % (line))
if line is not utf8("") and (line != b'\xe2\x80\x83'):
self.funlist += [line]
count += 1
#if self.parsingasutf8_win_crlf():
# self.funlist += [line.decode('utf-8').upper().encode('utf-8')]
#else:
# self.funlist += [line]
#self.vlog(VERB_MED, "<- getfunlist()")
self.vlog(VERB_MED, "<- %s" % __name__)
self.vlog(VERB_MAX, "result = %s" % (self.funlist))
#self.funlist += [result]
return self.funlist
def getfundict(self):
"""
Fills the fundict property with a dict where each element is indexed
by the fun name and each value is an object from the model
"""
self.vlog(VERB_MED, "-> getfundict()")
self.__fundict = {}
beginloc = self.bodystartloc()
finalloc = self.__f.size() - 1
endloc = finalloc
self.__f.seek(beginloc)
self.vlog(VERB_MAX, "bytes = %d" % (beginloc))
count = len(self.funlist)
# Iterate on the file backwards, it's more natural and easier...
for idx, funstr in enumerate(reversed(self.funlist)):
newidx = count - idx
#newfunstr = "%s. %s" % (newidx, funstr)
#newfunstr = utf8(str(newidx) + ".\t") + funstr
fieldterm = "\r\n"
if self.parsingasutf8_win_crlf():
#newfunstr = newfunstr.decode('utf-8')
#newfunstr = utf8(newfunstr.upper())
#newfunstr = utf8("\n" + str(newidx) + ".\t") + funstr
fieldsize = 101
#newfunstr = utf8(fieldterm + str(newidx) + ".\t") + funstr
newfunstr = utf8(fieldterm + str(newidx) + ".\t")
#newfunstr = utf8(str(newidx) + ".\t") + funstr
#if len(funstr) >= fieldsize:
# #TODO: BREAKPOINT HERE
# newfunstr = newfunstr[:fieldsize] + utf8(fieldterm) # + newfunstr[fieldsize:len(newfunstr)]
# #newfunstr = utf8(fieldterm) + newfunstr[:fieldsize-2] + utf8(fieldterm) # + newfunstr[fieldsize:len(newfunstr)]
# #newfunstr = newfunstr[:fieldsize-2] # + newfunstr[fieldsize:len(newfunstr)]
# #newfunstr = funstr[:99]
#newfunstr = newfunstr.decode('utf-8').upper().encode('utf-8')
#newfunstr = newfunstr.upper()
#utf8(str(newfunstr.upper()))#.encode('utf-8')
elif self.parsingasutf8_win():
newfunstr = utf8(fieldterm + str(newidx) + ". ") # + funstr
#newfunstr = utf8(newfunstr)
pass
self.vlog(VERB_MAX, "looking for: '%s'" % (newfunstr))
#beginloc = self.__f.rfind(newfunstr, beginloc, endloc)
beginloc = 0
beginloc = self.__f.rfind(newfunstr, beginloc, endloc)
if beginloc != -1:
beginloc += 2
self.__f.seek(beginloc)
line = self.__f.readline()
fieldsize = 85
if self.parsingasutf8_win_crlf():
if len(line.strip()) > fieldsize:
print("-----------------------------------MULTILINE")
funid = self.__getfunid(line)
line = self.__cleanfunfrombody(line)
self.vlog(VERB_MAX, "found from %d to %d out of %d | '%s. %s'" % (beginloc, endloc, finalloc, funid, line))
#self.fundict[funstr] = (beginloc, endloc, funid)
# I switched the dict keys from uppercase (body) to as they are
# on the index (capitalized as they are)
currentpos = self.__f.tell()
#newidx = count - funidx
r = model.funmodel(funid, funstr, beginloc, endloc)
r.fun.reqstart = beginloc
r.fun.reqend = endloc
r.rfistart = self.funrfistart(funstr, beginloc, endloc)
r.rfnstart = self.funrfnstart(funstr, beginloc, endloc)
r.rnfstart = self.funrnfstart(funstr, beginloc, endloc)
r.rgnstart = self.funrgnstart(funstr, beginloc, endloc)
startmarkups = [r.fun.reqstart, r.rfistart, r.rfnstart, r.rnfstart, r.rgnstart, r.fun.reqend]
startmarkups.sort()
result = "FUN id=%s [bytes=%d/%d]:\t'%s'\n" % (r.fun.reqid, r.fun.reqstart, r.fun.reqend, r.fun.reqname)
print(result)
r.rfiend = self.funsecend(funstr, r.rfistart, startmarkups)
r.rfnend = self.funsecend(funstr, r.rfnstart, startmarkups)
r.rnfend = self.funsecend(funstr, r.rnfstart, startmarkups)
r.rgnend = self.funsecend(funstr, r.rgnstart, startmarkups)
#self.vlog(VERB_MED, "%s" % (self.printfun(funidx+1, funname)))
# self.fun[funname].rfi = self.fp.gettagdic(funname, 'RFI')
self.fundict[funstr] = r #(beginloc, endloc, funid)
if r.rfistart != -1:
r.rfi = self.gettagdic(funstr, 'RFI', r.rfistart, r.rfiend)
pass
if r.rfnstart != -1:
r.rfn = self.gettagdic(funstr, 'RFN', r.rfnstart, r.rfnend)
if r.rnfstart != -1:
r.rnf = self.gettagdic(funstr, 'RNF', r.rnfstart, r.rnfend)
if r.rgnstart != -1:
r.rgn = self.gettagdic(funstr, 'RGN', r.rgnstart, r.rgnend)
self.__f.seek(currentpos)
endloc = beginloc - 1
beginloc = 0
else:
# TODO: An exception should be raised here
pass
self.vlog(VERB_MED, "<- getfundict()")
pass
def funhassection(self, funstr, secstr, start=0, end=0):
"""
Returns the position in bytes if a funstr has an secstr section within,
or -1 if it is not found.
It also moves the caret on the section start
Args:
funstr -- the string
secstr -- the string
"""
if start == 0:
beginloc = self.funstart(funstr)
else:
beginloc = start
if end == 0:
endloc = self.funend(funstr)
else:
endloc = end
#self.vlog(VERB_MAX, "pos = %d" % (self.__f.tell()))
self.__f.seek(beginloc)
#self.vlog(VERB_MAX, "pos = %d" % (self.__f.tell()))
header = secstr
if self.parsingasutf8_win_crlf() or self.parsingasutf8_win():
#header = header.upper()
#header = utf8(header.decode('utf-8').upper())
header = header.decode('utf-8').upper().encode('utf-8')
# Secstr is always going to be a str, so it needs to be converted to utf8
#header = utf8(header)
found = self.__f.find(header, beginloc+1, endloc-1)
#self.vlog(VERB_MAX, "found = %d" % (found))
if not found in range(beginloc, endloc):
return -1
else:
return found
#return found in range(beginloc, endloc)
def getorderedstarts(self, funstr):
funstart = self.funstart(funstr)
funend = self.funend(funstr)
rfistart = self.funrfistart(funstr)
rfnstart = self.funrfnstart(funstr)
rnfstart = self.funrnfstart(funstr)
rgnstart = self.funrgnstart(funstr)
startmarkups = [funstart, rfistart, rfnstart, rnfstart, rgnstart, funend]
startmarkups.sort()
return startmarkups
def funsecend(self, funstr, secstart, startmarkups):
#startmarkups = self.getorderedstarts(funstr)
result = -1
#secstart = self.funrfistart(funstr)
if secstart != -1:
result = startmarkups[startmarkups.index(secstart)+1] -1
return result
def funrfistart(self, funstr, start=0, end=0):
header = "Requisitos Funcionais de Interface"
return self.funhassection(funstr, header, start, end)
def funrfiend(self, funstr, secstart, startmarkups):
#startmarkups = self.getorderedstarts(funstr)
result = -1
#secstart = self.funrfistart(funstr)
if secstart != -1:
result = startmarkups[startmarkups.index(secstart)+1]
return result
def funrfnstart(self, funstr, start=0, end=0):
header = "REQUISITOS FUNCIONAIS DE NEG"
#"Requisitos Funcionais de Negócio"
return self.funhassection(funstr, header, start, end)
def funrfnend(self, funstr, secstart, startmarkups):
#startmarkups = self.getorderedstarts(funstr)
result = -1
#secstart = self.funrfnstart(funstr)
if secstart != -1:
result = startmarkups[startmarkups.index(secstart)+1]
return result
def funrnfstart(self, funstr, start=0, end=0):
#header = "Requisitos Não Funcionais"
header = "Requisitos N"
return self.funhassection(funstr, header, start, end)
def funrnfend(self, funstr, secstart, startmarkups):
#startmarkups = self.getorderedstarts(funstr)
result = -1
#secstart = self.funrnfstart(funstr)
if secstart != -1:
result = startmarkups[startmarkups.index(secstart)+1]
return result
def funrgnstart(self, funstr, start=0, end=0):
#header = "Regras de Negócio"
header = "Regras de Neg"
return self.funhassection(funstr, header, start, end)
def funrgnend(self, funstr, secstart, startmarkups):
#startmarkups = self.getorderedstarts(funstr)
result = -1
#secstart = self.funrgnstart(funstr)
if secstart != -1:
result = startmarkups[startmarkups.index(secstart)+1]
return result
def funstart(self, funstr):
return self.fundict[funstr].fun.reqstart
#self.fundict[funstr][0]
def funend(self, funstr):
return self.fundict[funstr].fun.reqend #[1]
def funid(self, funstr):
return self.fundict[funstr].fun.reqid #[2]
def funidname(self, funstr):
funid = self.funid(funstr)
return "%s. %s" % (funid, funstr)
def search_file(self, pattern, boffset, eoffset):
self.__f.seek(boffset)
#line = f.readline()
for line in self.__f:
#m = patter.search(line)
self.vlog(VERB_MAX, "line: '%s'" % (line))
m = re.match(pattern, line)
if m:
self.vlog(VERB_MAX, "FOUND: '%s'" % (line))
search_offset = self.__f.tell() - len(line) - 1
return search_offset + m.start(), search_offset + m.end()
def tagid(self, tagstr):
return self.fundict[funstr][2]
def tagidname(self, tagstr):
funid = self.fundict[funstr][2]
return "%s. %s" % (funid, funstr)
def cleantagid(self, tagstr):
return self.fundict[funstr][2]
def cleantagbody(self, tagstr):
funid = self.fundict[funstr][2]
return "%s. %s" % (funid, funstr)
def gettagdic(self, funstr, tag, start, end):
if start != 0:
beginloc = start
else:
beginloc = self.funstart(funstr)
if end != 0:
endloc = end
else:
endloc = self.funend(funstr)
funid = self.funid(funstr)
funidstr = self.funidname(funstr)
self.__f.seek(beginloc)
loc = beginloc #self.__f.tell()
insection = 1
findstr = "^" + tag + ".*"
expr = re.compile(findstr)
findstr = utf8(findstr)
result = {}
self.vlog(VERB_MAX, "finding from %d... '%s'" % (loc, findstr))
#pos = 0
#if endpos is None:
# endpos = len(text)
#d = {}
#while 1:
# m = entityRE.search(text,pos,endpos)
# if not m:
# break
# name,charcode,comment = m.groups()
# d[name] = charcode,comment
# pos = m.end()
#return d
isfirst = 1
reqbody = ""
while insection:
line = self.__f.readline()
loc += len(line)
#self.search_file(findstr, beginloc, endloc)
m = re.search(findstr, line)#, beginloc, endloc)
#print("found error", m.)
if m and len(m.group(0)) > 9:
inbody = 1
tagitem = m.group(0)#[:6]
reqid = self.__getfunid(tagitem)
reqname = self.__getfunname(tagitem)
reqstart = self.__f.tell()
while inbody and insection:
line = self.__f.readline()
loc += len(line)
m = re.search(findstr, line)
ended = re.search("^Media\r\n", line)
if (m == None or (m != None and len(m.group(0)) > 9)) and (ended == None):
reqbody += line
inbody = (m == None or (m != None and len(m.group(0)) == 8)) and (ended == None)
insection = loc < endloc
reqend = self.__f.tell()
newreq = model.reqmodel(reqid, reqname, reqstart, reqend)
newreq.reqbody = reqbody
reqbody = ''
result[reqid] = newreq
#self.vlog(VERB_MAX, "M IS TRUE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
#print()
#resultdict[] =
#print("found error", m.group(1))
#loc = self.__f.find(findstr, loc, endloc)
self.__f.seek(loc)
insection = loc < endloc
#self.vlog(VERB_MAX, "line: '%s'" % (line))
#if cond:
# line = self.__f.readline()
# if line:
# self.vlog(VERB_MAX, "found on location %d | '%s'" % (m.start(), m.group()))
# pass
return result
pass
#def printmap(self, d):
# for k, v in d.items():
# self.vlog(VERB_MAX, "[%s] | %s" % (k, v))
def printfun(self, idx, funstr):
result = ""
if not funstr in self.fundict:
result = "ERROR %s [%s] not found, and it should exist!!!\n" % (idx, funstr)
else:
t = self.fundict[funstr]
beginloc = self.funstart(funstr)
endloc = self.funend(funstr)
funid = self.funid(funstr)
funname = funstr #.upper()
result = "FUN %s: '%s' [%d | %d]\n" % (funid, funname, beginloc, endloc)
if self.funrfistart(funstr) != -1:
result = result + "RFIs\n"
#rfidict = self.gettagdic(funstr, 'RFI')
#if self.funhasrfn(funstr):
# result = result + "RFNs\n"
#if self.funhasrnf(funstr):
# result = result + "RNFs\n"
#if self.funhasrng(funstr):
# result = result + "RNGs\n"
return result
def printf(self):
result = ""
for idx, funstr in enumerate(self.funlist):
result = result + self.printfun(idx + 1, funstr)
def __str__(self):
result = ""
for idx, funstr in enumerate(self.funlist):
result = result + self.printfun(idx + 1, funstr)
return result
#---- mainline
def main(argv):
rfp = reqboxfileparser()
if rfp.parsingasutf8_win():# rfp.parsingasutf8_win():
#rfp.parsefile("./data/LRCv12-utf8-win.txt") # SAVE AS UTF-8 in Win!!
#rfp.parsefile("./data/LRCv12-utf8-dow2unix-l.txt")
#rfp.parsefile("./data/LRCv12-win.txt")
rfp.parsefile("./data/LRCv12.txt")
elif self.parsingasutf8_win_crlf():
#rfp = reqboxfileparser("./data/LRCv12-utf8-win.txt") # SAVE AS UTF-8 in Win!!
#rfp = reqboxfileparser("./data/LRCv12-utf8-win-dos2unix.txt") # SAVE AS UTF-8 in Win!!
rfp = reqboxfileparser("./data/LRCv12-utf8-crlf.txt") # SAVE AS UTF-8 in Win!!
# Error on the body:
#1. MANTER TABELA DE RETENÇÃO TRIBUTÁRIA
#REQUISITOS FUNCIONAIS DE INTERFACE
#Nome
#Alias
#Descrição
#Critici
#dade
#RFI251. MANTER TABELA DE
#RETENÇÃO TRIBUTÁRIA
#RFI25
#1.
#rfp = reqboxfileparser("./data/Rv12w.txt")
else:
#rfp = reqboxfileparser("./data/Rv12.txt")
pass
print("INPUT: " + rfp.filename)
#rfp.vlog(VERB_MED, "%d" % (rfp.fundict['Gerar Etiqueta de Destino']))
#rfp.vlog(VERB_MED, "%d" % (rfp.fundict['Provisão para despesas futuras']))
#rfp.printmap(rfp.fundict)
#rfp.printfun("18", utf8("Manter Prontuário"))
#rfp.printfun("43", utf8("Manter Plano de Ação"))
rfp.vlog(VERB_MED, "rfp = \n%s" % (rfp))
#rfp.getrfidic(utf8("Manter Tabela de Retenção Tributária"))
del rfp
if __name__ == "__main__":
sys.exit(main(sys.argv))