Skip to content

Commit

Permalink
(WIP) Fix nasa#72, Upgrade to PyQt5 and fix/update/clean as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lbleier-GSFC committed Apr 27, 2020
1 parent 3ed7b74 commit 8fb57f9
Show file tree
Hide file tree
Showing 9 changed files with 2,489 additions and 2,458 deletions.
1,008 changes: 513 additions & 495 deletions Subsystems/cmdGui/CHeaderParser.py

Large diffs are not rendered by default.

149 changes: 72 additions & 77 deletions Subsystems/cmdGui/CommandParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,90 +17,85 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
import csv
import getopt
import subprocess
import shlex
import re
import glob
import pickle
import re
from html.parser import HTMLParser

from bs4 import BeautifulSoup
from HTMLParser import HTMLParser
from struct import *

class CommandParser(HTMLParser):

#
# Initializes allData variable
#
def reset(self):
self.allData = []
self.allhref = []
HTMLParser.reset(self)
from bs4 import BeautifulSoup

#
# Appends HTML file content to allData variable
#
def handle_data(self, text):
if text.strip() != '': # excludes new lines
self.allData.append(text.strip())
# print self.allData[-1]

#
# Appends href tag contents to hrefTags variable
#
def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
val = re.split('#', value)[0]
self.allhref.append(val)
# print self.allhref[-1]
class CommandParser(HTMLParser):

#
# Initializes allData variable
#
def reset(self):
self.allData = []
self.allhref = []
HTMLParser.reset(self)

#
# Appends HTML file content to allData variable
#
def handle_data(self, data):
if data.strip(): # excludes new lines
self.allData.append(data.strip())
# print self.allData[-1]

#
# Appends href tag contents to hrefTags variable
#
def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
val = re.split('#', value)[0]
self.allhref.append(val)
# print self.allhref[-1]


if __name__ == '__main__':

#
# Searches for and reads HTML files
#
file_list = glob.glob('../../docs/cFE UsersGuide/Doxygen/cfe__*msg_8h.html')

for html_file in file_list:
with open(html_file) as html_obj:

# initializes variables
print '\n', 'FILE:', html_file
reader = html_obj.read()
soup = BeautifulSoup(reader)
cmdNames = [] # names of commands
cmdCodes = [] # command codes
htmlFiles = [] # HTML files with parameter information

# gets HTML file names
for link in soup.findAll(text="Command Structure"):
htmlFile = link.find_next('a')['href'] # next element with 'a' tag
htmlFile = re.split('\.', htmlFile)[0]
htmlFiles.append(htmlFile.encode('ascii'))

# gets command names and command codes
for names in soup.findAll(text="Name:"): # finds all 'Name:' text
pre_cmdCode = names.find_previous('td').get_text()
cmdCode = pre_cmdCode.split()[-1]
cmdCodes.append(cmdCode.encode('ascii'))
cmdName = names.next_element.get_text() # finds next text element
cmdNames.append(cmdName.encode('ascii'))

# prints values after iterating through whole file
print 'CMD NAMES:', cmdNames
print 'CMD CODES:', cmdCodes
print 'HTML FILES:', htmlFiles

# writes data to pickle file
pickle_file = 'CommandFiles/' + re.split('/|\.', html_file)[-2]
with open(pickle_file, 'wb') as pickle_obj:
pickle.dump([cmdNames, cmdCodes, htmlFiles], pickle_obj)


#
# Searches for and reads HTML files
#
file_list = glob.glob(
'../../docs/cFE UsersGuide/Doxygen/cfe__*msg_8h.html')

for html_file in file_list:
with open(html_file) as html_obj:

# initializes variables
print('\nFILE:', html_file)
reader = html_obj.read()
soup = BeautifulSoup(reader)
cmdNames = [] # names of commands
cmdCodes = [] # command codes
htmlFiles = [] # HTML files with parameter information

# gets HTML file names
for link in soup.findAll(text="Command Structure"):
htmlFile = link.find_next('a')[
'href'] # next element with 'a' tag
htmlFile = re.split(r'\.', htmlFile)[0]
htmlFiles.append(htmlFile.encode('ascii'))

# gets command names and command codes
for names in soup.findAll(text="Name:"): # finds all 'Name:' text
pre_cmdCode = names.find_previous('td').get_text()
cmdCode = pre_cmdCode.split()[-1]
cmdCodes.append(cmdCode.encode('ascii'))
cmdName = names.next_element.get_text(
) # finds next text element
cmdNames.append(cmdName.encode('ascii'))

# prints values after iterating through whole file
print('CMD NAMES:', cmdNames)
print('CMD CODES:', cmdCodes)
print('HTML FILES:', htmlFiles)

# writes data to pickle file
pickle_file = 'CommandFiles/' + re.split(r'/|\.', html_file)[-2]
with open(pickle_file, 'wb') as pickle_obj:
pickle.dump([cmdNames, cmdCodes, htmlFiles], pickle_obj)
Loading

0 comments on commit 8fb57f9

Please sign in to comment.