-
Notifications
You must be signed in to change notification settings - Fork 0
/
pa.py
executable file
·202 lines (161 loc) · 6.36 KB
/
pa.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python3
'''
Kevin's custom cli customizations:
1. Reduced the group list to only those groups I actually use.
2. Rearrange the order of the fields so that activity is prompted after the description is entered.
'''
import sys
import os
import cli
import log
class PerfAppCli(cli.ReportCli):
def displayHelp(self, *args):
'''
Called when "help" or "h" is typed. Prints a help message.
'''
#!print("displayHelp(", args, ")")
print("""
Commands:
help (h) displays this help
groups (lg) list all available groups
codes (pc) list all available pay codes
chd set a custom date to be used as the default
cld clear the custom date
lsd list the default date
sum [cat] displays the month summary w/o details (hours)
psum [cat] displays the month summary w/o details (percent)
rep [cat] displays the month summary w/ details (hours)
prep [cat] displays the month summary w/ details (percent)
pcr [pc] displays a pay code report w/o details (hours)
print (p) [#] prints info from the log file (default=everything)
list [label ...] list the labels used in the log. Default labels are
activity, group and title.
sc Start capturing report output to a text file instead of
printing it to stdout.
ec End capture report output to a text file. Quitting will
automatically close this file.
""")
return True
# Override the definition function to customize interface defaults
def definitions(self):
# Only a subset of commands apply for the year
self.commands = {
"help": self.displayHelp,
"h": self.displayHelp,
"print": self.displayLog,
"p": self.displayLog,
"chd": self.changeDate,
"cld": self.clearDate,
"lsd": self.showDate,
"exit": self.quit,
"quit": self.quit,
"q": self.quit,
"sum": self.displaySummary,
"psum": self.displayPercentSummary,
"rep": self.displayReport,
"prep": self.displayPercentReport,
"list": self.listLabels,
"l": self.listLabels,
"groups": self.listGroups,
"lg": self.listGroups,
"codes": self.listPayCodes,
"pc": self.listPayCodes,
"pcr": self.displayPayCodeReport,
"sc": self.startCapture,
"ec": self.endCapture,
}
# You can specify a different default name for the log file
self.logFilename = "work_log.xml"
# You can change the terminal width that is used to wrap text when displaying summaries
self.terminalWidth = 132
# Restore pre-Jira wr/wrep output
#!self.wrDateSort = False
# Here is where you can specify only the groups you regularly use
self.possibleGroups = ['',
'BCDA', 'Jira', 'MEDM Replacement', 'motor', 'synApps',
#'EPICS base', 'EPICS clients', 'areaDetector',
#'Python', 'spec', 'VxWorks', 'Beamline Comp Env',
'09ID-B', '09ID-C', '15ID', '26ID', '32ID', '33BM', '33ID',
'34ID-C', '34ID-E', 'XSD', 'Leave', '33ID-C HFM',
'ATOMIC/3DMN Support', 'ATOMIC/3DMN Design',
'ATOMIC 34ID-F', '3DMN 34ID-E']
self.payCodeDict = {#'None':'None',
'VAC':'Vacation',
'SIC':'Sick Pay',
'SLF':'Sick Leave Family',
'FHL':'Floating Holiday',
#'BRV':'Bereavement',
#'CL1':'Operations Suspended',
#'JUR':'Jury Duty',
#'PAR':'Parental Leave*',
'RG':'Regular',
'TEL':'TELECOMMUTING*'
}
self.possiblePayCodes = sorted(list(self.payCodeDict.keys()))
# Improve correctEntry prompts
#!self.showCorrectDefaults = True
#!self.showCorrectDescLen = 60
### Improve the wt command for Dayforce
self.showWBSCodes = True
# The cost codes are now workday project plans, which are only differentiated by the WBS code. Save screen space and omit them.
self.showCostCodes = False
# Pay codes only appear on d, ds and wd output
self.showPayCodes = True
# Use the default pay code for everything
self.promptForPayCode = False
# Temporarily change default pay code
self.defaultPayCode = "TEL"
def _getLogFilenames(self):
'''
Internal routine that determines the user-specified log file names
'''
# Allow the user to specify an log file when running the script
if len(sys.argv) > 1:
args = sys.argv[1:]
else:
args = ["{}/{}".format(os.getcwd(), self.logFilename),]
filepaths = []
for arg in args:
# Check to see if the file exists
if os.path.isfile(arg):
filepaths.append(arg)
else:
print("{} DOES NOT EXIST!".format(arg))
return filepaths[:]
# Override the createReportLog function so that PerfAppLog is used instead of ReportLog
def createReportLog(self, filepaths):
return PerfAppLog(filepaths)
# Override runMainLoop to allow handling multiple filenames
def runMainLoop(self):
# Get log filenames
filepaths = self._getLogFilenames()
if len(filepaths) > 0:
self.run = True
self.logObj = self.createReportLog(filepaths)
self.logEntryDef = self.logObj.getLogEntryDef()
# Run the main loop
self.main()
class PerfAppLog(log.ReportLog):
def __init__(self, logFiles):
self.definitions()
# Note: the ReportLog class also defines a logFile member, but that isn't needed here;
# all of the commands that use it have been removed.
self.entryArray = []
for logFile in logFiles:
print("Reading {}".format(logFile))
# Append the entries from each log file to the entry array
self.entryArray += (self.createLogFileObj(logFile, self.logEntryDef[:])).convertLogToObjs()
# Override the definition function to change the order of items in logEntryDef
# NOTE: group must always come before title
def definitions(self):
self.logEntryDef = [
"date",
"duration",
"group",
"title",
"description",
"activity",
"payCode"
]
if __name__ == '__main__':
perfAppCli = PerfAppCli()