#!/usr/local/bin/python
# isalabel.py
#
# Determine if a label exists
#
# Written April 2000 by Joshua Grigonis
import re, sys, string, os
update_pattern = re.compile ('Update:.*', re.IGNORECASE)
HELPTEXT = """
Usage:
\tpython isalabel.py [label]
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
"""
def check (label):
os.environ ["ISALABEL"] = "0"
isfound = 0
for line in os.popen ('p4 label -o ' + label).readlines():
found = update_pattern.match (line)
if found != None:
os.environ ["ISALABEL"]= "1"
isfound = 1
return isfound
# end of check() function
def run():
label = raw_input ('Enter label to check: ')
fnd = check(label)
if fnd == 1:
print "The Label " + label + " exists"
else:
print "The Label " + label + " does not exist"
sys.exit(1)
# end of run() function
if __name__ == '__main__':
if len(sys.argv) == 1:
run()
if len(sys.argv) == 2:
if string.upper(sys.argv[1]) == "/HELP":
print HELPTEXT
sys.exit(0)
if sys.argv[1] == "/?":
print HELPTEXT
sys.exit(0)
if string.upper(sys.argv[1]) == "-HELP":
print HELPTEXT
sys.exit(0)
fnd = check(sys.argv[1])
if fnd == 1:
print "The Label " + sys.argv[1] + " exists"
else:
print "The Label " + sys.argv[1] + " does not exist"
sys.exit(1)
if len(sys.argv) > 2:
print "You should only enter 1 label name on the command line"
# end of isalabel.py