#!/usr/bin/env python #============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE #------------------------------------------------------------------------------ # MANAGED BY ANSIBLE (perforce-sdp-install / group_limits.yml) -- do not edit by # hand. The exempt user and group lists are templated from host_vars # (p4_trigger_exempt_users / p4_trigger_exempt_groups). #------------------------------------------------------------------------------ """ Usage: keep_group_unset form-in group "/p4/common/bin/triggers/keep_group_unset.py %formfile% %user%" This script is designed to run as a form in trigger on the server. It changes any unlimited group values to unset. """ import os import re import sys import tempfile admins = [ {% for u in p4_trigger_exempt_users %}'{{ u }}'{% if not loop.last %}, {% endif %}{% endfor %} ] user = sys.argv[2] # Exit if the perforce user is modifying the form. if user in admins: sys.exit(0) input = open(sys.argv[1], "r") fd, temppath = tempfile.mkstemp(dir=os.path.dirname(os.path.abspath(sys.argv[1]))) output = os.fdopen(fd, "w") admingroup = False admingroups = [{% for g in p4_trigger_exempt_groups %}"{{ g }}"{% if not loop.last %}, {% endif %}{% endfor %}] for line in input.readlines(): # Exit if group being modified is an admin group. m = re.match(r"^Group:\s+(\S+)", line) if m and m.group(1) in admingroups: admingroup = True break if re.search(r"^Max.*:", line): line = re.sub(":.*", ": unset" , line) elif re.search(r"^Timeout.*:", line): line = re.sub(":.*", ": unset" , line) output.write(line) input.close() output.close() if admingroup == False: os.replace(temppath, sys.argv[1]) else: os.remove(temppath) sys.exit(0)