Skip to content

Commit

Permalink
openpyxl を利用して msbuild のログファイルの解析結果を excel ファイルに変換して artifacts に含める
Browse files Browse the repository at this point in the history
  • Loading branch information
m-tmatma committed Jul 8, 2018
1 parent 5da6469 commit bc0e84c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
22 changes: 22 additions & 0 deletions parse-buildlog.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
@echo off

@rem -------------------------------------------------------
@rem install openpyxl module on appveyor
@rem -------------------------------------------------------
if "%APPVEYOR%" == "True" (
call :openpyxl_install
) else (
@echo skip 'pip install openpyxl --user'
)

where python --version 1>nul 2>&1
if not "%ERRORLEVEL%" == "0" (
@echo NOTE: No python command
Expand All @@ -7,3 +17,15 @@ if not "%ERRORLEVEL%" == "0" (
)
@echo on
exit /b %ERRORLEVEL%


:openpyxl_install

where pip 1>nul 2>&1
if not "%ERRORLEVEL%" == "0" (
@echo NOTE: No pip command
) else (
@echo NOTE: found pip command
pip install openpyxl --user
)
exit /b
50 changes: 50 additions & 0 deletions parse-buildlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import os
import csv
import platform

# 解析結果を格納するハッシュのキー
logHashKeys = [
Expand Down Expand Up @@ -107,6 +108,53 @@ def writeToCSV(outfile, data):
writer.writerow(temp)

print ("wrote " + outfile)

# outfile: 出力ファイル名
# data : ログの解析結果が入ったハッシュの配列 ( parse_buildlog() の戻り値 )
def writeToXLSX(outfile, data):
# CELL に設定する値を変換する関数を返す
def getEntryConverter():
def converterPython3(value):
return value.encode('utf_8')

def converterPython2(value):
return value.decode('shiftjis').encode('utf_8')

(major, minor, patchlevel) = platform.python_version_tuple()
if int(major) >= 3:
return converterPython3
else:
return converterPython2

try:
import openpyxl
wb = openpyxl.Workbook()
ws = wb.active

y = 0
for x, item in enumerate(logHashKeys):
cell = ws.cell(row=y+1, column=x+1)
cell.value = item
y = y + 1

converter = getEntryConverter()

for entry in data:
for x, key in enumerate(logHashKeys):
cell = ws.cell(row=y+1, column=x+1)
entryKey = entry[key]
val = converter(entry[key])
if val.isdigit():
cell.value = int(val)
else:
cell.value = val

y = y + 1

wb.save(outfile)
print ("wrote " + outfile)
except ImportError:
print ("please run '<python root>\\Scripts\\pip install openpyxl --user'")

# main 関数
def main():
Expand All @@ -116,9 +164,11 @@ def main():

infile = sys.argv[1]
outcsvfile = infile + '.csv'
outxlsxfile = infile + '.xlsx'

data = parse_buildlog(infile)
writeToCSV(outcsvfile, data)
writeToXLSX(outxlsxfile, data)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions zipArtifacts.bat
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ if "%ALPHA%" == "1" (
copy installer\Output\*.exe %WORKDIR_INST%\
copy msbuild-%platform%-%configuration%.log %WORKDIR_LOG%\
copy msbuild-%platform%-%configuration%.log.csv %WORKDIR_LOG%\
if exist "msbuild-%platform%-%configuration%.log.xlsx" (
copy "msbuild-%platform%-%configuration%.log.xlsx" %WORKDIR_LOG%\
)
copy sakura_core\githash.h %WORKDIR_LOG%\

set HASHFILE=sha256.txt
Expand Down

0 comments on commit bc0e84c

Please sign in to comment.