dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # -*- coding:UTF-8 -*- |
| 3 | |
| 4 | # ===================================================================== |
| 5 | # @module: Get all blx commits and save to csv file |
| 6 | # @author: Li Dongqing (dongqing.li@amlogic.com) |
| 7 | # @License: Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| 8 | # @Changes: |
| 9 | # 1. 2022.07.20 v0.1 create for stable branch update. |
| 10 | # ===================================================================== |
| 11 | |
dongqing.li | 23bd26f | 2022-12-05 20:30:43 +0800 | [diff] [blame] | 12 | # Import modules |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 13 | try: |
| 14 | import sys |
| 15 | import os |
| 16 | import re |
| 17 | import json |
| 18 | import time |
| 19 | import argparse |
| 20 | import subprocess |
| 21 | import IPython |
| 22 | import openpyxl |
| 23 | from git.repo import Repo |
| 24 | from openpyxl.styles import Font, Alignment |
| 25 | from collections import OrderedDict |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 26 | import ast |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 27 | except Exception as e: |
| 28 | print(e) |
dongqing.li | 23bd26f | 2022-12-05 20:30:43 +0800 | [diff] [blame] | 29 | exit('Please install modules, eg: pip3 install os') |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 30 | |
| 31 | # jason example: bl3.4.5-20220711-pre-ver.json |
| 32 | # { |
| 33 | # "source_gits" : [ |
| 34 | # {"blType" : "bl2_sc2", "gitPath" : "bl2/core_sc2", "lastCommit" : "feebe5301418c038a06d45d0216c780ae9ea0033"}, |
| 35 | # {"blType" : "bl2_s4", "gitPath" : "bl2/core_s4", "lastCommit" : "817779a738e99b81081a31035ed784840cace44c"}, |
| 36 | # {"blType" : "bl2_ree", "gitPath" : "bl2/ree", "lastCommit" : "09d5c246638e95e2598a264b36da7f6ede7f6ea8"}, |
| 37 | # {"blType" : "bl2_tee", "gitPath" : "bl2/tee", "lastCommit" : "115e9fc38721c3564435f582875fc02908787b53"}, |
| 38 | # {"blType" : "bl30_aocpu", "gitPath" : "bl30/src_ao", "lastCommit" : "8c0b17692bd51f9c3311f8c51cd28bdf808a27a3"}, |
| 39 | # {"blType" : "bl31_1.3", "gitPath" : "bl31_1.3/src", "lastCommit" : "cf6108ce548d7ad3bfe268dedf801358664b6ead"}, |
| 40 | # {"blType" : "bl32_3.8", "gitPath" : "bl32_3.8/src", "lastCommit" : "c5ef42f2ce59304e2a4df7cf2dcbb12ab7ccefd1"}, |
| 41 | # {"blType" : "bl33", "gitPath" : "bl33/v2019", "lastCommit" : "f03ed9bc121114e9f31f1ee924d3adc176f13faa"}, |
| 42 | # {"blType" : "fip", "gitPath" : "fip", "lastCommit" : "d60ea7c9adfe8e537d0a11d2c2ce8e8097de5035"} |
| 43 | # ] |
| 44 | # } |
| 45 | |
| 46 | # bootloader trunk branch and remote info |
| 47 | pdPrefix = "https://jira.amlogic.com/browse/" |
| 48 | scgitPrefix = "https://scgit.amlogic.com/plugins/gitiles/" |
| 49 | blSrcGits = [ |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 50 | {"blType" : "bl2_sc2", "gitBranch" : "projects/sc2", "stbBranch" : "projects/openlinux/bl-sc2-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/core/+/"}, |
| 51 | {"blType" : "bl2_s4", "gitBranch" : "projects/s4", "stbBranch" : "projects/openlinux/bl-s4-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/core/+/"}, |
| 52 | {"blType" : "bl2_s5", "gitBranch" : "projects/s5", "stbBranch" : "projects/openlinux/bl-s5-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/core/+/"}, |
| 53 | {"blType" : "bl2_t7", "gitBranch" : "projects/t7", "stbBranch" : "projects/openlinux/bl-s7-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/core/+/"}, |
| 54 | {"blType" : "bl2_s7", "gitBranch" : "projects/s7", "stbBranch" : "projects/openlinux/bl-s7d-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/core/+/"}, |
| 55 | {"blType" : "bl2_s7d", "gitBranch" : "projects/s7d", "stbBranch" : "projects/openlinux/bl-t7-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/core/+/"}, |
| 56 | {"blType" : "ddr", "gitBranch" : "amlogic-ddr-core", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "firmware", "upStream" : "bl2/src/ddr/+/"}, |
| 57 | {"blType" : "bl2_ree", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/ree/+/"}, |
| 58 | {"blType" : "bl2_tee", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "firmware", "upStream" : "bootloader/amlogic-advanced-bootloader/tee/+/"}, |
| 59 | {"blType" : "bl30_aocpu", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "firmware", "upStream" : "firmware/aocpu/+/"}, |
| 60 | {"blType" : "rtos_arch", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/arch/riscv/+/"}, |
| 61 | {"blType" : "rtosboards", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/boards/riscv/+/"}, |
| 62 | {"blType" : "rtos_build", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/build/+/"}, |
| 63 | {"blType" : "rtos_driver_aocpu", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/drivers_aocpu/+/"}, |
| 64 | {"blType" : "rtos_freertos", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/freertos/+/"}, |
| 65 | {"blType" : "rtos_libc", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/libc/+/"}, |
| 66 | {"blType" : "rtos_products_aocpu", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/product/aocpu/+/"}, |
| 67 | {"blType" : "rtos_scripts", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/scripts/+/"}, |
| 68 | {"blType" : "rtos_soc", "gitBranch" : "projects/amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "origin", "upStream" : "rtos_sdk/soc/riscv/+/"}, |
| 69 | {"blType" : "bl31_1.3", "gitBranch" : "amlogic-dev-1.3", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "firmware", "upStream" : "ARM-software/arm-trusted-firmware/+/"}, |
| 70 | {"blType" : "bl31_2.7", "gitBranch" : "amlogic-dev-2.7", "stbBranch" : "projects/openlinux/bl-3.5.0-2.7", "gitRemote" : "firmware", "upStream" : "ARM-software/arm-trusted-firmware/+/"}, |
| 71 | {"blType" : "bl32_3.8", "gitBranch" : "amlogic-dev-3.8.0", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "firmware", "upStream" : "OP-TEE/optee_os/+/"}, |
| 72 | {"blType" : "bl32_3.18", "gitBranch" : "amlogic-dev-3.18.0", "stbBranch" : "projects/openlinux/bl-3.5.0-3.18", "gitRemote" : "firmware", "upStream" : "OP-TEE/optee_os/+/"}, |
| 73 | {"blType" : "bl33_v2019", "gitBranch" : "amlogic-dev-2019", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "uboot", "upStream" : "uboot/+/"}, |
| 74 | {"blType" : "bl33_v2023", "gitBranch" : "amlogic-dev-2023", "stbBranch" : "projects/openlinux/bl-3.5.0-2023", "gitRemote" : "uboot", "upStream" : "uboot/+/"}, |
| 75 | {"blType" : "fip", "gitBranch" : "amlogic-dev", "stbBranch" : "projects/openlinux/bl-3.5.0", "gitRemote" : "fip", "upStream" : "amlogic/tools/fip/+/"} |
| 76 | ] |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 77 | |
wenbo.wang | 79145cc | 2023-03-01 10:41:59 +0800 | [diff] [blame] | 78 | # the local csv file columns |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 79 | csv_file_column = [ |
| 80 | {"ID" : "A", "WIDTH" : 12, "NAME" : "Index"}, |
| 81 | {"ID" : "B", "WIDTH" : 45, "NAME" : "Trunk Commit"}, |
| 82 | {"ID" : "C", "WIDTH" : 30, "NAME" : "Trunk Cl Link"}, |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 83 | {"ID" : "D", "WIDTH" : 20, "NAME" : "Stb Merged?"}, |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 84 | {"ID" : "D", "WIDTH" : 20, "NAME" : "Is Force Patch?"}, |
| 85 | {"ID" : "E", "WIDTH" : 20, "NAME" : "Is Secure Patch?"}, |
| 86 | {"ID" : "F", "WIDTH" : 20, "NAME" : "Reviewer"}, |
| 87 | {"ID" : "G", "WIDTH" : 16, "NAME" : "Related to other CL ?"}, |
| 88 | {"ID" : "H", "WIDTH" : 20, "NAME" : "QA Test Cases"}, |
| 89 | {"ID" : "I", "WIDTH" : 16, "NAME" : "QA Verify Result"}, |
| 90 | {"ID" : "J", "WIDTH" : 20, "NAME" : "New CL"} |
| 91 | ] |
| 92 | |
| 93 | # git update branch |
| 94 | def git_src_update(gitPath, gitRemote, gitBranch): |
| 95 | local_path = os.path.join(gitPath) |
| 96 | repo = Repo(local_path) |
| 97 | |
| 98 | try: |
| 99 | repo.git.branch('-D', 'test') |
| 100 | except: |
| 101 | pass |
| 102 | |
| 103 | try: |
| 104 | repo.git.checkout('-b', 'test') |
| 105 | except: |
| 106 | try: |
| 107 | repo.git.checkout('test') |
| 108 | except: |
| 109 | pass |
| 110 | pass |
| 111 | |
| 112 | try: |
| 113 | repo.git.branch('-D', gitBranch) |
| 114 | except: |
| 115 | pass |
| 116 | |
| 117 | try: |
| 118 | #repo.git.clean('-d', '-fx') |
| 119 | repo.git.checkout('-t', 'remotes/' + gitRemote + '/' + gitBranch) |
| 120 | except: |
| 121 | try: |
| 122 | repo.git.checkout(gitBranch) |
| 123 | except: |
| 124 | exit('Error: check out branch (%s / %s) failed!'%(gitRemote,gitBranch)) |
| 125 | pass |
| 126 | |
| 127 | try: |
| 128 | repo.git.branch('-D', 'test') |
| 129 | except: |
| 130 | pass |
| 131 | |
| 132 | try: |
| 133 | repo.git.fetch('--all') |
| 134 | except: |
| 135 | pass |
| 136 | |
| 137 | try: |
| 138 | repo.git.reset('--hard', gitRemote + '/' + gitBranch) |
| 139 | except: |
| 140 | exit('Error: git reset branch (%s / %s) failed!'%(gitRemote,gitBranch)) |
| 141 | |
| 142 | try: |
| 143 | #repo.git.pull(gitRemote, gitBranch) |
| 144 | repo.git.pull() |
| 145 | except: |
| 146 | exit('Error: git pull branch (%s) failed!'%gitBranch) |
| 147 | |
| 148 | # git update branch |
| 149 | def get_bltype_branch_id(bltype, list): |
| 150 | for i in range(len(list)): |
| 151 | stream_dic = {"blType":None, "gitBranch":None, "gitRemote":None, "upStream":None} |
| 152 | stream_dic = list[i] |
| 153 | |
| 154 | if str(bltype) == str(stream_dic['blType']): |
| 155 | print(' > Match the local bltype ID = ', i+1) |
| 156 | return i |
| 157 | |
| 158 | else: |
| 159 | return -1 |
| 160 | |
| 161 | # Prase json array to get commits info |
| 162 | def git_commits_to_src_link(): |
| 163 | print('\n[TRUNK LIST]:') |
| 164 | |
| 165 | # prase each repo |
| 166 | for i in range(len(trunk_list)): |
| 167 | print(' > [%d] gitPath: %-12s lastCommit: %s'%(i+1, trunk_list[i]['gitPath'], trunk_list[i]['lastCommit'])) |
| 168 | |
dongqing.li | a8d42d0 | 2023-02-22 17:04:33 +0800 | [diff] [blame] | 169 | if len(trunk_list[i]['lastCommit']) == 0: |
| 170 | print(' > lastCommit is NULL !') |
| 171 | continue |
| 172 | |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 173 | try: |
| 174 | os.chdir(topdir + trunk_list[i]['gitPath']) |
| 175 | except: |
| 176 | exit('Error: NO such git path:', trunk_list[i]['gitPath']) |
| 177 | |
| 178 | # compare trunk list and local blSrcGits, find match id |
| 179 | index = get_bltype_branch_id(trunk_list[i]['blType'], blSrcGits) |
| 180 | if index < 0: |
| 181 | exit("Error: NO found match blType:", trunk_list[i]['blType']) |
| 182 | |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 183 | # update stable branch |
| 184 | git_src_update(os.getcwd(), blSrcGits[index]['gitRemote'], blSrcGits[index]['stbBranch']) |
| 185 | changedId_list = get_stb_changeId(os.getcwd(), 200) |
| 186 | |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 187 | # update target branch |
| 188 | git_src_update(os.getcwd(), blSrcGits[index]['gitRemote'], blSrcGits[index]['gitBranch']) |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 189 | # run git log format and produce commit list |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 190 | commit_list = git_cmt_parse(os.getcwd(), trunk_list[i]['lastCommit'], 'HEAD', changedId_list) |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 191 | |
| 192 | git_cmt_2_csv(csvfile, trunk_list[i]['blType'], commit_list, blSrcGits[index], i) |
| 193 | |
| 194 | # Open json file, prase last commit |
| 195 | def prase_json_file(): |
| 196 | global trunk_list |
| 197 | |
| 198 | with open(jsonfile,'r') as load_f: |
| 199 | try: |
| 200 | json_array = json.load(load_f, object_pairs_hook=OrderedDict) |
| 201 | except: |
| 202 | exit('Error: Incorrect json format!') |
| 203 | |
| 204 | trunk_list = [] |
| 205 | for item in json_array['source_gits']: |
| 206 | try: |
| 207 | store_details = {"blType":None, "gitPath":None, "lastCommit":None} |
| 208 | store_details['blType'] = item['blType'] |
| 209 | store_details['gitPath'] = item['gitPath'] |
| 210 | store_details['lastCommit'] = item['lastCommit'] |
| 211 | trunk_list.append(store_details) |
| 212 | except: |
| 213 | exit('Error: get trunk last commit failed.\n') |
| 214 | |
| 215 | return trunk_list |
| 216 | |
| 217 | # output instance of str |
| 218 | def to_str(bytes_or_str): |
| 219 | if isinstance(bytes_or_str, bytes): |
| 220 | value = bytes_or_str.decode('utf-8') |
| 221 | |
| 222 | else: |
| 223 | value = bytes_or_str |
| 224 | |
| 225 | return value |
| 226 | |
| 227 | # run shell cmd return bytes |
| 228 | def bash_command(cmd): |
| 229 | process = subprocess.Popen(cmd, |
| 230 | shell=True, |
| 231 | stdout=subprocess.PIPE, |
| 232 | stderr=subprocess.PIPE) |
| 233 | |
| 234 | #stdout, stderr = process.communicate() |
| 235 | |
| 236 | return process.stdout.read() |
| 237 | |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 238 | # get stable branch changed-id list |
| 239 | def get_stb_changeId(gitPath, clNum): |
| 240 | local_path = os.path.join(gitPath) |
| 241 | |
| 242 | repo = Repo(local_path) |
| 243 | commit_log = repo.git.log('--pretty={"commit":"%h"}', max_count=clNum) |
| 244 | try: |
| 245 | log_list = commit_log.split("\n") |
| 246 | #if debug_enable: |
| 247 | # print(' > %s'%(log_list)) |
| 248 | except: |
| 249 | pass |
| 250 | |
| 251 | real_log_list = [eval(str(item)) for item in log_list] |
| 252 | changedId_list = [None] * clNum |
| 253 | |
| 254 | for i in range(len(real_log_list)): |
| 255 | try: |
| 256 | cmd = 'git log ' + real_log_list[i]['commit'] + ' -1 | grep Change-Id: | head -n 1' |
| 257 | res = to_str(bash_command(cmd)).replace('\n', '') |
| 258 | if res: |
| 259 | changedId_list[i] = res.split("Change-Id:")[1] |
| 260 | |
| 261 | else: |
| 262 | changedId_list[i] = 'NULL' |
| 263 | if debug_enable: |
| 264 | print(' > [%d] overwrite Change-Id: = %s'%(i,changedId_list[i] )) |
| 265 | except: |
| 266 | pass |
| 267 | #print("changedId_list: ",changedId_list[0]) |
| 268 | return changedId_list |
| 269 | |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 270 | # get commit list info |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 271 | def git_cmt_parse(gitPath, lastCommit, headCommit, changedId_list): |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 272 | local_path = os.path.join(gitPath) |
| 273 | |
| 274 | repo = Repo(local_path) |
| 275 | |
| 276 | # run git log --format |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 277 | commit_log = repo.git.log('--pretty={"summary":"%s","commit":"%h","hash":"%H","author":"%ae","date":"%cd","Change-Id":"null","meged":"null"}', |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 278 | '--reverse', lastCommit + '...' + headCommit) |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 279 | try: |
| 280 | log_list = commit_log.split("\n") |
| 281 | #if debug_enable: |
| 282 | # print(' > %s'%(log_list)) |
| 283 | except: |
| 284 | pass |
wenbo.wang | 79145cc | 2023-03-01 10:41:59 +0800 | [diff] [blame] | 285 | #Remove invalid commits |
| 286 | autosubmit = [] |
| 287 | log_list_len = len(log_list) |
| 288 | for i in range(log_list_len): |
| 289 | if "gerrit.autosubmit@amlogic.com" in log_list[i]: |
| 290 | autosubmit.append(i) |
| 291 | log_list = [log_list[i] for i in range(log_list_len) if (i not in autosubmit)] |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 292 | |
wenbo.wang | 79145cc | 2023-03-01 10:41:59 +0800 | [diff] [blame] | 293 | # deal with "Merge into" or "revert" commits |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 294 | for i in range(len(log_list)): |
| 295 | try: |
| 296 | log_list[i] = str(re.sub(r'Merge "', r'Merge <', str(log_list[i]))) |
| 297 | log_list[i] = str(re.sub(r'" into', r'> into', str(log_list[i]))) |
| 298 | log_list[i] = str(re.sub(r'Revert "', r'Revert <', str(log_list[i]))) |
| 299 | log_list[i] = str(re.sub(r'"",', r'>",', str(log_list[i]))) |
wenbo.wang | cf2190c | 2024-06-19 17:08:30 +0800 | [diff] [blame] | 300 | log_list[i] = str(re.sub(r' "', r' "', str(log_list[i]))) |
| 301 | log_list[i] = str(re.sub(r'" ', r'" ', str(log_list[i]))) |
wenbo.wang | 8e5c8f7 | 2023-08-31 13:01:54 +0800 | [diff] [blame] | 302 | log_list[i] = str(re.sub(r' `', r' ', str(log_list[i]))) |
| 303 | log_list[i] = str(re.sub(r'&', r' ', str(log_list[i]))) |
| 304 | log_list[i] = str(re.sub(r'loc\'', r'loc', str(log_list[i]))) |
| 305 | log_list[i] = str(re.sub(r'">"', r'>"', str(log_list[i]))) |
| 306 | log_list[i] = str(re.sub(r'">', r' >', str(log_list[i]))) |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 307 | log_list[i] = str(re.sub(r'("colorattribute")', r"'colorattribute'", str(log_list[i]))) |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 308 | |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 309 | except: |
| 310 | pass |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 311 | #print(' > [%d] %s'%(i,log_list[i])) |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 312 | # eval special special characters |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 313 | real_log_list=[] |
| 314 | for index, item in enumerate(log_list): |
| 315 | try: |
| 316 | real_log_list.append(eval(str(item))) |
| 317 | except(ValueError, SyntaxError) as e: |
| 318 | real_log_list = [] |
dongqing.li | a8d42d0 | 2023-02-22 17:04:33 +0800 | [diff] [blame] | 319 | print(' > eval(str(item)) ERROR!') |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 320 | print(' > %s'%(item)) |
| 321 | #print(f" > Error details: {e}") |
| 322 | pass |
| 323 | # update real_log_list[i]['Change-Id'] with JiraNo |
| 324 | |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 325 | for j in range(len(real_log_list)): |
| 326 | try: |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 327 | cmd = 'git log ' + real_log_list[j]['commit'] + ' -1 | grep Change-Id: | head -n 1' |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 328 | res = to_str(bash_command(cmd)).replace('\n', '') |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 329 | if res: |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 330 | real_log_list[j]['Change-Id'] = res.split("Change-Id:")[1] |
| 331 | if real_log_list[j]['Change-Id'] in changedId_list : |
| 332 | real_log_list[j]['meged'] = '1' |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 333 | else: |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 334 | real_log_list[j]['Change-Id'] = 'NULL' |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 335 | if debug_enable: |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 336 | print(' > [%d] overwrite Change-Id: = %s'%(j,real_log_list[j]['Change-Id'])) |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 337 | except: |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 338 | print("Change-Id get bypass") |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 339 | pass |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 340 | try: |
| 341 | print(' > Commit list max number of rows = ', len(real_log_list)) |
| 342 | except: |
| 343 | pass |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 344 | return real_log_list |
| 345 | |
| 346 | # save commit info to csv |
| 347 | def git_cmt_2_csv(csvfile, blType, commit_list, stream_dic, sheet_index): |
| 348 | global alignment |
| 349 | |
| 350 | # Load a workbook object |
| 351 | wb = openpyxl.load_workbook(csvfile) |
| 352 | |
| 353 | # Creat csv sheet named by blType |
| 354 | title = re.sub(r'[?|$|.|!|/|*]', r'_', blType) |
| 355 | sheet = wb.create_sheet(title, sheet_index) |
| 356 | |
| 357 | sheet.title = title |
| 358 | |
| 359 | # Set active sheet |
| 360 | wb.active = sheet_index |
| 361 | |
| 362 | try: |
| 363 | # Set aligment |
| 364 | alignment = Alignment(horizontal="left", vertical="center", wrap_text=True) |
| 365 | |
| 366 | for i in range(len(commit_list) + 1): |
| 367 | |
| 368 | for j in range(len(csv_file_column)): |
| 369 | sheet.cell(row = i + 1, column = j + 1).alignment = alignment |
| 370 | except: |
| 371 | pass |
| 372 | |
| 373 | # set cell(1,1): value and font |
| 374 | font = Font(size=11, bold=True) |
| 375 | sheet.cell(row = 1, column = 1).value = blType + " " + csv_file_column[0]['NAME'] |
| 376 | sheet.cell(row = 1, column = 1).font = font |
| 377 | |
| 378 | # set row 1: value and font |
| 379 | for i in range(1, len(csv_file_column)): |
| 380 | sheet.cell(row = 1, column = i + 1).value = csv_file_column[i]['NAME'] |
| 381 | sheet.cell(row = 1, column = i + 1).font = font |
| 382 | |
| 383 | # set row 1: height |
| 384 | # sheet.row_dimensions[1].height = 30 |
| 385 | |
| 386 | # set row 2-n: trunk commit |
| 387 | for i in range(len(commit_list)): |
| 388 | try: |
| 389 | # column 1: ID index |
| 390 | sheet.cell(row = i + 2, column = 1).value = i + 1 |
| 391 | |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 392 | sheet.cell(row = i + 2, column = 2).value = \ |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 393 | commit_list[i]['summary'] + '\n'\ |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 394 | 'Commit: ' + commit_list[i]['commit'] + '\n'\ |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 395 | 'Change-Id: ' + commit_list[i]['Change-Id'] + '\n'\ |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 396 | 'Author: ' + commit_list[i]['author'] + '\n'\ |
| 397 | 'Date: ' + commit_list[i]['date'] |
| 398 | |
| 399 | # column 3:Trunk Cl Link |
| 400 | sheet.cell(row = i + 2, column = 3).value = scgitPrefix + \ |
| 401 | stream_dic['upStream'] + \ |
| 402 | commit_list[i]['hash'] |
wenbo.wang | a41dcc0 | 2024-06-04 17:14:33 +0800 | [diff] [blame] | 403 | |
| 404 | sheet.cell(row = i + 2, column = 4).value = commit_list[i]['meged'] |
dongqing.li | 93ffff3 | 2022-07-25 10:38:31 +0800 | [diff] [blame] | 405 | except: |
| 406 | pass |
| 407 | |
| 408 | # set column A-I width |
| 409 | for i in range(len(csv_file_column)): |
| 410 | sheet.column_dimensions[csv_file_column[i]['ID']].width = csv_file_column[i]['WIDTH'] |
| 411 | |
| 412 | # save the file |
| 413 | wb.save(csvfile) |
| 414 | |
| 415 | # Creat csv file to save cmt list |
| 416 | def create_csv_file(outdir, inputfile): |
| 417 | global csvfile |
| 418 | |
| 419 | # get csv file full name |
| 420 | localTime = time.strftime("_%Y%m%d_%H%M%S", time.localtime()) |
| 421 | |
| 422 | base_name=os.path.basename(inputfile) |
| 423 | file_name = os.path.splitext(base_name)[0] |
| 424 | |
| 425 | csvfile = str(topdir) + str(outdir) + "/" + file_name + str(localTime) + ".xlsx" |
| 426 | |
| 427 | # creat csv file, overwrite existing files |
| 428 | wb = openpyxl.Workbook() |
| 429 | |
| 430 | wb.save(csvfile) |
| 431 | |
| 432 | # get argv |
| 433 | def getOptions(args=sys.argv[1:]): |
| 434 | global jsonfile |
| 435 | global debug_enable |
| 436 | |
| 437 | # crate prase progress |
| 438 | parser = argparse.ArgumentParser(description="Get all blx commits and save to csv file.") |
| 439 | |
| 440 | # add argv support |
| 441 | parser.add_argument("-j", "--jsoncfg", required=True, help="Your input json file.") |
| 442 | parser.add_argument("-o", "--outDir", required=True, help="Your output .xlsx dir.") |
| 443 | parser.add_argument("-v", "--verbose", required=False, help="Increase output verbosity.", action="store_true") |
| 444 | parser.add_argument("-p", "--push", required=False, help="Push csv file to confluence.", action="store_true") |
| 445 | |
| 446 | # prase argv |
| 447 | options = parser.parse_args(args) |
| 448 | |
| 449 | # check debug on |
| 450 | if options.verbose: |
| 451 | debug_enable = 1 |
| 452 | else: |
| 453 | debug_enable = 0 |
| 454 | |
| 455 | # check whether the outdir is available |
| 456 | jsonfile = str(options.jsoncfg) |
| 457 | if not os.path.isdir(options.outDir): |
| 458 | exit('Error: No such directory!') |
| 459 | |
| 460 | # creat new csv file |
| 461 | create_csv_file(options.outDir, options.jsoncfg) |
| 462 | print('\n[CONFIG INFO]:') |
| 463 | print(' > Run in toplevel : ', topdir) |
| 464 | print(' > Input json file : ', options.jsoncfg) |
| 465 | print(' > Output xlsx dir : ', options.outDir) |
| 466 | print(' > Output xlsx name: ', csvfile) |
| 467 | |
| 468 | # Get the top-level directory which include .repo |
| 469 | def get_top_dir(): |
| 470 | global topdir |
| 471 | |
| 472 | pwd = os.getcwd() |
| 473 | dirName = 'fip' |
| 474 | |
| 475 | if not os.path.exists(dirName): |
| 476 | topdir = pwd + "/../" |
| 477 | else: |
| 478 | topdir = pwd + "/" |
| 479 | |
| 480 | return topdir |
| 481 | |
| 482 | # Record summary info, and save to scv file |
| 483 | def record_in_summary_sheet(): |
| 484 | wb = openpyxl.load_workbook(csvfile) |
| 485 | |
| 486 | default_ws = 'Sheet' |
| 487 | # active |
| 488 | for s in range(len(wb.sheetnames)): |
| 489 | if wb.sheetnames[s] == default_ws: |
| 490 | break |
| 491 | |
| 492 | try: |
| 493 | wb.active = s |
| 494 | sheet = wb[default_ws] |
| 495 | sheet.title = 'summary' |
| 496 | except: |
| 497 | exit('Error: NOT found sheet: %s'%default_ws) |
| 498 | |
| 499 | # set column width |
| 500 | try: |
| 501 | sheet.column_dimensions['A'].width = 10 |
| 502 | sheet.column_dimensions['B'].width = 20 |
| 503 | sheet.column_dimensions['C'].width = 15 |
| 504 | except: |
| 505 | pass |
| 506 | |
| 507 | # row 1: summary head |
| 508 | sheet.cell(row = 1, column = 1).value = 'ID' |
| 509 | sheet.cell(row = 1, column = 2).value = 'title' |
| 510 | sheet.cell(row = 1, column = 3).value = 'max_row' |
| 511 | |
| 512 | # row n: summary info |
| 513 | for j in range(0,len(summary_list)): |
| 514 | try: |
| 515 | sheet.cell(row = j+2, column = 1).value = summary_list[j]['ID'] |
| 516 | sheet.cell(row = j+2, column = 2).value = summary_list[j]['title'] |
| 517 | sheet.cell(row = j+2, column = 3).value = summary_list[j]['max_row'] |
| 518 | |
| 519 | if debug_enable: |
| 520 | print('[%d] id:%d, title:%s, title:%2d'%(j+1, |
| 521 | summary_list[j]['ID'], |
| 522 | summary_list[j]['title'], |
| 523 | summary_list[j]['max_row'])) |
| 524 | except: |
| 525 | pass |
| 526 | |
| 527 | # Set aligment |
| 528 | for i in range(0, len(summary_list) + 1): |
| 529 | |
| 530 | for j in range(0, 3): |
| 531 | try: |
| 532 | sheet.cell(row = i + 1, column = j + 1).alignment = alignment |
| 533 | except: |
| 534 | pass |
| 535 | |
| 536 | wb.save(csvfile) |
| 537 | return |
| 538 | |
| 539 | # Printf scv file , such as max list num |
| 540 | def summary_for_scv_sheets(): |
| 541 | global summary_list |
| 542 | |
| 543 | wb = openpyxl.load_workbook(csvfile) |
| 544 | |
| 545 | summary_list = [] |
| 546 | |
| 547 | print('\n[SUMMARY SHEETS]:') |
| 548 | print('=========================================') |
| 549 | |
| 550 | for i in range(0, len(wb.sheetnames)-1): |
| 551 | try: |
| 552 | sheet = wb[wb.sheetnames[i]] |
| 553 | print('[%d] Sheet: %-12s Max_Row: %2d'%(i+1, sheet.title, sheet.max_row-1)) |
| 554 | summary_details = {"ID":0, "title":None, "max_row":0} |
| 555 | summary_details['ID'] = i+1 |
| 556 | summary_details['title'] = sheet.title |
| 557 | summary_details['max_row'] = sheet.max_row-1 |
| 558 | summary_list.append(summary_details) |
| 559 | except: |
| 560 | pass |
| 561 | |
| 562 | print('=========================================\n') |
| 563 | |
| 564 | #print('summary_list: ', summary_list) |
| 565 | |
| 566 | wb.save(csvfile) |
| 567 | return |
| 568 | |
| 569 | # Main func |
| 570 | if __name__ == "__main__": |
| 571 | # Set stderr with color |
| 572 | from IPython.core.ultratb import ColorTB |
| 573 | sys.excepthook = ColorTB() |
| 574 | |
| 575 | # get repo top dir |
| 576 | get_top_dir() |
| 577 | |
| 578 | # Prase argv in / out |
| 579 | getOptions(sys.argv[1:]) |
| 580 | |
| 581 | # Prase json file to get last commit |
| 582 | prase_json_file() |
| 583 | |
| 584 | # Get commits list and src link |
| 585 | git_commits_to_src_link() |
| 586 | |
| 587 | # Output csv summary |
| 588 | summary_for_scv_sheets() |
| 589 | |
| 590 | # Record in summary sheet |
| 591 | record_in_summary_sheet() |
| 592 | |
| 593 | print('OUTPUT csv: ', os.path.basename(csvfile)) |
| 594 | exit('RUN OK !') |
| 595 | |