Re: [p4] Anyone have a way to preview p4 protect updates outside of the P4V admin tool?

Sambwise <[email protected]> Mon, 2 Apr 2018 22:10:01 -0700
Newsgroups gmane.comp.version-control.perforce
Message-ID <[email protected]>
Posted on behalf of forum user 'Sambwise'.

I decided to see if I still remember how to do this stuff:

import argparse import enum import shlex import P4 argp =
argparse.ArgumentParser(description='Run protection table checks.')
argp.add_argument('-i', dest='input', help='Input filename
for protect table', required=True) argp.add_argument('-u',
dest='user', help='User to check', required=True)
argp.add_argument('-p', dest='perm', help='Permission level
to check', required=True) argp.add_argument('-g', # This is so you
can pass a list of groups the user is a member of. dest='groups',
help='Group(s) to include', action='append')
argp.add_argument('path', help='Depot path to check') args =
argp.parse_args() # Build up dict of desired permission to levels we see in the
table. perms = {} # type: Dict[str, Set[str]] for perm in
['read', 'branch', 'open', 'write']:
perms['='+perm] = set([perm])
perms['list'] = set(['list'])
perms['read'] = perms['list'] |
perms['=branch'] | perms['=read']
perms['open'] = perms['read'] |
perms['=open'] perms['write'] =
perms['open'] | perms['=write']
perms['admin'] = perms['write'] |
set(['admin']) perms['super'] =
perms['admin'] | set(['super'])
perms['review'] = perms['read'] |
set(['review']) perms['owner'] =
set(['owner']) # Parse the file and build a map. f =
open(args.input, 'r') spec = P4.P4().parse_protect(f.read()) map =
P4.Map() for line in spec._Protections: perm, type, name, _, path =
shlex.split(line) # Check to see if this line is applicable to our protection
map. if args.perm not in perms[perm]: continue if type == 'user'
and name != args.user: continue if type == 'group' and name not in
args.groups: continue map.insert('"'+path+'"')
print("%s's %s protections mapping:" % (args.user, args.perm))
print(map) print("includes %s? %s" % (args.path,
map.includes(args.path))) 



--
Please click here to see the post in its original format:
  http://forums.perforce.com/index.php?/topic/5674-anyone-have-a-way-to-preview-p4-protect-updates-outside-of-the-p4v-admin-tool
_______________________________________________
perforce-user mailing list  -  [email protected]
http://maillist.perforce.com/mailman/listinfo/perforce-user