meta data for this page
  •  

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Következő változat
Előző változat
shell:riportok:gather_data:dsmadmc_to_excel.sh [2026/03/03 20:22] – létrehozva adminshell:riportok:gather_data:dsmadmc_to_excel.sh [2026/03/03 21:29] (aktuális) admin
Sor 1: Sor 1:
 +<WRAP prewrap>
 +<file sh dsmadmc_to_excel.sh>
 #!/bin/bash #!/bin/bash
 set -e set -e
Sor 21: Sor 23:
  
 def convert_value(val): def convert_value(val):
-    """Szöveget számmá alakít ha lehet.""" 
     if not val or not isinstance(val, str):     if not val or not isinstance(val, str):
         return val         return val
Sor 27: Sor 28:
     if not val:     if not val:
         return val         return val
-    # Ezres elválasztó vessző eltávolítása (pl. "1,234.56" -> "1234.56") 
-    # De csak ha tizedesponttal van (angol formátum) 
     cleaned = val     cleaned = val
     if ',' in val and '.' in val:     if ',' in val and '.' in val:
-        # Angol formátum: 1,234.56 
         cleaned = val.replace(',', '')         cleaned = val.replace(',', '')
     elif ',' in val and '.' not in val:     elif ',' in val and '.' not in val:
-        # Lehet magyar formátum (1.234,56) vagy sima ezres (1,234) 
-        # Ellenőrizzük, hogy a vessző után 3 számjegy van-e (ezres elválasztó) 
         parts = val.split(',')         parts = val.split(',')
         if len(parts) == 2 and len(parts[1]) == 3 and parts[1].isdigit():         if len(parts) == 2 and len(parts[1]) == 3 and parts[1].isdigit():
-            # Ezres elválasztó: 1,234 -> 1234 
             cleaned = val.replace(',', '')             cleaned = val.replace(',', '')
         elif len(parts) == 2 and parts[1].replace('-','').isdigit():         elif len(parts) == 2 and parts[1].replace('-','').isdigit():
-            # Magyar tizedes: 1234,56 -> 1234.56 
             cleaned = val.replace(',', '.')             cleaned = val.replace(',', '.')
-     
-    # Próbáljuk int-ként 
     try:     try:
         if '.' not in cleaned and cleaned.lstrip('-').isdigit():         if '.' not in cleaned and cleaned.lstrip('-').isdigit():
Sor 50: Sor 42:
     except:     except:
         pass         pass
-     
-    # Próbáljuk float-ként 
     try:     try:
         f = float(cleaned)         f = float(cleaned)
-        # Ha egész szám, int-ként adjuk vissza 
         if f == int(f) and abs(f) < 1e15:         if f == int(f) and abs(f) < 1e15:
             return int(f)             return int(f)
Sor 60: Sor 49:
     except:     except:
         pass         pass
-     
     return val     return val
 +
 +def looks_like_number(val):
 +    """Ellenorzi, hogy az ertek szamnak tunik-e (szamjegyek, vesszo, pont)."""
 +    if not val:
 +        return False
 +    # Csak szamjegyek, vesszo, pont, szokoz, minusz
 +    cleaned = val.replace(',', '').replace('.', '').replace(' ', '').replace('-', '')
 +    return cleaned.isdigit()
  
 def remove_hdr(c): def remove_hdr(c):
-    ls=c.split('\n');r=[];ds=False+    ls = c.split('\n') 
 +    r = [] 
 +    ds = False
     for l in ls:     for l in ls:
-        if 'ANS8000I' in l:ds=True;continue +        if 'ANS8000I' in l: 
-        if l.strip().startswith('ANS800'):continue+            ds = True 
 +            continue 
 +        if l.strip().startswith('ANS800'): 
 +            continue
         if not ds:         if not ds:
-            if any(x in l for x in ['IBM Spectrum','Command Line','(c) Copyright','Session established','Server Version','Server date','Last access']):continue +            if any(x in l for x in ['IBM Spectrum', 'Command Line', '(c) Copyright',  
-            if l.strip()=='' and not r:continue +                                     'Session established', 'Server Version', 'Server date', 'Last access']): 
-        if ds:r.append(l) +                continue 
-    if not r:r=[l for l in ls if not any(x in l for x in ['IBM Spectrum','Command Line','(c) Copyright','Session established','Server Version','Server date','Last access'])]+            if l.strip() == '' and not r: 
 +                continue 
 +        if ds: 
 +            r.append(l) 
 +    if not r: 
 +        r = [l for l in ls if not any(x in l for x in ['IBM Spectrum', 'Command Line',  
 +             '(c) Copyright', 'Session established', 'Server Version', 'Server date', 'Last access'])]
     return '\n'.join(r)     return '\n'.join(r)
  
 def parse_fw(c): def parse_fw(c):
