2
# -*- coding: utf-8 -*-
4
import os, sys, traceback, tempfile, zipfile
10
State_StartedEarly = 2
12
State_FinishedLate = 4
13
State_FinishedEarly = 5
16
State_RunningEarly = 8
17
State_ReadyToStart = 9 # all precceeding tasks finished (if any)
18
State_NotReadyToStart = 10 # all precceeding tasks not finished (must be one or more)
19
State_NotScheduled = 11
21
def testBit(int_type, offset):
23
return ( int_type & mask ) > 0
25
def state( int_type ):
26
if testBit( int_type, State_NotScheduled ) is True:
27
return "Not scheduled"
28
if testBit( int_type, State_FinishedEarly ) is True:
29
return "Finished early"
30
if testBit( int_type, State_FinishedLate ) is True:
31
return "Finished late"
32
if testBit( int_type, State_Finished ) is True:
34
if testBit( int_type, State_ReadyToStart ) is True:
35
return "Ready to start"
36
if testBit( int_type, State_NotReadyToStart ) is True:
37
return "Not ready to start"
38
if testBit( int_type, State_StartedLate ) is True:
40
if testBit( int_type, State_StartedEarly ) is True:
41
return "Started early"
42
if testBit( int_type, State_RunningEarly ) is True:
43
return "Running early"
44
if testBit( int_type, State_RunningLate ) is True:
46
if testBit( int_type, State_Running ) is True:
49
return "Error: Invalid state %d" % ( int_type )
52
def printStates( node, schedule ):
53
printState( node, schedule )
54
for i in range( node.childCount() ):
55
printStates( node.childAt( i ), schedule )
57
def printState( node, schedule ):
58
if node.type() in [ 'Task' ]:
59
st = Plan.project().data( node, 'Status', 'EditRole', schedule )
60
print "%-30s %-20s %20s" % (
61
Plan.project().data( node, 'Name', 'DisplayRole', schedule ),
62
Plan.project().data( node, 'Status', 'DisplayRole', schedule ),
65
def printNodes( node, props, schedule, types = None ):
66
printNode( node, props, schedule, types )
67
for i in range( node.childCount() ):
68
printNodes( node.childAt( i ), props, schedule, types )
70
def printNode( node, props, schedule, types = None ):
71
if types is None or node.type() in types:
73
print "%-25s" % ( Plan.project().data( node, prop[0], prop[1], schedule ) ),
76
def printGroup( group, props ):
78
print "%-25s" % ( Plan.project().data( group, prop ) ),
80
for i in range( group.resourceCount() ):
81
printResource( group.resourceAt( i ), props )
83
def printResource( resource, props ):
85
print "%-25s" % ( Plan.project().data( resource, prop ) ),
89
print "%-10s %-25s %-10s" % ( "Identity", "Name", "Scheduled" )
90
for i in range( proj.scheduleCount() ):
91
printSchedule( proj.scheduleAt( i ) )
95
def printSchedule( sch ):
96
print "%-10s %-25s %-10s" % ( sch.id(), sch.name(), sch.isScheduled() )
97
for i in range( sch.childCount() ):
98
printSchedule( sch.childAt( i ) )
100
def printEffortCost( name, values ):
101
print "%-20s" % ( name )
102
for d, v in sorted( values.iteritems() ):
105
print "%-20s %-15s %20f %20f" % ( "", d, e, c )
107
def printProjectBusyinfo( proj ):
108
print "%-20s %-30s %-30s %8s" % ( "Resource", "Start", "End", "Load" )
109
id = proj.scheduleAt( 0 ).id()
110
for gi in range( proj.resourceGroupCount() ):
111
g = proj.resourceGroupAt( gi )
112
for ri in range( g.resourceCount() ):
113
r = g.resourceAt( ri )
114
printBusyinfo( r, r.appointmentIntervals( id ) )
119
def printBusyinfo( res, lst ):
120
name = Plan.project().data( res, 'Name' )
122
print "%-20s %-30s %-30s %8s" % ( name, interval[0], interval[1], interval[2] )
125
def printProjectCalendars( proj ):
126
for c in range( proj.calendarCount() ):
127
printChildCalendars( proj.calendarAt ( c ) )
129
def printChildCalendars( calendar ):
130
print calendar.name()
131
for c in range( calendar.childCount() ):
132
printChildCalendars( calendar.childAt ( c ) )
135
def printExternalProjects( proj ):
136
projects = proj.externalProjects()
137
if len(projects) == 0:
138
print "No external project appointments"
140
if len(projects) % 2 == 1:
141
print "Illegal id/name pair in list: %s" % projects
144
print "%-35s %s" % ( "Identity", "Name" )
146
print "%-35s %s" % ( c[0], c[1] )
148
def printTaskEffortCost( parent ):
149
for i in range( parent.childCount() ):
150
node = parent.childAt( i )
151
name = Plan.project().data( node, 'Name' )
152
printEffortCost( name, node.plannedEffortCostPrDay( "2007-09-12", "2007-09-18", sid ) )
154
#------------------------
155
proj = Plan.project()
159
if proj.scheduleCount() > 0:
160
sid = proj.scheduleAt( 0 ).id()
162
print "Using schedule id: %-3s" % ( sid )
165
nodeprops = [['WBSCode', 'DisplayRole'], ['Name', 'DisplayRole'], ['Type', 'DisplayRole'], ['Responsible', 'DisplayRole'], ['Status', 'EditRole'] ]
166
print "Print tasks and milestones in arbitrary order:"
167
# print the localized headers
168
for prop in nodeprops:
169
print "%-25s" % (proj.taskHeaderData( prop ) ),
171
printNodes( proj, nodeprops, sid, [ 'Task', 'Milestone' ] )
174
print "Print all nodes including project:"
175
for prop in nodeprops:
176
print "%-25s" % (proj.taskHeaderData( prop ) ),
178
printNodes( proj, nodeprops, sid )
181
print "Print Resources:"
182
resprops = [ 'Name', 'Type', 'Email', 'Calendar' ]
183
# print the localized headers
184
for prop in resprops:
185
print "%-25s" % (proj.resourceHeaderData( prop ) ),
187
for index in range( proj.resourceGroupCount() ):
188
g = proj.resourceGroupAt( index )
189
printGroup( g, resprops )
193
print "Print Schedules:"
198
print "Print Effort/Cost for each task:"
199
print "%-20s %-10s %-10s %-10s" % ( 'Name', 'Date', 'Effort', 'Cost' )
200
printTaskEffortCost( proj )
202
print "Print Effort/Cost for the project:"
203
print "%-20s %-10s %-10s %-10s" % ( 'Name', 'Date', 'Effort', 'Cost' )
204
printEffortCost( proj.name(), proj.plannedEffortCostPrDay( "2007-09-12", "2007-09-17", sid ) )
206
print "Print Busy information for all resources in the project:"
207
printProjectBusyinfo( proj )
210
print "Print the calendars in the project:"
211
printProjectCalendars( proj )
214
print "Print planned Effort/Cost for each account:"
215
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' )
216
for i in range( proj.accountCount() ):
217
account = proj.accountAt( i )
218
name = Plan.project().data( account, 'Name' )
219
printEffortCost( name, account.plannedEffortCostPrDay( sid ) )
222
print "Print actual Effort/Cost for each account:"
223
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' )
224
for i in range( proj.accountCount() ):
225
account = proj.accountAt( i )
226
name = Plan.project().data( account, 'Name' )
227
printEffortCost( name, account.actualEffortCostPrDay( sid ) )
230
print "Print BCWS for the project:"
231
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' )
232
printEffortCost( proj.name(), proj.bcwsPrDay( sid ) )
234
print "Print BCWP for the project:"
235
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' )
236
printEffortCost( proj.name(), proj.bcwpPrDay( sid ) )
239
print "Print ACWP for the project:"
240
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' )
241
printEffortCost( proj.name(), proj.acwpPrDay( sid ) )
244
print "Print Task status:"
245
printStates( proj, sid )
248
print "Print external projects:"
249
printExternalProjects( proj )