| 1 |
#!/usr/bin/env kross |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
import os, sys, traceback, tempfile, zipfile |
| 5 |
import Kross |
| 6 |
import Plan |
| 7 |
|
| 8 |
State_Started = 0 |
| 9 |
State_StartedLate = 1 |
| 10 |
State_StartedEarly = 2 |
| 11 |
State_Finished = 3 |
| 12 |
State_FinishedLate = 4 |
| 13 |
State_FinishedEarly = 5 |
| 14 |
State_Running = 6 |
| 15 |
State_RunningLate = 7 |
| 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 |
| 20 |
|
| 21 |
def testBit(int_type, offset): |
| 22 |
mask = 1 << offset |
| 23 |
return ( int_type & mask ) > 0 |
| 24 |
|
| 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: |
| 33 |
return "Finished" |
| 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: |
| 39 |
return "Started late" |
| 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: |
| 45 |
return "Running late" |
| 46 |
if testBit( int_type, State_Running ) is True: |
| 47 |
return "Running" |
| 48 |
if int_type > 0: |
| 49 |
return "Error: Invalid state %d" % ( int_type ) |
| 50 |
return "None" |
| 51 |
|
| 52 |
def printStates( node, schedule ): |
| 53 |
printState( node, schedule ) |
| 54 |
for i in range( node.childCount() ): |
| 55 |
printStates( node.childAt( i ), schedule ) |
| 56 |
|
| 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 ), |
| 63 |
state( int( st ) ) ) |
| 64 |
|
| 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 ) |
| 69 |
|
| 70 |
def printNode( node, props, schedule, types = None ): |
| 71 |
if types is None or node.type() in types: |
| 72 |
for prop in props: |
| 73 |
print "%-25s" % ( Plan.project().data( node, prop[0], prop[1], schedule ) ), |
| 74 |
print |
| 75 |
|
| 76 |
def printGroup( group, props ): |
| 77 |
for prop in props: |
| 78 |
print "%-25s" % ( Plan.project().data( group, prop ) ), |
| 79 |
print |
| 80 |
for i in range( group.resourceCount() ): |
| 81 |
printResource( group.resourceAt( i ), props ) |
| 82 |
|
| 83 |
def printResource( resource, props ): |
| 84 |
for prop in props: |
| 85 |
print "%-25s" % ( Plan.project().data( resource, prop ) ), |
| 86 |
print |
| 87 |
|
| 88 |
def printSchedules(): |
| 89 |
print "%-10s %-25s %-10s" % ( "Identity", "Name", "Scheduled" ) |
| 90 |
for i in range( proj.scheduleCount() ): |
| 91 |
printSchedule( proj.scheduleAt( i ) ) |
| 92 |
print |
| 93 |
|
| 94 |
|
| 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 ) ) |
| 99 |
|
| 100 |
def printEffortCost( name, values ): |
| 101 |
print "%-20s" % ( name ) |
| 102 |
for d, v in sorted( values.iteritems() ): |
| 103 |
e = v[0] |
| 104 |
c = v[1] |
| 105 |
print "%-20s %-15s %20f %20f" % ( "", d, e, c ) |
| 106 |
|
| 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 ) ) |
| 115 |
print |
| 116 |
|
| 117 |
print |
| 118 |
|
| 119 |
def printBusyinfo( res, lst ): |
| 120 |
name = Plan.project().data( res, 'Name' ) |
| 121 |
for interval in lst: |
| 122 |
print "%-20s %-30s %-30s %8s" % ( name, interval[0], interval[1], interval[2] ) |
| 123 |
name = "" |
| 124 |
|
| 125 |
def printProjectCalendars( proj ): |
| 126 |
for c in range( proj.calendarCount() ): |
| 127 |
printChildCalendars( proj.calendarAt ( c ) ) |
| 128 |
|
| 129 |
def printChildCalendars( calendar ): |
| 130 |
print calendar.name() |
| 131 |
for c in range( calendar.childCount() ): |
| 132 |
printChildCalendars( calendar.childAt ( c ) ) |
| 133 |
|
| 134 |
|
| 135 |
def printExternalProjects( proj ): |
| 136 |
projects = proj.externalProjects() |
| 137 |
if len(projects) == 0: |
| 138 |
print "No external project appointments" |
| 139 |
return |
| 140 |
if len(projects) % 2 == 1: |
| 141 |
print "Illegal id/name pair in list: %s" % projects |
| 142 |
return |
| 143 |
|
| 144 |
print "%-35s %s" % ( "Identity", "Name" ) |
| 145 |
for c in projects: |
| 146 |
print "%-35s %s" % ( c[0], c[1] ) |
| 147 |
|
| 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 ) ) |
| 153 |
|
| 154 |
#------------------------ |
| 155 |
proj = Plan.project() |
| 156 |
|
| 157 |
sid = -1; |
| 158 |
# get a schedule id |
| 159 |
if proj.scheduleCount() > 0: |
| 160 |
sid = proj.scheduleAt( 0 ).id() |
| 161 |
|
| 162 |
print "Using schedule id: %-3s" % ( sid ) |
| 163 |
print |
| 164 |
|
| 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 ) ), |
| 170 |
print |
| 171 |
printNodes( proj, nodeprops, sid, [ 'Task', 'Milestone' ] ) |
| 172 |
print |
| 173 |
|
| 174 |
print "Print all nodes including project:" |
| 175 |
for prop in nodeprops: |
| 176 |
print "%-25s" % (proj.taskHeaderData( prop ) ), |
| 177 |
print |
| 178 |
printNodes( proj, nodeprops, sid ) |
| 179 |
print |
| 180 |
|
| 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 ) ), |
| 186 |
print |
| 187 |
for index in range( proj.resourceGroupCount() ): |
| 188 |
g = proj.resourceGroupAt( index ) |
| 189 |
printGroup( g, resprops ) |
| 190 |
|
| 191 |
print |
| 192 |
|
| 193 |
print "Print Schedules:" |
| 194 |
printSchedules() |
| 195 |
print |
| 196 |
|
| 197 |
|
| 198 |
print "Print Effort/Cost for each task:" |
| 199 |
print "%-20s %-10s %-10s %-10s" % ( 'Name', 'Date', 'Effort', 'Cost' ) |
| 200 |
printTaskEffortCost( proj ) |
| 201 |
print |
| 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 ) ) |
| 205 |
print |
| 206 |
print "Print Busy information for all resources in the project:" |
| 207 |
printProjectBusyinfo( proj ) |
| 208 |
print |
| 209 |
|
| 210 |
print "Print the calendars in the project:" |
| 211 |
printProjectCalendars( proj ) |
| 212 |
print |
| 213 |
|
| 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 ) ) |
| 220 |
print |
| 221 |
|
| 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 ) ) |
| 228 |
print |
| 229 |
|
| 230 |
print "Print BCWS for the project:" |
| 231 |
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' ) |
| 232 |
printEffortCost( proj.name(), proj.bcwsPrDay( sid ) ) |
| 233 |
print |
| 234 |
print "Print BCWP for the project:" |
| 235 |
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' ) |
| 236 |
printEffortCost( proj.name(), proj.bcwpPrDay( sid ) ) |
| 237 |
print |
| 238 |
|
| 239 |
print "Print ACWP for the project:" |
| 240 |
print "%-20s %-15s %20s %20s" % ( 'Name', 'Date', 'Effort', 'Cost' ) |
| 241 |
printEffortCost( proj.name(), proj.acwpPrDay( sid ) ) |
| 242 |
print |
| 243 |
|
| 244 |
print "Print Task status:" |
| 245 |
printStates( proj, sid ) |
| 246 |
print |
| 247 |
|
| 248 |
print "Print external projects:" |
| 249 |
printExternalProjects( proj ) |
| 250 |
print |