# Run this script under the System Account that owns / start Perforce,
# which will be the local system account if it is running as a Windows Service
# There are two ways that you can run this script:
# (a) As a trigger script, add the following line to the p4 triggers table
#
# In Windows:
#
# p4-report form-out client "C:\Python3\python.exe C:\p4-report.py %serverport% %serverhost% %serverip% %user%"
#
# In *nix:
#
# p4-report form-out client "/usr/bin/Python3 /users/Perforce/triggers/p4-report.py %serverport% %serverhost% %serverip% %user%"
#
# Or, (b) Run inside a command prompt / shell
#
# In Windows:
#
# Download and install psexec.exe from here:
#
# http://technet.microsoft.com/en-au/sysinternals/bb897553.asp
#
# Start a Local System Acccount prompt in Administrator prompt:
#
# psexec -i -s cmd.exe
#
# In *nix:
#
# Simply run it using the unix account that owns / start the Perforce Server
#
import os
import sys
print("############# p4-report START ##################")
if len(sys.argv) > 4:
print ("serverport=[ {0} ] serverhost=[ {1} ] serverip=[ {2} ] user=[ {3} ]".format(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]))
print("\n")
print ("P4USER = {0}".format(os.environ.get('P4UER')))
print ("P4PORT = {0}".format(os.environ.get('P4PORT')))
print ("P4CHARSET = {0}".format(os.environ.get('P4CHARSET')))
print ("P4TICKETS = {0}".format(os.environ.get('P4TICKETS')))
print("\n'p4 tickets' => \n{0}".format(os.popen("p4 tickets").read()))
print("\n'p4 info' => \n{0}".format(os.popen("p4 info").read()))
if sys.platform.startswith('linux'):
print ("HOME = {0}".format(os.environ.get('HOME')))
print("\n'p4 set' => \n{0}".format(os.popen('p4 set').read()))
elif sys.platform.startswith('win'):
print ("USERPROFILE = {0}".format(os.environ.get('USERPROFILE')))
print("\n'p4 set' => \n{0}".format(os.popen('p4 set -S Perforce').read()))
print("############# p4-report END ##################\n\n")