Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. #=======================================================================================================================
  2. class TagDepth(object):
  3.     def __init__(self):
  4.         self.tag_depth = []
  5.  
  6.     def get_tree(self):
  7.         val = ''
  8.         for tag in self.tag_depth:
  9.             val += (tag + '|')
  10.         return val
  11.  
  12.     def rem(self):
  13.         if len(self.tag_depth) > 0:
  14.             del self.tag_depth[-1]
  15.  
  16.     def add(self, tag_name):
  17.         self.tag_depth.append(tag_name)
  18.  
  19. #=======================================================================================================================
  20.  
  21. file_name = './poms/ws/pom.xml'
  22.  
  23. tag_ex = ['modelVersion', '?xml', 'packaging']
  24.  
  25. tag_found = False
  26. row = col = 1
  27. tag_name = pc = c = ''
  28.  
  29. tag_depth = TagDepth()
  30. artifact = []
  31. with open(file_name, encoding='utf8') as file:
  32.     while True:
  33.         pc, c = c, file.read(1)
  34.         col += 1
  35.  
  36.         if c == '':
  37.             break
  38.  
  39.         if c == '\n':
  40.             row += 1
  41.             col = 1
  42.             continue
  43.  
  44.         if tag_found:
  45.             if c == '/' and pc == '<':
  46.                 tag_found = False
  47.                 tag_depth.rem()
  48.                 continue
  49.             elif c == '>':
  50.                 tag_found = False
  51.                 if len(tag_name) > 0 and not tag_name in tag_ex:
  52.                     print(row, ' ', col, ' ',  tag_depth.get_tree() + tag_name)
  53.                     tag_depth.add(tag_name)
  54.                 continue
  55.             elif c != ' ':
  56.                 tag_name += c
  57.             else:
  58.                 tag_found = False
  59.                 tag_depth.add(tag_name)
  60.  
  61.         if c == '<':
  62.             tag_found = True
  63.             tag_name = ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement