isitalabel.py #2

  • //
  • guest/
  • perforce_software/
  • sdp/
  • main/
  • Maintenance/
  • isitalabel.py
  • View
  • Commits
  • Open Download .zip Download (1 KB)
#!/usr/bin/python

"""
Determine if a label exists in Perforce.

Usage:
  isitalabel.py labelname

Program will print out results of the search.
Sets ISALABEL in the environment to 0 if found, 1 if not found.
Also will exit with errorlevel 1 if the label is not found
"""

import os
import re
import string
import sys

def check(label):
  update_pattern = re.compile("^Update:.*", re.IGNORECASE)

  os.environ ["ISALABEL"] = "0"
  isfound = 0

  for line in os.popen("p4 label -o %s" % (label)).readlines():
    found = update_pattern.match(line)
    if found != None:
      os.environ ["ISALABEL"]= "1"
      isfound = 1

  return isfound

def main():
  if len(sys.argv) == 2:
    fnd = check(sys.argv[1])
    if fnd == 1:
      print ("The Label %s exists") % (sys.argv[0])
    else:
      print ("The Label %s does not exist.") % (sys.argv[1])
      sys.exit(0)

  if len(sys.argv) > 2:
    print ("You should only enter 1 label name on the command line")

###########################################################################
# main
if __name__ == '__main__':
  main()

# Change User Description Committed
#3 27331 C. Thomas Tyler Released SDP 2020.1.27325 (2021/01/29).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#2 26161 C. Thomas Tyler Released SDP 2019.3.26159 (2019/11/06).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#1 20353 C. Thomas Tyler Released SDP 2016.1.20348.
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev',
with selective removal of changes related to work-in-progress
changes.
//guest/perforce_software/sdp/dev/Maintenance/isitalabel.py
#1 20289 Russell C. Jackson (Rusty) Script to convert labels to autoreload labels