1
import commands
import tempfile

cluster = commands.getoutput('lsid | grep "My cluster name" |awk \'{print $5}\'')
path = '/nxdi_env/lsf/conf/lsbatch/' + cluster + '/configdir/lsb.users'
bl = commands.getoutput('sed -n \'/# BL Fairshare group/,/(it_normal it_priority)/p\' %s | grep -v ^# | sed \'/^$/d\'' %path)
grp = ''
group = ''
txt = ''
normal_detail = ''
priority_detail = ''
subgrp_detail = ''

def print_group(g,sub):
    global normal_detail
    global priority_detail
    subgrp = (group + '_' + sub).lower()
    subgrp1 = subgrp + ','
    if sub == 'normal':
       subgrp_share = txt[txt.find(subgrp1)+len(subgrp1):txt.find("]")]
       subgrp_detail = normal_detail
    else:
       subgrp_share = txt[txt.find(subgrp1)+len(subgrp1):txt.find("])")]
       subgrp_detail = priority_detail
    subgrp_detail = subgrp_detail.strip().split('(all) ')
    subgrp_detail = subgrp_detail[1].replace(' 
    ','').replace('([','').replace('])','').split('][')
    print(' |- %s   \t  %-5s' %(subgrp,subgrp_share))
    for i in subgrp_detail:
       user, slot = i.split(',')
       print(' |       | - %-13s%-5s ' %(user,slot))


with tempfile.NamedTemporaryFile(delete=True) as f:
     f.write(bl)
     f.seek(0)
     for line in f:
         grp = line.split()
         if '_' in grp[0]:
            subgrp = grp[0]
            group = subgrp.split('_')
            group = group[0].upper()
            if 'normal' in grp[0]:
               normal_detail = line
            else:
               priority_detail = line
         else:
            print(group)
            txt = line
            print_group(group, 'normal')
            print_group(group, 'priority')
STerliakov
  • 4,983
  • 3
  • 15
  • 37
Ar8itrator
  • 23
  • 6

0 Answers0