1#!/usr/bin/env kross 2# -*- coding: utf-8 -*- 3 4import os, datetime, sys, traceback, csv, pickle 5import Kross, Plan 6 7T = Kross.module("kdetranslation") 8 9def i18n(text, args = []): 10 if T is not None: 11 return T.i18n(text, args).decode('utf-8') 12 # No translation module, return the untranslated string 13 for a in range( len(args) ): 14 text = text.replace( ("%" + "%d" % ( a + 1 )), str(args[a]) ) 15 return text 16 17class BusyinfoExporter: 18 19 def __init__(self, scriptaction): 20 self.scriptaction = scriptaction 21 self.currentpath = self.scriptaction.currentPath() 22 23 self.proj = Plan.project() 24 25 self.forms = Kross.module("forms") 26 self.dialog = self.forms.createDialog(i18n("Busy Information Export")) 27 self.dialog.setButtons("Ok|Cancel") 28 self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed 29 30 datapage = self.dialog.addPage(i18n("Schedules"),i18n("Export Selected Schedule"),"document-export") 31 self.scheduleview = Plan.createScheduleListView(datapage) 32 33 savepage = self.dialog.addPage(i18n("Save"),i18n("Export Busy Info File"),"document-save") 34 self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kplatobusyinfoexportsave") 35 self.savewidget.setMode("Saving") 36 self.savewidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1' : i18n("Resource Busy Information"), '2' : i18n("All Files") } ) 37 38 if self.dialog.exec_loop(): 39 try: 40 self.doExport( self.proj ) 41 except: 42 self.forms.showMessageBox("Error", i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) 43 44 def doExport( self, project ): 45 filename = self.savewidget.selectedFile() 46 if not filename: 47 self.forms.showMessageBox("Sorry", i18n("Error"), i18n("No file selected")) 48 return 49 schId = self.scheduleview.currentSchedule() 50 if schId == -1: 51 self.forms.showMessageBox("Sorry", i18n("Error"), i18n("No schedule selected")) 52 return 53 file = open( filename, 'wb' ) 54 p = [] 55 p.append( project.id() ) 56 p.append( project.data( project, 'NodeName' ) ) 57 pickle.dump( p, file ) 58 for i in range( project.resourceGroupCount() ): 59 g = project.resourceGroupAt( i ) 60 for ri in range( g.resourceCount() ): 61 r = g.resourceAt( ri ) 62 lst = r.appointmentIntervals( schId ) 63 for iv in lst: 64 iv.insert( 0, r.id() ) 65 iv.insert( 1, project.data( r, 'ResourceName' ) ) 66 pickle.dump( iv, file ) 67 68 file.close() 69 70BusyinfoExporter( self ) 71