-    ls=c.split('\n');di=None +    ls = c.split('\n') 
-    for i,l in enumerate(ls): +     
-        if re.match(r'^[\s-]+$',l) and l.count('-')>10:di=i;break +    di = None 
-    if di is None or di==0:return None +    for i, l in enumerate(ls): 
-    hl=ls[:di];dl=ls[di];dls=ls[di+1:+        if re.match(r'^[\s-]+$', l) and l.count('-') > 10: 
-    cp=[];ind=False;st=0 +            di = i 
-    for i,ch in enumerate(dl): +            break 
-        if ch=='-' and not ind:ind=True;st=i +    if di is None or di == 0: 
-        elif ch!='-' and ind:ind=False;cp.append((st,i)) +        return None 
-    if ind:cp.append((st,len(dl))) +     
-    if not cp:return None +    header_end = di 
-    hd=[] +    header_start = di 
-    for s,e in cp: +    for i in range(di - 1, -1, -1): 
-        pts=[]+        line = ls[i].strip() 
 +        if line == '': 
 +            header_start = i + 1 
 +            break 
 +        header_start = i 
 +     
 +    hl = ls[header_start:header_end] 
 +    dl = ls[di] 
 +    dls = ls[di + 1:] 
 +     
 +    cp = [] 
 +    ind = False 
 +    st = 0 
 +    for i, ch in enumerate(dl): 
 +        if ch == '-' and not ind: 
 +            ind = True 
 +            st = i 
 +        elif ch != '-' and ind: 
 +            ind = False 
 +            cp.append((st, i)) 
 +    if ind: 
 +        cp.append((st, len(dl))) 
 +    if not cp: 
 +        return None 
 +     
 +    hd = [] 
 +    for s, e in cp: 
 +        pts = []
         for h in hl:         for h in hl:
-            if len(h)>s: +            if len(h) > s: 
-                p=h[s:min(e,len(h))].strip().replace('-',''+                p = h[s:min(e, len(h))].strip() 
-                if p:pts.append(p)+                if p and p not in ['-', '--']: 
 +                    pts.append(p.replace('-', ''))
         hd.append(' '.join(pts))         hd.append(' '.join(pts))
-    res=[hd];cr=None+     
 +    res = [hd] 
 +    cr = None 
 +    prev_had_hyphen = False 
 +    
     for l in dls:     for l in dls:
-        if not l.strip() or l.strip().startswith('ANS'):continue +        if not l.strip()
-        fc=l[:cp[0][1]].strip() if cp else '' +            continue 
-        ic=(fc=='' and l.strip()) +        if l.strip().startswith('ANS'): 
-        if ic and cr: +            continue 
-            for idx,(s,e) in enumerate(cp): +         
-                if len(l)>s: +        first_col_raw = l[:cp[0][1]] if cp else '' 
-                    cl=l[s:min(e,len(l))].strip() +        first_col_val first_col_raw.strip(
-                    if cl+         
-                        if cr[idx].endswith('-'):cr[idx]=cr[idx][:-1]+cl +        is_continuation = False 
-                        elif cr[idx]:cr[idx]+=cl +        if first_col_val == '' and l.strip()
-                        else:cr[idx]=cl+            is_continuation = True 
 +        elif prev_had_hyphen and len(l> 0 and l[0] == ' ': 
 +            is_continuation = True 
 +         
 +        if is_continuation and cr is not None
 +            for idx, (s, e) in enumerate(cp): 
 +                cell_val = l[s:min(e, len(l))].strip() if len(l) > s else '' 
 +                if cell_val
 +                    prev_val = cr[idx] 
 +                    if prev_val: 
 +                        if prev_val.endswith('-'): 
 +                            # Kotojellel vegzodik -> egybeírjuk 
 +                            cr[idx] = prev_val[:-1] + cell_val 
 +                        elif looks_like_number(prev_val) and looks_like_number(cell_val): 
 +                            # Mindketto szam -> egybeírjuk (szam tortese) 
 +                            cr[idx] = prev_val + cell_val 
 +                        else: 
 +                            # Szoveg -> szokozzel 
 +                            cr[idx] = prev_val + ' ' + cell_val 
 +                    else: 
 +                        cr[idx] = cell_val 
 +            prev_had_hyphen = any(v.endswith('-') for v in cr if v)
         else:         else:
-            if cr:res.append([convert_value(re.sub(r'-\s*','',x).strip()) for x in cr]+            if cr is not None: 
-            cr=[] +                cleaned = [
-            for s,e in cp:cr.append(l[s:min(e,len(l))].strip() if len(l)>s else ''+                for val in cr: 
-    if cr:res.append([convert_value(re.sub(r'-\s*','',x).strip()) for x in cr])+                    if val: 
 +                        val = re.sub(r'-\s+', '', val) 
 +                        val = re.sub(r'\s+', ' ', val) 
 +                        val = val.strip() 
 +                    cleaned.append(convert_value(val)) 
 +                res.append(cleaned) 
 +             
 +            cr = [] 
 +            for s, e in cp: 
 +                cr.append(l[s:min(e, len(l))].strip() if len(l) > s else ''
 +            prev_had_hyphen = any(v.endswith('-') for v in cr if v) 
 +     
 +    if cr is not None: 
 +        cleaned = [
 +        for val in cr: 
 +            if val: 
 +                val = re.sub(r'-\s+', '', val) 
 +                val = re.sub(r'\s+', ' ', val) 
 +                val = val.strip() 
 +            cleaned.append(convert_value(val)) 
 +        res.append(cleaned) 
 +    
     return res     return res
  
 def parse_csv(c): def parse_csv(c):
-    ls=c.strip().split('\n');r=[]+    ls = c.strip().split('\n') 
 +    r = []
     for l in ls:     for l in ls:
-        if not l.strip() or l.strip().startswith('ANS'):continue+        if not l.strip() or l.strip().startswith('ANS'): 
 +            continue
         try:         try:
-            rd=csv.reader(StringIO(l))+            rd = csv.reader(StringIO(l))
             for rw in rd:             for rw in rd:
-                if rw:r.append([convert_value(x.strip()) for x in rw]) +                if rw: 
-        except:r.append([convert_value(x.strip().strip('"')) for x in l.split(',')])+                    r.append([convert_value(x.strip()) for x in rw]) 
 +        except: 
 +            r.append([convert_value(x.strip().strip('"')) for x in l.split(',')])
     return r if r else None     return r if r else None
  
 def parse_sys(c): def parse_sys(c):
-    secs=re.split(r'\*{10,}',c);ad=[]+    secs = re.split(r'\*{10,}', c) 
 +    ad = []
     for s in secs:     for s in secs:
-        s=s.strip() +        s = s.strip() 
-        if not s:continue +        if not s: 
-        tm=re.search(r'---> (.+?)(?:\n|$)',s) +            continue 
-        t=tm.group(1).strip() if tm else "" +        tm = re.search(r'---> (.+?)(?:\n|$)', s) 
-        tb=parse_fw(s) +        t = tm.group(1).strip() if tm else "" 
-        if tb and len(tb)>1: +        tb = parse_fw(s) 
-            for i,r in enumerate(tb):r.insert(0,"Section" if i==0 else t)+        if tb and len(tb) > 1: 
 +            for i, r in enumerate(tb): 
 +                r.insert(0, "Section" if i == 0 else t)
             ad.extend(tb if not ad else tb[1:])             ad.extend(tb if not ad else tb[1:])
     return ad if ad else None     return ad if ad else None
  
 def detect(c): def detect(c):
-    c=remove_hdr(c) +    c = remove_hdr(c) 
-    if not c.strip():return None +    if not c.strip(): 
-    if '***' in c and '--->' in c:return parse_sys(c) +        return None 
-    ls=c.split('\n')+    if '***' in c and '--->' in c: 
 +        return parse_sys(c) 
 +    ls = c.split('\n')
     for l in ls[:20]:     for l in ls[:20]:
-        if re.match(r'^[\s-]+$',l) and l.count('-')>10:return parse_fw(c) +        if re.match(r'^[\s-]+$', l) and l.count('-') > 10: 
-    cc=sum(1 for l in ls[:10] if ',' in l) +            return parse_fw(c) 
-    if cc>3:return parse_csv(c)+    cc = sum(1 for l in ls[:10] if ',' in l) 
 +    if cc > 3: 
 +        return parse_csv(c)
     return [[convert_value(l.strip())] for l in ls if l.strip()]     return [[convert_value(l.strip())] for l in ls if l.strip()]
  
 def sn(fn): def sn(fn):
-    n=Path(fn).stem +    n = Path(fn).stem 
-    if '_' in n:p=n.split('_',1);n=p[1] if len(p)>1 and p[1] else n +    if '_' in n: 
-    for c in ['\\','/','*','?',':','[',']']:n=n.replace(c,'_')+        p = n.split('_', 1) 
 +        n = p[1] if len(p) > 1 and p[1] else n 
 +    for c in ['\\', '/', '*', '?', ':', '[', ']']: 
 +        n = n.replace(c, '_')
     return n[:31]     return n[:31]
  
-sd=Path(sys.argv[1]);of=sd/sys.argv[2];fs=sorted(sd.glob('*.out')) +sd = Path(sys.argv[1]) 
-if not fs:print("HIBA");sys.exit(1)+of = sd / sys.argv[2] 
 +fs = sorted(sd.glob('*.out')) 
 +if not fs: 
 +    print("HIBA") 
 +    sys.exit(1)
 print(f"Talaltam {len(fs)} .out fajlt") print(f"Talaltam {len(fs)} .out fajlt")
-wb=Workbook();wb.remove(wb.active) + 
-hf=PatternFill(start_color='4472C4',end_color='4472C4',fill_type='solid'+wb = Workbook() 
-hfn=Font(bold=True,color='FFFFFF'+wb.remove(wb.active) 
-bd=Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),bottom=Side(style='thin')) +hf = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid'
-un={}+hfn = Font(bold=True, color='FFFFFF'
 +bd = Border(left=Side(style='thin'), right=Side(style='thin'),  
 +            top=Side(style='thin'), bottom=Side(style='thin')) 
 +un = {} 
 for f in fs: for f in fs:
     print(f"  Feldolgozas: {f.name}")     print(f"  Feldolgozas: {f.name}")
-    try:ct=open(f,'r',encoding='utf-8',errors='replace').read() +    try: 
-    except Exception as e:print(f"    HIBA: {e}");continue +        ct = open(f, 'r', encoding='utf-8', errors='replace').read() 
-    dt=detect(ct) +    except Exception as e: 
-    if not dt:dt=[[l] for l in ct.split('\n') if l.strip()][:100] +        print(f"    HIBA: {e}") 
-    if not dt:continue +        continue 
-    bs=sn(f.name);nm=bs;cn=1 +     
-    while nm in un:nm=f"{bs[:28]}_{cn}";cn+=1 +    dt = detect(ct) 
-    un[nm]=True +    if not dt: 
-    ws=wb.create_sheet(title=nm) +        dt = [[l] for l in ct.split('\n') if l.strip()][:100] 
-    for ri,rw in enumerate(dt,1): +    if not dt: 
-        for ci,cl in enumerate(rw,1): +        continue 
-            ws.cell(ri,ci,value=cl) +     
-            if ri==1:ws.cell(ri,ci).font=hfn;ws.cell(ri,ci).fill=hf;ws.cell(ri,ci).alignment=Alignment(wrap_text=True) +    bs = sn(f.name) 
-            ws.cell(ri,ci).border=bd +    nm = bs 
-    for ci in range(1,ws.max_column+1): +    cn = 1 
-        mx=max((len(str(c.value or '')) for c in ws[get_column_letter(ci)]),default=10) +    while nm in un: 
-        ws.column_dimensions[get_column_letter(ci)].width=min(mx+2,50) +        nm = f"{bs[:28]}_{cn}" 
-    if len(dt)>1:ws.auto_filter.ref=ws.dimensions +        cn += 1 
-    ws.freeze_panes='A2'+    un[nm] = True 
 +     
 +    ws = wb.create_sheet(title=nm) 
 +    for ri, rw in enumerate(dt, 1): 
 +        for ci, cl in enumerate(rw, 1): 
 +            ws.cell(ri, ci, value=cl) 
 +            if ri == 1: 
 +                ws.cell(ri, ci).font = hfn 
 +                ws.cell(ri, ci).fill = hf 
 +                ws.cell(ri, ci).alignment = Alignment(wrap_text=True) 
 +            ws.cell(ri, ci).border = bd 
 +     
 +    for ci in range(1, ws.max_column + 1): 
 +        mx = max((len(str(c.value or '')) for c in ws[get_column_letter(ci)]), default=10) 
 +        ws.column_dimensions[get_column_letter(ci)].width = min(mx + 2, 50) 
 +     
 +    if len(dt) > 1: 
 +        ws.auto_filter.ref = ws.dimensions 
 +    ws.freeze_panes = 'A2' 
 wb.save(of) wb.save(of)
 print(f"\nKesz! {of}") print(f"\nKesz! {of}")
 print(f"Osszesen {len(wb.sheetnames)} munkalap") print(f"Osszesen {len(wb.sheetnames)} munkalap")
 PYEOF PYEOF
 +
 +</file></WRAP>