-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp4journal.py
100 lines (78 loc) · 2.09 KB
/
p4journal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# This script is public domain, with not warranty or guarantee of functionality
# This script was written to minimize server-side load for highly scaled servers
#
# https://github.com/gorlak/p4scripts
#
# core python
import locale
import optparse
import os
import re
import stat
import subprocess
import sys
import time
#
# setup argument parsing
#
parser = optparse.OptionParser()
( options, args ) = parser.parse_args()
import pprint
pp = pprint.PrettyPrinter( indent=4 )
if os.name != "nt":
print( "Not tested outside of windows\n" )
exit( 1 )
from ctypes import windll, create_string_buffer
# stdin handle is -10
# stdout handle is -11
# stderr handle is -12
h = windll.kernel32.GetStdHandle(-12)
csbi = create_string_buffer(22)
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
if res:
import struct
(bufx, bufy, curx, cury, wattr,
left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
sizex = right - left + 1
sizey = bottom - top + 1
else:
sizex, sizey = 80, 25 # can't determine actual size - return default values
#
# main
#
try:
increment = 100000
notify = increment
count = 0
matched = 0
workspaces = dict()
for arg in args:
j = open(arg)
for line in iter(j):
count = count + 1
match = re.match( r'@rv@ [0-9]+ @db.have@ @//(.*?)/', line )
if match != None:
matched = matched + 1
workspace = match.group(1)
workspaceCount = 0
if workspace in workspaces.keys():
workspaceCount = workspaces[ workspace ]
workspaceCount = workspaceCount + 1
workspaces[ workspace ] = workspaceCount
if count == notify:
notify = notify + increment
print( str( len(workspaces) ) )
os.system('cls')
print( "Matched " + str( matched ) + " of " + str( count ) + " lines." )
sortedWorkspaces = list( workspaces.items() )
sortedWorkspaces.sort(key=lambda tup: tup[1], reverse=True)
screenLines = 3
for k, v in sortedWorkspaces:
print( k + ": " + str( v ) )
screenLines = screenLines + 1
if screenLines == sizey:
break
j.close()
except KeyboardInterrupt:
exit( 1 )