Showing posts with label perforce. Show all posts
Showing posts with label perforce. Show all posts

Friday, May 3, 2019

Fromatting Perforce Output For Simple Scripting

Perforce has a global option -ztag




If you run a normal perforce command like this


1
2
3
4
p4 files -m3 ...
//depot/da/infra/dmx/main/lib/python/dmx/tnrlib/__init__.py#1 - add change 4491003 (text+kx)
//depot/da/infra/dmx/main/lib/python/dmx/tnrlib/audit_check.py#57 - edit change 5716075 (text+kx)
//depot/da/infra/dmx/main/lib/python/dmx/tnrlib/css/style.css#1 - branch change 4757380 (text+k)


With the -ztag ...

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
p4 -ztag files -m3 ...
... depotFile //depot/da/infra/dmx/main/lib/python/dmx/tnrlib/__init__.py
... rev 1
... change 4491003
... action add
... type text+kx
... time 1473325143

... depotFile //depot/da/infra/dmx/main/lib/python/dmx/tnrlib/audit_check.py
... rev 57
... change 5716075
... action edit
... type text+kx
... time 1556850031

... depotFile //depot/da/infra/dmx/main/lib/python/dmx/tnrlib/css/style.css
... rev 1
... change 4757380
... action branch
... type text+k
... time 1494905434



Now, say, I'd like to have perforce report out the following info in 3 columns, separated by :::, like this

1
depotFile ::: revision ::: type



All I need to do is run the following:-

1
2
3
4
p42 -ztag -F "%depotFile% ::: %rev% ::: %type%" files -m3 ...
//depot/da/infra/dmx/main/lib/python/dmx/tnrlib/__init__.py ::: 1 ::: text+kx
//depot/da/infra/dmx/main/lib/python/dmx/tnrlib/audit_check.py ::: 57 ::: text+kx
//depot/da/infra/dmx/main/lib/python/dmx/tnrlib/css/style.css ::: 1 ::: text+k


... and here you go :)

Wednesday, May 22, 2013

Working With Perforce -G (Python Marshalled Object) Option

Most common pitfall is to directly get the output pirnted in stdout and marshal it:-

#!/usr/bin/env python
cmd = 'p4 -G changelists -m 3'
mo = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0]
result = marshal.loads(mo)
pprint(result)

Nope. This won't work correctly.
You will only get the last data in the list of 3 items.

This is the correct way to do it:-

#!/usr/bin/env python
cmd = 'p4 -G changelists -m 3'
mo = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

result = []
try:
   while 1:
      output = marshal.load(mo.stdout)
      result.append(output)
except EOFError:
   pass
finally:
   mo.stdout.close()

pprint(result)

How To Bypass Kerberos(kinit) Authentication

Whenever you try to setuid and impersonate as someone else to run something, it is very likely that you will run into kerberos/kinit issues....