From 2b44dba96725ef05ae47b948d5f24a1c83542e37 Mon Sep 17 00:00:00 2001 From: shrlnm Date: Wed, 9 Oct 2019 11:50:51 +0300 Subject: [PATCH] 9p doc improvements --- pyren/convert_db.py | 9 +++++- pyren/doc_maker.py | 30 +++++++++++++++---- pyren/mod_ddt_ecu.py | 67 ------------------------------------------ pyren/mod_ddt_utils.py | 4 +-- pyren/mod_ecu.py | 23 +++++++++++---- pyren/mod_globals.py | 9 ++++-- pyren/mod_utils.py | 54 +++++++++++++++++++++++++++------- pyren/pyren.py | 7 +++-- 8 files changed, 105 insertions(+), 98 deletions(-) diff --git a/pyren/convert_db.py b/pyren/convert_db.py index 2948ef9..7134e7e 100755 --- a/pyren/convert_db.py +++ b/pyren/convert_db.py @@ -29,6 +29,7 @@ if __name__ == "__main__": fbsessionfiles += glob.glob (os.path.join (ecudir, "Sessions", "FG*.xml")) fgsessionfiles = glob.glob (os.path.join (ecudir, "Sessions", "SG*.xml")) vehiclesfiles = glob.glob (os.path.join (vehicledir, "*.xml")) + dfgfiles = glob.glob (os.path.join (vehicledir, "DFG", "*.xml")) locationsfiles = glob.glob (os.path.join (locationdir, "*.bqm")) scnerariosfiles = glob.glob (os.path.join (ecudir, "Scenarios", "*.xml")) @@ -44,7 +45,13 @@ if __name__ == "__main__": f = open (vf, "r") data = f.read () zf.writestr (os.path.join ("Vehicles", os.path.basename (vf)), str (data)) - + + for vf in dfgfiles: + print "Processing file ", vf + f = open(vf, "r") + data = f.read() + zf.writestr(os.path.join("Vehicles", "DFG", os.path.basename(vf)), str(data)) + for vf in ecufiles: print "Processing file ", vf f = open (vf, "r") diff --git a/pyren/doc_maker.py b/pyren/doc_maker.py index 95c15bc..0e2dacc 100755 --- a/pyren/doc_maker.py +++ b/pyren/doc_maker.py @@ -388,9 +388,16 @@ def processXML( path, l, ff ): #ma = acf_MTC_compare_doc( sieconfigid, mtc ) #if ma: #document complines to MTC filter - title = root.find('title').text.strip() - if title=='': #check id documents refers to another - root,title = getTitleAndRef( path, ff, root, title, l ) + try: + title = root.find('title').text.strip() + except: + title = '' + + try: + if title=='': #check id documents refers to another + root,title = getTitleAndRef( path, ff, root, title, l ) + except: + pass lid = l[:-4] @@ -400,13 +407,23 @@ def processXML( path, l, ff ): if fns[4]!='000000': title = 'DTC'+fns[4]+' '+title - + + dtcId = '' + if fns[4]!='000000' and fns[5]=='104': + dtcId = fns[4] + #add line to bookmark #cop = et.SubElement(h_o, 'p') #coa = et.SubElement(cop, 'a', href='#'+l[:-4]).text = title + nel = et.Element('div') et.SubElement(nel, 'hr', attrib={'id':lid}) - et.SubElement(nel, 'a', attrib={'href':'#home'}).text = "Up" + + if dtcId!='': + et.SubElement(nel, 'a', attrib={'href':'#home','id':dtcId}).text = "Up" + else: + et.SubElement(nel, 'a', attrib={'href':'#home'}).text = "Up" + convertXML( root, nel, fns, ff, lid ) return nel, lid, title @@ -480,6 +497,7 @@ def f_functions( dfg_dom, ff, of, pref, domname, path ): of.remove( l ) cop = et.SubElement(dom_dtc_o, 'p') et.SubElement(cop, 'a', href='#'+lid).text = title + print lid,';',title dom_t.append(nel) cop = et.SubElement(dom_o, 'p') @@ -604,7 +622,7 @@ def generateHTML(path, mtc, vin, dfg, date_madc ): h_o.append(oth_o) tree = et.ElementTree(doc) - tree.write('./'+vin+'.htm', encoding='UTF-8', xml_declaration=True, default_namespace=None, method='html') + tree.write('./doc/'+vin+'.htm', encoding='UTF-8', xml_declaration=True, default_namespace=None, method='html') print '\r\tDone:100%' vin_opt = '' diff --git a/pyren/mod_ddt_ecu.py b/pyren/mod_ddt_ecu.py index 7d35f47..9eaf848 100755 --- a/pyren/mod_ddt_ecu.py +++ b/pyren/mod_ddt_ecu.py @@ -284,17 +284,6 @@ class DDTECU(): eculist = mod_ddt_utils.loadECUlist() - ##make or load eculist - #print "Loading eculist" - #eculistcache = "./cache/ddt_eculist.p" - # - #if os.path.isfile(eculistcache): #if cache exists - # eculist = pickle.load( open( eculistcache, "rb" ) ) #load it - #else: #else - # eculist = mod_ddt_utils.loadECUlist() #loading original data - # if eculist == None: return #return if no eculist file - # pickle.dump( eculist, open( eculistcache, "wb" ) ) #and save cache - mod_ddt_utils.searchddtroot() if len(mod_globals.opt_ddtxml)>0: @@ -363,62 +352,6 @@ class DDTECU(): if di.Name not in self.cmd4data.keys(): self.cmd4data[di.Name] = r.Name - ''' - def loadECUlist(self): - - global eculist - - #open xml - if not os.path.isfile('../ecus/eculist.xml'): - print "No such file: ../ecus/eculist.xml" - return None - - ns = {'ns0': 'http://www-diag.renault.com/2002/ECU', - 'ns1': 'http://www-diag.renault.com/2002/screens'} - - tree = et.parse ('../ecus/eculist.xml') - root = tree.getroot () - - eculist = {} - #print et.dump(root) - functions = root.findall("Function") - if len(functions): - for function in functions: - Address = hex(int(function.attrib["Address"])).replace("0x","").zfill(2).upper() - eculist[Address] = {} - FuncName = function.attrib["Name"] - targets = function.findall("Target") - eculist[Address]["FuncName"] = FuncName - eculist[Address]["targets"] = {} - if len(targets): - for target in targets: - href = target.attrib["href"] - eculist[Address]["targets"][href] = {} - pjc = target.findall("Projects") - if len(pjc)>0: - pjcl = [elem.tag.upper() for elem in pjc[0].iter()][1:] - else: - pjcl = [] - eculist[Address]["targets"][href]['Projects'] = pjcl - ail = [] - ais = target.findall("AutoIdents") - if len(ais): - for ai in ais: - AutoIdents = ai.findall("AutoIdent") - if len(AutoIdents): - for AutoIdent in AutoIdents: - air = {} - air['DiagVersion'] = AutoIdent.attrib["DiagVersion"].strip() - air['Supplier'] = AutoIdent.attrib["Supplier"].strip() - air['Soft'] = AutoIdent.attrib["Soft"].strip() - air['Version'] = AutoIdent.attrib["Version"].strip() - #if len(DiagVersion)==1 : DiagVersion = '0'+DiagVersion - #hash = Address+DiagVersion+Supplier+Soft+Version - #eculist[hash] = href - ail.append(air) - eculist[Address]["targets"][href]['AutoIdents'] = ail - ''' - def saveDump( self ): ''' save responces from all 21xx, 22xxxx commands ''' diff --git a/pyren/mod_ddt_utils.py b/pyren/mod_ddt_utils.py index f195e55..aabecd2 100644 --- a/pyren/mod_ddt_utils.py +++ b/pyren/mod_ddt_utils.py @@ -86,7 +86,7 @@ def loadECUlist(): eculistcache = "./cache/ddt_eculist.p" if os.path.isfile(eculistcache): # if cache exists - eculist = pickle.load(open(eculistcache, "rb")) # load it + eculist = pickle.load(open(eculistcache, "rb")) # load it #dbaccess else: # open xml @@ -135,7 +135,7 @@ def loadECUlist(): air['Version'] = AutoIdent.attrib["Version"].strip() ail.append(air) eculist[Address]["targets"][href]['AutoIdents'] = ail - pickle.dump(eculist, open(eculistcache, "wb")) # and save cache + pickle.dump(eculist, open(eculistcache, "wb")) # and save cache #dbaccess return eculist diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 1bf0256..55a9f0c 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -23,6 +23,7 @@ import mod_globals from xml.dom.minidom import parse from datetime import datetime +from mod_utils import show_doc import xml.dom.minidom import xml.etree.ElementTree as et import struct @@ -375,13 +376,22 @@ class ECU: #if mod_globals.os == 'android': # csv_filename = csv_filename.encode("ascii","ignore") csvf = open("./csv/"+pyren_encode(csv_filename), "wt") - + + DTCpos = path.find('DTC') + if DTCpos > 0: + IDstr = '#' + path[DTCpos+3:DTCpos + 9] + else: + IDstr = '' + + #debug + #show_doc(self.ecudata['dst'], IDstr) + kb = KBHit() tb = time.time() #time of begining if len(datarefs)==0 and 'DE' not in path: return - + page = 0 while(True): @@ -455,9 +465,9 @@ class ECU: newScreen = newScreen + pyren_encode( l ) + ' \n' if pages>0: - newScreen = newScreen+'\n'+"[Page "+str(page+1)+" from "+str(pages+1)+"] Press page number to switch or any other to exit" + newScreen = newScreen+'\n'+"[Page "+str(page+1)+" from "+str(pages+1)+"] N for page number H for help or any other to exit" else: - newScreen = newScreen+'\n'+"Press any key to exit" + newScreen = newScreen+'\n'+"Press H for help or any key to exit" print newScreen, sys.stdout.flush () @@ -479,6 +489,9 @@ class ECU: page = n-1 clearScreen() continue + if c in ['h','H']: + show_doc(self.ecudata['dst'], IDstr) + continue if mod_globals.opt_csv and (c in mod_globals.opt_usrkey): csvline += ";" + c continue @@ -579,7 +592,7 @@ class ECU: path = path+' -> '+defstr[dtchex]+'\n\n'+hlpstr[dtchex]+'\n' - self.show_datarefs(self.Defaults[dtchex[:4]].datarefs, path) + self.show_datarefs(self.Defaults[dtchex[:4]].datarefs, path) def show_defaults_std_b(self): while(1): diff --git a/pyren/mod_globals.py b/pyren/mod_globals.py index bb66ee7..450fbc7 100755 --- a/pyren/mod_globals.py +++ b/pyren/mod_globals.py @@ -39,13 +39,16 @@ currentDDTscreen = None ext_cur_DTC = "000000" -none_val = 'None' +none_val = "None" -mtcdir = '../MTCSAVE/VIN' +mtcdir = "../MTCSAVE/VIN" -ddtroot = '..' # parent folder for backward compatibility. for 9n and up use ../DDT2000data +ddtroot = ".." # parent folder for backward compatibility. for 9n and up use ../DDT2000data os = "" language_dict = {} +vin = "" + +doc_server_proc = None \ No newline at end of file diff --git a/pyren/mod_utils.py b/pyren/mod_utils.py index 7699287..e497212 100755 --- a/pyren/mod_utils.py +++ b/pyren/mod_utils.py @@ -14,7 +14,14 @@ GNU General Public License for more details. import sys import os +import signal +import atexit +import subprocess import mod_globals +try: + import webbrowser +except: + pass # Snippet from http://home.wlu.edu/~levys/software/kbhit.py @@ -25,9 +32,9 @@ if os.name == 'nt': # Posix (Linux, OS X) else: import termios - import atexit + #import atexit from select import select - from decimal import * + #from decimal import * class KBHit: @@ -379,14 +386,16 @@ def chkDirTree(): os.makedirs('./dumps') if not os.path.exists('./macro'): os.makedirs('./macro') + if not os.path.exists('./doc'): + os.makedirs('./doc') -def getVIN( de, elm ): +def getVIN( de, elm, getFirst = False ): ''' getting VINs from every ECU ''' ''' de - list of detected ECUs ''' ''' elm - reference to ELM class ''' - m_vin = {} + m_vin = set([]) for e in de: # init elm @@ -406,19 +415,21 @@ def getVIN( de, elm ): rsp = elm.request( req = '22F190', positive = '62', cache = False )[9:59] else: rsp = elm.request( req = '2181', positive = '61', cache = False )[6:56] - + try: vin = rsp.replace(' ','').decode('HEX') except: continue #debug - print e['dst'],' : ', vin + #print e['dst'],' : ', vin if len(vin)==17: - m_vin[vin] = '' + m_vin.add(vin) + if getFirst: + return vin - l_vin = m_vin.keys() + l_vin = m_vin if os.path.exists('savedVIN.txt'): with open('savedVIN.txt') as vinfile: @@ -427,14 +438,14 @@ def getVIN( de, elm ): l = l.strip() if '#' in l: continue if len(l)==17: - l_vin.append(l.upper()) + l_vin.add(l.upper()) - if len(l_vin)==0: + if len(l_vin)==0 and not getFirst: print "ERROR!!! Can't find any VIN. Check connection" exit() if len(l_vin)<2: - return l_vin[0] + return next(iter(l_vin)) print "\nFound ",len(l_vin), " VINs\n" @@ -446,3 +457,24 @@ def DBG( tag, s ): if mod_globals.opt_debug and mod_globals.debug_file!=None: mod_globals.debug_file.write( '### ' + tag + '\n') mod_globals.debug_file.write( '"' + s + '"\n') + +def kill_server(): + if mod_globals.doc_server_proc is None: + pass + else: + os.kill(mod_globals.doc_server_proc.pid, signal.SIGTERM) + +def show_doc( addr, id ): + if mod_globals.vin == '': + return + + if mod_globals.doc_server_proc == None: + mod_globals.doc_server_proc = subprocess.Popen(["python", "-m", "SimpleHTTPServer", "59152"]) + atexit.register(kill_server) + + url = 'http://localhost:59152/doc/'+mod_globals.vin+'.htm'+id + webbrowser.open(url, new=0) + + + + diff --git a/pyren/pyren.py b/pyren/pyren.py index 09aa714..f9db4c0 100755 --- a/pyren/pyren.py +++ b/pyren/pyren.py @@ -247,8 +247,8 @@ def main(): print 'Loading ECUs list' se = ScanEcus(elm) #Prepare list of all ecus - - SEFname = "savedEcus.p" + + SEFname = "savedEcus.p" if mod_globals.opt_can2: SEFname = "savedEcus2.p" @@ -272,7 +272,8 @@ def main(): # Do this check every time se.scanAllEcus() #First scan of all ecus - + mod_globals.vin = getVIN(se.detectedEcus, elm, getFirst=True) + print "Loading language " sys.stdout.flush() #loading language data