summaryrefslogtreecommitdiffstats
path: root/src/tools/models/buildtool/sbeGitUtility.py
diff options
context:
space:
mode:
authorspashabk-in <shakeebbk@in.ibm.com>2017-02-02 01:10:33 -0600
committerSachin Gupta <sgupta2m@in.ibm.com>2017-02-24 21:10:00 -0500
commit7088a779f43b2b3c1b09be0e5fb8adcfdb805fe5 (patch)
treea73214250816bf891c73883a21a6532c39d6d22a /src/tools/models/buildtool/sbeGitUtility.py
parent36ef073ffc88c8bf2fe179f9f51914c7d8164ee5 (diff)
downloadtalos-sbe-7088a779f43b2b3c1b09be0e5fb8adcfdb805fe5.tar.gz
talos-sbe-7088a779f43b2b3c1b09be0e5fb8adcfdb805fe5.zip
SBE model build tool
Change-Id: I5ed406f7b6adc299f4c8b9242eaa5aef34e3dcb4 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/35775 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Reviewed-by: Sachin Gupta <sgupta2m@in.ibm.com>
Diffstat (limited to 'src/tools/models/buildtool/sbeGitUtility.py')
-rwxr-xr-xsrc/tools/models/buildtool/sbeGitUtility.py220
1 files changed, 220 insertions, 0 deletions
diff --git a/src/tools/models/buildtool/sbeGitUtility.py b/src/tools/models/buildtool/sbeGitUtility.py
new file mode 100755
index 00000000..fba1bb17
--- /dev/null
+++ b/src/tools/models/buildtool/sbeGitUtility.py
@@ -0,0 +1,220 @@
+#!/usr/bin/python
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/tools/models/buildtool/sbeGitUtility.py $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2017
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+###########################################################
+# @file sbeGitUtility.py
+# @brief Git Utilility Module to support building SBE image
+#
+# @author George Keishing
+#
+# @date Nov 23, 2015
+# ----------------------------------------------------
+# @version Developer Date Description
+# ----------------------------------------------------
+# 1.0 gkeishin 11/12/15 Initial create
+###########################################################
+
+#-------------------------
+# Imports
+#-------------------------
+import os
+import sys
+import time
+import shutil
+import os.path
+import subprocess
+from subprocess import Popen, PIPE
+from os.path import expanduser # for getting $HOME PATH
+# Local imports
+import sbeConstants as sbeConstants
+
+##########################################################################
+# Function : utilGitShowCommitFiles
+#
+# @param i_commitId : user supplied command line input commit id
+# @param i_ppe_path : user supplied command line input path
+#
+# @brief Check the files associated with this commit id
+#
+##########################################################################
+def utilGitShowCommitFiles(i_commitId, i_ppe_path):
+
+ if i_commitId == "None":
+ return sbeConstants.SUCCESS_EXIT
+
+ if i_ppe_path == "None":
+ l_home_ppe_path = expanduser("~") + "/" +sbeConstants.GIT_PPE_REPO_SB
+ else:
+ l_home_ppe_path = i_ppe_path + "/" +sbeConstants.GIT_PPE_REPO_SB
+
+ os.chdir(l_home_ppe_path)
+ print " --> ", l_home_ppe_path
+
+ # Quickly check if this commit id is valid or not
+ is_valid = "git cat-file -t " + i_commitId
+ p_valid = subprocess.Popen(is_valid, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
+ for line in p_valid.stdout:
+ line = line.strip()
+ if line == "commit":
+ print " * This Commit Validated "
+ else:
+ #There is an error - command has exited with non-zero code
+ return sbeConstants.ERROR_GIT_CHANGEID_FAILED
+
+ # Git command to list only the files associatede with this commit
+ l_gitCmd='git show --pretty="format:" --name-only ' + i_commitId
+ print " Executing : ", l_gitCmd
+
+ p_out = subprocess.Popen(l_gitCmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
+ for line in p_out.stdout:
+ line = line.strip()
+ print " " ,line
+
+ return sbeConstants.SUCCESS_EXIT
+
+##########################################################################
+# Function : utilGitShowCommitFiles
+#
+# @param i_commitId : user supplied command line input commit id
+# @param i_ppe_path : user supplied command line input path
+#
+# @brief Check the files associated with this commit id
+#
+##########################################################################
+def utilGitCommitCheckout(i_commitId, i_ppe_path):
+
+ if i_commitId == "None":
+ return sbeConstants.SUCCESS_EXIT
+
+ if i_ppe_path == "None":
+ l_home_ppe_path = expanduser("~") + "/" +sbeConstants.GIT_PPE_REPO_SB
+ else:
+ l_home_ppe_path = i_ppe_path + "/" +sbeConstants.GIT_PPE_REPO_SB
+
+ os.chdir(l_home_ppe_path)
+ print " --> ", l_home_ppe_path
+
+ # Git command to list only the files associatede with this commit
+ l_gitCmd='git checkout ' + i_commitId + ' -b test_build'
+ print " Executing : ", l_gitCmd
+ p_out = subprocess.Popen(l_gitCmd, stdout=subprocess.PIPE, shell=True)
+
+ # Allow time to sink in the checkout
+ time.sleep(10)
+
+ l_gitbranch='git branch'
+ p_checkout_out = subprocess.Popen(l_gitbranch, stdout=subprocess.PIPE, shell=True)
+ for line in p_checkout_out.stdout:
+ line = line.strip()
+ print " " ,line
+
+ # Allow time to switch to new branch
+ time.sleep(3)
+
+ return sbeConstants.SUCCESS_EXIT
+
+##########################################################################
+# Function : utilGetChangeID
+#
+# @param i_num : user supplied command line input commit id
+#
+# @brief Get the git log id based on the changed ID
+#
+##########################################################################
+def utilGetChangeID(i_num):
+ print " commit",i_num
+ l_found = False
+ #data = []
+
+ # execute the command
+ l_cmd = 'git log ' + i_num
+
+ p = subprocess.Popen(l_cmd, stdout=subprocess.PIPE, shell=True)
+ #(output, err) = p.communicate()
+
+ while p.poll() is None:
+ line = p.stdout.readline()
+ line = line.strip()
+ if not line: continue
+
+ if i_num in line:
+ #print "Commit id marker found"
+ l_found=True
+ continue
+
+ if 'Change-Id:' in line:
+ if l_found:
+ #print " ", line
+ #data.append(line)
+ break
+
+ # Should n't come out without data
+ if l_found:
+ return line
+ else:
+ return sbeConstants.ERROR_PREP_CHANGE_FAILED
+
+##########################################################################
+# Function : utilGetCommitID
+#
+# @param i_num : user supplied command line input commit id
+#
+# @brief Get the git log id based on the changed ID
+#
+##########################################################################
+def utilGetCommitID(i_num):
+ print " Change-Id: ",i_num
+ l_found = False
+ #data = []
+
+ # execute the command
+ l_cmd = 'git log'
+ p = subprocess.Popen(l_cmd, stdout=subprocess.PIPE, shell=True)
+
+ while p.poll() is None:
+ line = p.stdout.readline()
+ line = line.strip()
+ if not line:
+ continue
+
+ # Saved off the previous entry which is commit id
+ if line.startswith('commit'):
+ l_saved_commit_id=line
+
+ if line.startswith('Change-Id:'):
+ # Check if the Id is found
+ if i_num in line:
+ l_found=True
+ #print " ", l_saved_commit_id
+ break
+ else:
+ continue
+
+ # Should n't come out without data
+ if l_found:
+ return l_saved_commit_id
+ else:
+ return sbeConstants.ERROR_PREP_COM_FAILED
+
+
OpenPOWER on IntegriCloud