From 4a983a6771ca189754c8fb9418610a35f571e1c7 Mon Sep 17 00:00:00 2001 From: shrlnm Date: Sun, 26 Mar 2023 16:38:19 +0300 Subject: [PATCH] acf --ref option for alternative refs, plus update from command line by main.py update --- main.py | 9 ++++++ pyren3/mod_acf_func.py | 64 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9fda290..02e3f0b 100755 --- a/main.py +++ b/main.py @@ -872,6 +872,15 @@ if osname != 'android': if __name__ == '__main__': os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) + if len(sys.argv)>1 and sys.argv[1]=='update': + res = update_from_gitlab() + if res == 0: + print( "Done") + elif res == 1: + print( "No connection with gitlab.com") + elif res == 2: + print( "UnZip error") + exit() main() else: diff --git a/pyren3/mod_acf_func.py b/pyren3/mod_acf_func.py index 5531f7b..806357b 100644 --- a/pyren3/mod_acf_func.py +++ b/pyren3/mod_acf_func.py @@ -2,6 +2,7 @@ import sys import os +import time import mod_globals import zipfile import pickle @@ -30,6 +31,61 @@ class ACE(): self.req = {} self.dat = {} +def get_alternative_refs( platform ): + #finds more frequent use of ref1 from --ref otion in REF.DAT + if mod_globals.opt_ref =='': return {} + + start_time = time.time() + + res = {} + alt = {} + for aref in mod_globals.opt_ref.split(';'): + aref = aref.strip() + if (len(aref)==23 or len(aref)==24) and ' ' in aref: + #ref pair defined compleatle + idf,refPair = aref.split(':') + res[idf] = refPair + continue + idf,ref1 = aref.split(':') + if len(ref1)==10: + alt[aref] = {} + + #find in REF.DAT + try: + vindir = '../BVMEXTRACTION/'+platform+'/' + ref_name = 'REF.dat' + for fn in os.listdir(vindir): + if fn.upper()=='REF.DAT': ref_name = fn + rz = open(vindir+ref_name,'r') + reflist = rz.read().split('\n') + rz.close() + for l in reflist: + if l == '': continue + ll = l[l.find(':')+1:].split(';') + for e in ll: + for a in alt.keys(): + if e.startswith(a): + if e not in alt[a].keys(): + alt[a][e] = 1 + else: + alt[a][e] += 1 + except: + print("\n\nREF.dat is absent!!!\n\n") + + for a in alt.keys(): + max = list(alt[a].keys())[0] + for ak in alt[a].keys(): + if alt[a][ak]>alt[a][max]: max = ak + idf,refPair = max.split(':') + res[idf] = refPair + + end_time = time.time() + print( "Ref search took:", int(end_time-start_time), " sec" ) + print( res ) + + return res + + def acf_find_in_sirev( ref2, platform ): global errone global zip @@ -76,10 +132,16 @@ def acf_loadModules( de, refdata, platform ): module_list = [] + #first check mod_globals.opt_ref for alternatives + alt = get_alternative_refs( platform ) + for r in refdata.split(';'): try: idf, r1 = r.split(':') - ref1,ref2 = r1.split(' ') + if idf in alt.keys(): + ref1,ref2 = alt[idf].split(' ') + else: + ref1,ref2 = r1.split(' ') except: continue