#!/usr/bin/python
# find old workspace. For example: find the workspaces that have not
# been accessed for 60 days.
import os
import sys
import time
import datetime
from subprocess import Popen, PIPE
GAP = 3600*24*60 #two MONTH
MAXITEMS = "1000" # max return clients
PASSWD = b"abcd.1234\n"
t = time.time()
itime = int(t) - GAP
os.environ['P4PORT']='192.168.56.101:1666'
os.environ['P4USER']='root'
os.environ['P4CHARSET'] = 'utf8'
#os.environ['P4PASSWD'] = "abcd.1234"
def run_cmd(cmd):
# Popen call wrapper.return (code, stdout, stderr)
child = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
out, err = child.communicate()
ret = child.wait()
return (ret, out, err)
s = Popen("p4 login", stdin=PIPE, stdout=PIPE, shell=True)
s.stdin.write(PASSWD)
s.stdin.close()
output = s.stdout.read().decode("GBK")
s.stdout.close()
print output
cmdstr = 'p4 -ztag clients -m ' + MAXITEMS
(ret, r, err) = run_cmd(cmdstr)
if ret != 0:
print r, err
exit(1)
oldws = []
curclient = ""
lines = r.split('\n')
i = 0
while i < len(lines):
# print i, lines[i]
x = lines[i]
if x.find("... client ") != -1:
curclient = x.split(' ')[2]
y = lines[i+2].split(' ')[2]
if (int(y) < itime):
hacctime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(y)))
owner = lines[i+3].split(' ')[2]
oldws.append((owner, curclient,hacctime))
i = i + 12
i = i+1
for (o, c, t) in oldws:
print ("%-15s %-45s %-20s"%(o, c, t))
# |
Change |
User |
Description |
Committed |
|
#1
|
26725 |
Pei Li |
add check job and delete old workspaces script. |
|
|