예제 #1
0
def printState( node, schedule ):
    if node.type() in [ 'Task' ]:
        st = KPlato.data( node, 'NodeStatus', 'EditRole', schedule )
        print "%-30s %-20s %20s" % ( 
            KPlato.data( node, 'NodeName', 'DisplayRole', schedule ),
            KPlato.data( node, 'NodeStatus', 'DisplayRole', schedule ),
            state( int( st ) ) )
예제 #2
0
    def doExport( self, project ):
        filename = self.savewidget.selectedFile()
        if not filename:
            self.forms.showMessageBox("Sorry", i18n("Error"), i18n("No file selected"))
            return
        schId = self.scheduleview.currentSchedule()
        if schId == -1:
            self.forms.showMessageBox("Sorry", i18n("Error"), i18n("No schedule selected"))
            return
        # cal= Calendar()
        # cal.add('prodid', '-//'+project.id()+'//'+KPlato.data(project, 'NodeName'))
        # cal.add('version', '0.1')
        file = open( filename, 'wb' )
        print("=================== "+str(project.id())+str(KPlato.data(project,'NodeName'))+" ==================",file=file)
        for i in range( project.resourceGroupCount() ):
            g = project.resourceGroupAt( i )
            print (g,file=file)
            for ri in range( g.resourceCount() ):
                r = g.resourceAt( ri )
                print("====> r:\n\t", "\n\t".join( dir(r)),file=file)
                lst = r.appointmentIntervals( schId )
                print("====> lst:\n\t", "\n\t".join(dir(lst)),file=file)
                for iv in lst:
                    print(r.id(), KPlato.data( r, 'ResourceName' ), iv, sep=" | ", file=file)
                    print ("====> iv:\n\t", "\n\t".join( dir(iv)),file=file)
                    # iv.insert( 0, r.id() )
                    # iv.insert( 1, KPlato.data( r, 'ResourceName' ) )
                    # pickle.dump( iv, file )

        file.close()
예제 #3
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        self.currentpath = self.scriptaction.currentPath()

        self.proj = KPlato.project()
        
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog(i18n("Busy Information Export"))
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        datapage = self.dialog.addPage(i18n("Schedules"),i18n("Export Selected Schedule"),"document-export")
        self.scheduleview = KPlato.createScheduleListView(datapage)
        
        savepage = self.dialog.addPage(i18n("Save"),i18n("Export Busy Info File"),"document-save")
        self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kplatobusyinfoexportsave")
        self.savewidget.setMode("Saving")
        self.savewidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1' : i18n("Resource Busy Information"), '2' : i18n("All Files") } )

        if self.dialog.exec_loop():
            try:
                self.doExport( self.proj )
            except Exception, inst:
                self.forms.showMessageBox("Sorry", i18n("Error"), "%s" % inst)
            except:
예제 #4
0
 def loadAppointment( self, project, pid, pname, data ):
     r = project.findResource( data[0] )
     if r is None:
         print "Resource is not used in this project: %s, %s" % ( data[0], data[1] )
         return
     if KPlato.data( r, 'ResourceName' ) != data[1]:
         #TODO Warning ?
         print "Resources has same id but different names %s - %s" % ( KPlato.data( r, 'ResourceName' ), data[1] )
     r.addExternalAppointment( pid, pname, data[2:5] )
예제 #5
0
    def doImport( self, project ):
        filename = self.openwidget.selectedFile()
        if not os.path.isfile(filename):
            raise Exception, i18n("No file selected")

        Other = KPlato.openDocument("Other", filename)
        if Other is None:
            self.forms.showMessageBox("Sorry", i18n("Error"), i18n("Could not open document: %1", [filename]))
            return
        otherproj = Other.project()
        if otherproj is None:
            self.forms.showMessageBox("Sorry", i18n("Error"), i18n("No project to import from"))
            return
        if project.id() == otherproj.id():
            self.forms.showMessageBox("Sorry", i18n("Error"), i18n("Project identities are identical"))
            return

        for ci in range( otherproj.calendarCount() ):
            self.doImportCalendar( project, otherproj.calendarAt( ci ) )
        #TODO Default calendar

        for gi in range( otherproj.resourceGroupCount() ):
            othergroup = otherproj.resourceGroupAt( gi )
            gr = project.findResourceGroup( othergroup.id() )
            if gr is None:
                gr = project.createResourceGroup( othergroup )
                if gr is None:
                    self.forms.showMessageBox("Sorry", i18n("Error"), i18n("Unable to create copy of resource group: %1", [othergroup.name()]))
                    return
            for ri in range( othergroup.resourceCount() ):
                otherresource = othergroup.resourceAt( ri )
                if otherresource is None:
                    self.forms.showMessageBox("Sorry", i18n("Error"), i18n("No resource to copy from"))
                    return
                self.doImportResource( project, gr, otherresource )
예제 #6
0
def printNode(node, props, schedule, types=None):
    if types is None or node.type() in types:
        for prop in props:
            print "%-25s" % (KPlato.data(node, prop[0], prop[1], schedule)),
        print
        print dir(node)
    else:
        print "missing: ", node.type(), dir(node)
예제 #7
0
 def doImportResource( self, project, group, resource ):
     r = project.findResource( resource.id() )
     if r is None:
         r = project.createResource( group, resource )
         if r is None:
             raise Exception, i18n("Unable to create copy of resource: %1", [resource.name()])
     else:
         #TODO update?
         print "Resource already exists: %s %s" % ( r.id(), KPlato.data( r, 'ResourceName' ) )
예제 #8
0
 def doImportResource( self, project, group, resource ):
     r = project.findResource( resource.id() )
     if r is None:
         r = project.createResource( group, resource )
         if r is None:
             self.forms.showMessageBox("Sorry", i18n("Error"), i18n("Unable to create copy of resource: %1", [resource.name()]))
             return
     else:
         #TODO update?
         print "Resource already exists: %s %s" % ( r.id(), KPlato.data( r, 'ResourceName' ) )
예제 #9
0
 def check(self, project):
     lst = []
     for i in range(project.resourceGroupCount()):
         g = project.resourceGroupAt(i)
         for ri in range(g.resourceCount()):
             r = g.resourceAt(ri)
             lst = r.externalAppointments()
             for iv in lst:
                 iv.insert(0, r.id())
                 iv.insert(1, KPlato.data(r, "ResourceName"))
             print lst
예제 #10
0
    def doExport( self, project ):
        filename = self.savewidget.selectedFile()
        if not filename:
            raise Exception, i18n("No file selected")
        schId = self.scheduleview.currentSchedule()
        if schId == -1:
            raise Exception, i18n("No schedule selected")
        file = open( filename, 'w' )
        p = []
        p.append( project.id() )
        p.append( KPlato.data( project, 'NodeName' ) )
        pickle.dump( p, file )
        for i in range( project.resourceGroupCount() ):
            g = project.resourceGroupAt( i )
            for ri in range( g.resourceCount() ):
                r = g.resourceAt( ri )
                lst = r.appointmentIntervals( schId )
                for iv in lst:
                    iv.insert( 0, r.id() )
                    iv.insert( 1, KPlato.data( r, 'ResourceName' ) )
                    pickle.dump( iv, file )

        file.close()
예제 #11
0
    def __init__(self, scriptaction,cli=False):
        self.scriptaction = scriptaction
        self.currentpath = self.scriptaction.currentPath()

        self.cli=cli

        self.forms = Kross.module("forms")

        if not self.cli:
            # launched from inside KPlato
            self.proj = KPlato.project()
        else:
            # launched as a standalone script...
            print("opening doc...")
            filename=self.showImportDialog()
            KPlato.document().openUrl(filename)
            print( filename)
            self.proj=KPlato.project()
        
        self.dialog = self.forms.createDialog(i18n("Busy Information Export"))
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        datapage = self.dialog.addPage(i18n("Schedules"),i18n("Export Selected Schedule"),"document-export")
        self.scheduleview = KPlato.createScheduleListView(datapage)
        
        savepage = self.dialog.addPage(i18n("Save"),i18n("Export Busy Info File"),"document-save")
        self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kplatobusyinfoexportsave")
        self.savewidget.setMode("Saving")
        self.savewidget.setFilter("*.ics|%(1)s\n*|%(2)s" % { '1' : i18n("Calendar"), '2' : i18n("All Files") } )

        if self.dialog.exec_loop():
            try:
                self.doExport( self.proj )
            except:
                self.forms.showMessageBox("Error", i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
예제 #12
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        self.currentpath = self.scriptaction.currentPath()

        self.proj = KPlato.project()
        
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog(i18n("Project Information Export"))
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        datapage = self.dialog.addPage(i18n("Schedules"),i18n("Export Selected Schedule"),"document-export")
        self.scheduleview = KPlato.createScheduleListView(datapage)
        
        savepage = self.dialog.addPage(i18n("Save"),i18n("Export Project Info File"),"document-save")
        self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kplatoprojinfoexportsave")
        self.savewidget.setMode("Saving")
        self.savewidget.setFilter("*.txt|%(1)s\n*|%(2)s" % { '1' : i18n("Text Files"), '2' : i18n("All Files") } )

        if self.dialog.exec_loop():
            try:
                self.doExport( self.proj )
            except:
                self.forms.showMessageBox("Error", i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
예제 #13
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        self.currentpath = self.scriptaction.currentPath()

        self.proj = KPlato.project()
        
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog(i18n("Busy Information Import"))
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        openpage = self.dialog.addPage(i18n("Open"),i18n("Import Busy Info File"),"document-open")
        self.openwidget = self.forms.createFileWidget(openpage, "kfiledialog:///kplatobusyinfoimportopen")
        self.openwidget.setMode("Opening")
        self.openwidget.setFilter("*.rbi|%(1)s\n*|%(2)s" % { '1' : i18n("Resource Busy Information"), '2' : i18n("All Files") } )

        if self.dialog.exec_loop():
            try:
                self.doImport( self.proj )
            except:
                self.forms.showMessageBox("Error", i18n("Error"), "%s" % "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
예제 #14
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction

        self.proj = KPlato.project()
        
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog(i18n("Resources Import"))
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        #TODO add options page ( import Calendars? Select calendars, Select resources... )
        
        openpage = self.dialog.addPage(i18n("Open"),i18n("KPlato Resources"),"document-open")
        self.openwidget = self.forms.createFileWidget(openpage, "kfiledialog:///kplatresourcesimportopen")
        self.openwidget.setMode("Opening")
        self.openwidget.setFilter("*.kplato|%(1)s\n*|%(2)s" % { '1' : i18n("Resource Busy Information"), '2' : i18n("All Files") } )

        if self.dialog.exec_loop():
            try:
                self.doImport( self.proj )
            except Exception, inst:
                self.forms.showMessageBox("Sorry", i18n("Error"), "%s" % inst)
            except:
예제 #15
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

import os, datetime, sys, traceback, pickle
import Kross, KPlato

#TODO some ui
KPlato.project().clearAllExternalAppointments();

예제 #16
0
def printResource( resource, props ):
    for prop in props:
        print "%-25s" % ( KPlato.data( resource, prop ) ),
    print
예제 #17
0
def printGroup( group, props ):
    for prop in props:
        print "%-25s" % ( KPlato.data( group, prop ) ),
    print
    for i in range( group.resourceCount() ):
        printResource( group.resourceAt( i ), props )
예제 #18
0
def printNode( node, props, schedule, types = None ):
    if types is None or node.type() in types:
        for prop in props:
            print "%-25s" % ( KPlato.data( node, prop[0], prop[1], schedule ) ),
        print
예제 #19
0
def printBusyinfo( res, lst ):
    name = KPlato.data( res, 'ResourceName' )
    for interval in lst:
        print "%-20s %-30s %-30s %8s" % ( name, interval[0], interval[1], interval[2] )
        name = ""
예제 #20
0
    for interval in lst:
        print "%-20s %-30s %-30s %8s" % ( name, interval[0], interval[1], interval[2] )
        name = ""

def printProjectCalendars( proj ):
    for c in range( proj.calendarCount() ):
        printChildCalendars( proj.calendarAt ( c ) )

def printChildCalendars( calendar ):
    print calendar.name()
    for c in range( calendar.childCount() ):
        printChildCalendars( calendar.childAt ( c ) )


#------------------------
proj = KPlato.project()

sid = -1;
# get a schedule id
if proj.scheduleCount() > 0:
    sid = proj.scheduleAt( 0 ).id()

print "Using schedule id: %-3s" % ( sid )
print

nodeprops = [['NodeWBSCode', 'DisplayRole'], ['NodeName', 'DisplayRole'], ['NodeType', 'DisplayRole'], ['NodeResponsible', 'DisplayRole'], ['NodeStatus', 'EditRole'] ]
print "Print tasks and milestones in arbitrary order:"
# print the localized headers
for prop in nodeprops:
    print "%-25s" % (proj.nodeHeaderData( prop ) ),
print
예제 #21
0
 def __init__(self, scriptaction):
     proj = KPlato.project()
     self.check(proj)
예제 #22
0
def printNode( node, props, types = None ):
    if types is None or node.type() in types:
        for prop in props:
            print "%-25s" % ( KPlato.data( node, prop ) ),
        print
예제 #23
0
def printSchedule(sch):
    print "%-10s %-25s %-10s" % (sch.id(), sch.name(), sch.isScheduled())
    print "sch ( %s )" % ";".join(dir(sch))
    print sch.appointments()
    for i in range(sch.childCount()):
        printSchedule(sch.childAt(i))


forms = Kross.module("forms")
print "forms: ", dir(forms)

for mn in dir(KPlato):
    m = getattr(KPlato, mn)
    print mn, "===>", m.__doc__

KPlato.document().openUrl("/home/dimon/work/python/koffice-scripts/kplato/test_project.kplato")
project = KPlato.project()

print dir(KPlato.data)

sid = -1
# get a schedule id
if project.scheduleCount() > 0:
    sched = project.scheduleAt(0)
    sid = sched.id()
    print "appointments?? : ", KPlato.data(sched, "m_appointments")

print project.id(), KPlato.data(project, "NodeName")

printSchedules(project)
예제 #24
0
 def printNode( node, props, schedule, types = None ):
     s=''
     if types is None or node.type() in types:
         for prop in props:
             s=s+"%-25s" % ( KPlato.data( node, prop[0], prop[1], schedule ) )
     return s