#!/usr/bin/env python3
"""
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 subprocess
import sys
def check(label):
update_pattern = re.compile("^Update:.*", re.IGNORECASE)
os.environ["ISALABEL"] = "0"
isfound = 0
result = subprocess.run(
["p4", "label", "-o", label],
capture_output=True, text=True
)
for line in result.stdout.splitlines():
found = update_pattern.match(line)
if found is not 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[1])
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 | |
|---|---|---|---|---|---|
| #4 | 32423 | Russell C. Jackson (Rusty) |
Modernize SDP maintenance scripts: security, correctness, and Python 3 - Replace all os.system() and os.popen() calls with subprocess.run() using argument lists to eliminate shell injection vulnerabilities - Fix critical bugs: broken indentation in convert_label_to_autoreload.py, malformed print() in p4lock/p4unlock, wrong variable in isitalabel, format string typo in maintain_user_from_groups - Add p4 property alias and shared SKIP_USERS constant to sdputils.py - Add try/finally with p4.disconnect() to all P4Python scripts - Replace bare except: with specific exception types throughout - Update all shebangs to python3, remove unnecessary __future__ imports - Use context managers for all file handle operations - Replace from subprocess import * with explicit imports |
||
| #3 | 32388 | Russell C. Jackson (Rusty) | Updates using Claude.ai to clean up the code, reduce duplication, enhanace security, and use current standards. | ||
| #2 | 24675 | Russell C. Jackson (Rusty) |
Fixed bugs in sdputils.py and scripts using it. Converted to standard 2 space spacing, removed copyright stuff. |
||
| #1 | 22693 | Russell C. Jackson (Rusty) |
Branched a Unix only version of the SDP. Removed extra items to create a cleaner tree. Moved a few items around to make more sense without Windows in the mix. |
||
| //guest/perforce_software/sdp/dev/Maintenance/isitalabel.py | |||||
| #1 | 20289 | Russell C. Jackson (Rusty) | Script to convert labels to autoreload labels | ||