Skip to content

Instantly share code, notes, and snippets.

@darkblue-b
Last active December 20, 2015 01:29
Show Gist options
  • Save darkblue-b/6049656 to your computer and use it in GitHub Desktop.
Save darkblue-b/6049656 to your computer and use it in GitHub Desktop.
next rev to parse build log
import sys,re
# more hacks
# remove the last two lines from the saved output
# psql
# > create database pkgs1;
# > \c pkgs1
# pkgs1=# create table raw_parse (script_name text, action text, pkg_name text);
# pkgs1=# copy raw_parse from '/home/user/out1.csv' with CSV delimiter E'\t';
# pkgs1=# select pkg_name from raw_parse group by pkg_name having every(action <> 'REMOVE') order by pkg_name;
#
# --
if len(sys.argv) > 1 and sys.argv[1] is not None:
tF = sys.argv[1]
else:
tF = 'chroot-build.log'
try:
tLog = open( tF, 'r+')
except Exception, E:
print str(E)
sys.exit(1)
tScriptBlocksA = []
tPkgs_New = []
tPkgs_Extra = []
tPkgs_Rem = []
tLineBuf = []
tCurBlockName = None
tCnt = 0
bStartBlock = False
bInHdrBlock = False
bInFinishBlk = False
bInPkgsNewBlk = False
bInPkgsExBlk = False
for tLine in tLog.readlines():
tCnt += 1
resM_Hdr = re.search( '^[=]{64}$', tLine )
resM_BlkTitle = re.search( '^Starting \"([\-a-zA-Z0-9_]+)\.sh', tLine )
resM_PkgNew = re.search( '^The following NEW packages will be installed', tLine)
resM_PkgEx = re.search( '^The following extra packages will be installed', tLine)
resM_PkgRemove = re.search( '^Removing ([\-a-zA-Z0-9_]+) ...', tLine)
if resM_PkgRemove is not None and tCurBlockName is not None:
resM_hack = re.search( ' ([\-a-zA-Z0-9_]+) ', tLine)
tRemElem = resM_hack.group(0)
tRemElem = tRemElem[1:-1]
tPkgs_Rem.append( tRemElem )
print '\t'.join( [tCurBlockName,'REMOVE', tRemElem] )
continue
if resM_BlkTitle is not None:
tCurBlockName = tLine[10:-9]
tScriptBlocksA.append( tCurBlockName )
continue
if resM_PkgEx is not None:
##-- chroot starter breaks the pattern.. so check for that too
if tCurBlockName is None:
continue
bInPkgsExBlk = True
#print ' EXTRA'
continue
else:
if tLine[0:2] != ' ':
bInPkgsExBlk = False
#print ' --'
elif bInPkgsExBlk == True and tLine[0:2] == ' ':
tSomePkgs = tLine[2:-1].split(' ')
for n in tSomePkgs:
tPkgs_Extra.append(n)
print '\t'.join( [tCurBlockName,'EXTRA',n] )
if resM_PkgNew is not None:
##-- chroot starter breaks the pattern.. so check for that too
if tCurBlockName is None:
continue
bInPkgsNewBlk = True
#print ' NEW'
continue
else:
if tLine[0:2] != ' ':
bInPkgsNewBlk = False
#print ' --'
elif bInPkgsNewBlk == True and tLine[0:2] == ' ':
tSomePkgs = tLine[2:-1].split(' ')
for n in tSomePkgs:
tPkgs_New.append(n)
print '\t'.join( [tCurBlockName,'NEW',n] )
if resM_Hdr is not None:
if bStartBlock == False and bInFinishBlk == False:
bStartBlock = True
bInHdrBlock = True
continue
elif bStartBlock == True:
if bInHdrBlock == True:
bInHdrBlock = False
continue
elif bInFinishBlk == False:
bInFinishBlk = True
continue
elif bInFinishBlk == True:
bInFinishBlk = False
##-- clean up a block here
tCurBlockName = None
tPkgs_New = []
tPkgs_Extra = []
tPkgs_Rem = []
continue
else:
print tLine
print 'PROBLEM'
if bInFinishBlk == True:
continue
print 'DONE'
print tScriptBlocksA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment