2010-03-16 05:11:52 -04:00
|
|
|
;;; org-taskjuggler.el --- TaskJuggler exporter for org-mode
|
|
|
|
;;
|
|
|
|
;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
|
|
|
;;
|
|
|
|
;; Emacs Lisp Archive Entry
|
|
|
|
;; Filename: org-taskjuggler.el
|
|
|
|
;; Version: 6.34trans
|
|
|
|
;; Author: Christian Egli
|
|
|
|
;; Maintainer: Christian Egli
|
|
|
|
;; Keywords: org, taskjuggler, project planning
|
|
|
|
;; Description: Converts an org-mode buffer into a taskjuggler project plan
|
|
|
|
;; URL:
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This library implements a TaskJuggler exporter for org-mode.
|
|
|
|
;;
|
|
|
|
;; The interactive functions are similar to those of the HTML and LaTeX
|
|
|
|
;; exporters:
|
|
|
|
;;
|
|
|
|
;; M-x `org-export-as-taskjuggler'
|
|
|
|
;; M-x `org-export-as-taskjuggler-and-open'
|
|
|
|
;;
|
2010-03-17 11:36:36 -04:00
|
|
|
;;; TODO:
|
|
|
|
;; * Code cleanup
|
|
|
|
;; * Add documentation
|
|
|
|
;; * Try using plists instead of alists
|
|
|
|
;;
|
2010-03-16 05:11:52 -04:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(eval-when-compile
|
|
|
|
(require 'cl))
|
|
|
|
|
|
|
|
(require 'org)
|
|
|
|
(require 'org-exp)
|
|
|
|
|
|
|
|
;;; User variables:
|
|
|
|
|
|
|
|
(defgroup org-export-taskjuggler nil
|
|
|
|
"Options for exporting Org-mode files to TaskJuggler."
|
|
|
|
:tag "Org Export TaskJuggler"
|
|
|
|
:group 'org-export)
|
|
|
|
|
|
|
|
(defcustom org-export-taskjuggler-extension ".tjp"
|
|
|
|
"Extension of TaskJuggler files."
|
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type 'string)
|
|
|
|
|
|
|
|
(defcustom org-export-taskjuggler-project-tag "project"
|
2010-03-18 05:07:38 -04:00
|
|
|
"Tag, property or todo used to find the tree containing all
|
|
|
|
the tasks for the project."
|
2010-03-16 05:11:52 -04:00
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type 'string)
|
|
|
|
|
|
|
|
(defcustom org-export-taskjuggler-resource-tag "resource"
|
2010-03-18 05:07:38 -04:00
|
|
|
"Tag, property or todo used to find the tree containing all the
|
|
|
|
resources for the project."
|
2010-03-16 05:11:52 -04:00
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type 'string)
|
|
|
|
|
|
|
|
(defcustom org-export-taskjuggler-default-project-version "1.0"
|
2010-03-18 05:07:38 -04:00
|
|
|
"Default version string for the project."
|
2010-03-16 05:11:52 -04:00
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type 'string)
|
|
|
|
|
2010-03-16 09:14:24 -04:00
|
|
|
(defcustom org-export-taskjuggler-default-project-duration 180
|
2010-03-18 05:07:38 -04:00
|
|
|
"Default project duration if no start and end date have been defined
|
|
|
|
in the root node of the task tree, i.e. the tree that has been marked
|
|
|
|
with `org-export-taskjuggler-project-tag'"
|
2010-03-16 05:11:52 -04:00
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type 'integer)
|
|
|
|
|
2010-03-16 09:14:24 -04:00
|
|
|
(defcustom org-export-taskjuggler-default-reports
|
|
|
|
'("taskreport \"Gantt Chart\" {
|
|
|
|
headline \"Project Gantt Chart\"
|
|
|
|
columns hierarchindex, name, start, end, effort, duration, completed, chart
|
2010-03-19 09:46:37 -04:00
|
|
|
timeformat \"%Y-%m-%d\"
|
|
|
|
hideresource 1
|
2010-03-16 09:14:24 -04:00
|
|
|
loadunit days
|
|
|
|
}"
|
|
|
|
"resourcereport \"Resource Graph\" {
|
|
|
|
headline \"Resource Allocation Graph\"
|
2010-03-19 09:46:37 -04:00
|
|
|
columns no, name, utilization, freeload, chart
|
2010-03-16 09:14:24 -04:00
|
|
|
loadunit days
|
2010-03-19 12:12:22 -04:00
|
|
|
sorttasks startup
|
|
|
|
hidetask ~isleaf()
|
2010-03-16 09:14:24 -04:00
|
|
|
}")
|
2010-03-18 05:07:38 -04:00
|
|
|
"Default reports for the project."
|
2010-03-16 09:14:24 -04:00
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type '(repeat (string :tag "Report")))
|
|
|
|
|
2010-03-22 12:27:53 -04:00
|
|
|
(defcustom org-export-taskjuggler-default-global-properties
|
|
|
|
"shift s40 \"Part time shift\" {
|
|
|
|
workinghours wed, thu, fri off
|
|
|
|
}
|
|
|
|
"
|
|
|
|
"Default global properties for the project. Here you typically
|
|
|
|
define global properties such as shifts, accounts, rates,
|
|
|
|
vacation, macros and flags. Any property that is allowed within
|
|
|
|
the TaskJuggler file can be inserted. You could for example
|
|
|
|
include another TaskJuggler file.
|
|
|
|
|
|
|
|
The global properties are inserted after the project declaration
|
|
|
|
but before any resource and task declarations."
|
|
|
|
:group 'org-export-taskjuggler
|
|
|
|
:type '(string :tag "Preamble"))
|
|
|
|
|
2010-03-16 05:11:52 -04:00
|
|
|
;;; Hooks
|
|
|
|
|
|
|
|
(defvar org-export-taskjuggler-final-hook nil
|
|
|
|
"Hook run at the end of TaskJuggler export, in the new buffer.")
|
|
|
|
|
|
|
|
;;; Autoload functions:
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-export-as-taskjuggler ()
|
2010-03-18 05:07:38 -04:00
|
|
|
"Export parts of the current buffer as a TaskJuggler file.
|
|
|
|
The exporter looks for a tree with tag, property or todo that
|
|
|
|
matches `org-export-taskjuggler-project-tag' and takes this as
|
|
|
|
the tasks for this project. The first node of this tree defines
|
|
|
|
the project properties such as project name and project period.
|
|
|
|
If there is a tree with tag, property or todo that matches
|
|
|
|
`org-export-taskjuggler-resource-tag' this three is taken as
|
|
|
|
resources for the project. If no resources are specified, a
|
|
|
|
default resource is created and allocated to the project. Also
|
|
|
|
the taskjuggler project will be created with default reports as
|
|
|
|
defined in `org-export-taskjuggler-default-reports'."
|
2010-03-16 05:11:52 -04:00
|
|
|
(interactive)
|
|
|
|
|
|
|
|
(message "Exporting...")
|
2010-03-17 12:05:28 -04:00
|
|
|
(setq-default org-done-keywords org-done-keywords)
|
2010-03-16 05:11:52 -04:00
|
|
|
(let* ((tasks
|
2010-03-17 09:13:03 -04:00
|
|
|
(org-taskjuggler-resolve-dependencies
|
2010-03-17 10:44:54 -04:00
|
|
|
(org-taskjuggler-assign-task-ids
|
2010-03-17 09:13:03 -04:00
|
|
|
(org-map-entries '(org-taskjuggler-components)
|
|
|
|
org-export-taskjuggler-project-tag nil 'archive 'comment))))
|
2010-03-16 05:11:52 -04:00
|
|
|
(resources
|
2010-03-17 10:44:54 -04:00
|
|
|
(org-taskjuggler-assign-resource-ids
|
|
|
|
(org-map-entries '(org-taskjuggler-components)
|
|
|
|
org-export-taskjuggler-resource-tag nil 'archive 'comment)))
|
2010-03-16 05:11:52 -04:00
|
|
|
(filename (expand-file-name
|
|
|
|
(concat
|
|
|
|
(file-name-sans-extension
|
|
|
|
(file-name-nondirectory buffer-file-name))
|
|
|
|
org-export-taskjuggler-extension)))
|
|
|
|
(buffer (find-file-noselect filename))
|
|
|
|
(old-level 0)
|
|
|
|
task resource)
|
|
|
|
;; add a default resource
|
|
|
|
(unless resources
|
|
|
|
(setq resources
|
|
|
|
`((("ID" . ,(user-login-name))
|
|
|
|
("headline" . ,user-full-name)
|
|
|
|
("level" . 1)))))
|
2010-03-16 05:27:37 -04:00
|
|
|
;; add a default allocation to the first task if none was given
|
2010-03-16 05:11:52 -04:00
|
|
|
(unless (assoc "allocate" (car tasks))
|
2010-03-16 05:27:37 -04:00
|
|
|
(let ((task (car tasks))
|
|
|
|
(resource-id (cdr (assoc "ID" (car resources)))))
|
|
|
|
(setcar tasks (push (cons "allocate" resource-id) task))))
|
2010-03-16 05:11:52 -04:00
|
|
|
;; add a default start date to the first task if none was given
|
|
|
|
(unless (assoc "start" (car tasks))
|
|
|
|
(let ((task (car tasks))
|
|
|
|
(time-string (format-time-string "%Y-%m-%d")))
|
|
|
|
(setcar tasks (push (cons "start" time-string) task))))
|
|
|
|
;; add a default version if none was given
|
|
|
|
(unless (assoc "version" (car tasks))
|
|
|
|
(let ((task (car tasks))
|
|
|
|
(version org-export-taskjuggler-default-project-version))
|
|
|
|
(setcar tasks (push (cons "version" version) task))))
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(erase-buffer)
|
|
|
|
(org-taskjuggler-open-project (car tasks))
|
2010-03-22 12:27:53 -04:00
|
|
|
(insert org-export-taskjuggler-default-global-properties)
|
2010-03-16 09:14:24 -04:00
|
|
|
(dolist (resource resources)
|
2010-03-16 05:11:52 -04:00
|
|
|
(let ((level (cdr (assoc "level" resource))))
|
|
|
|
(org-taskjuggler-close-maybe level)
|
|
|
|
(org-taskjuggler-open-resource resource)
|
|
|
|
(setq old-level level)))
|
|
|
|
(org-taskjuggler-close-maybe 1)
|
|
|
|
(setq old-level 0)
|
2010-03-16 09:14:24 -04:00
|
|
|
(dolist (task tasks)
|
2010-03-16 05:11:52 -04:00
|
|
|
(let ((level (cdr (assoc "level" task))))
|
|
|
|
(org-taskjuggler-close-maybe level)
|
|
|
|
(org-taskjuggler-open-task task)
|
|
|
|
(setq old-level level)))
|
2010-03-16 09:14:24 -04:00
|
|
|
(org-taskjuggler-close-maybe 1)
|
2010-03-16 09:41:24 -04:00
|
|
|
(org-taskjuggler-insert-reports)
|
|
|
|
(save-buffer)
|
|
|
|
(or (org-export-push-to-kill-ring "TaskJuggler")
|
|
|
|
(message "Exporting... done"))
|
|
|
|
(current-buffer))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-export-as-taskjuggler-and-open ()
|
|
|
|
"Export the current buffer as a TaskJuggler file and open it with the TaskJuggler GUI."
|
|
|
|
(interactive)
|
|
|
|
(let ((file-name (buffer-file-name (org-export-as-taskjuggler)))
|
|
|
|
(command "TaskJugglerUI"))
|
|
|
|
(start-process-shell-command command nil command file-name)))
|
2010-03-16 05:11:52 -04:00
|
|
|
|
2010-03-17 09:13:03 -04:00
|
|
|
(defun org-taskjuggler-parent-is-ordered-p ()
|
2010-03-18 05:22:49 -04:00
|
|
|
"Return true if the parent of the current node has a property
|
|
|
|
\"ORDERED\". Return nil otherwise."
|
2010-03-17 09:13:03 -04:00
|
|
|
(save-excursion
|
|
|
|
(and (org-up-heading-safe) (org-entry-get (point) "ORDERED"))))
|
|
|
|
|
2010-03-16 05:11:52 -04:00
|
|
|
(defun org-taskjuggler-components ()
|
2010-03-18 05:22:49 -04:00
|
|
|
"Return an alist containing all the pertinent information for
|
|
|
|
the current node such as the headline, the level, todo state
|
|
|
|
information, all the properties, etc."
|
2010-03-16 05:11:52 -04:00
|
|
|
(let* ((props (org-entry-properties))
|
|
|
|
(components (org-heading-components))
|
|
|
|
(level (car components))
|
2010-03-17 09:13:03 -04:00
|
|
|
(headline (nth 4 components))
|
|
|
|
(parent-ordered (org-taskjuggler-parent-is-ordered-p)))
|
2010-03-16 05:11:52 -04:00
|
|
|
(push (cons "level" level) props)
|
2010-03-17 09:13:03 -04:00
|
|
|
(push (cons "headline" headline) props)
|
|
|
|
(push (cons "parent-ordered" parent-ordered) props)))
|
|
|
|
|
2010-03-17 10:44:54 -04:00
|
|
|
(defun org-taskjuggler-assign-task-ids (tasks)
|
2010-03-18 05:22:49 -04:00
|
|
|
"Given a list of tasks return the same list assigning a unique id
|
|
|
|
and the full path to each task. Taskjuggler takes hierarchical ids.
|
|
|
|
For that reason we have to make ids locally unique and we have to keep
|
|
|
|
a path to the current task."
|
2010-03-17 09:13:03 -04:00
|
|
|
(let ((previous-level 0)
|
2010-03-22 12:27:53 -04:00
|
|
|
unique-ids unique-id
|
2010-03-17 09:13:03 -04:00
|
|
|
path
|
|
|
|
task resolved-tasks tmp)
|
|
|
|
(dolist (task tasks resolved-tasks)
|
2010-03-17 10:02:01 -04:00
|
|
|
(let ((level (cdr (assoc "level" task))))
|
2010-03-17 09:13:03 -04:00
|
|
|
(cond
|
|
|
|
((< previous-level level)
|
2010-03-17 10:02:01 -04:00
|
|
|
(setq unique-id (org-taskjuggler-get-unique-id task (car unique-ids)))
|
2010-03-17 09:13:03 -04:00
|
|
|
(dotimes (tmp (- level previous-level))
|
|
|
|
(push (list unique-id) unique-ids)
|
|
|
|
(push unique-id path)))
|
|
|
|
((= previous-level level)
|
2010-03-17 10:02:01 -04:00
|
|
|
(setq unique-id (org-taskjuggler-get-unique-id task (car unique-ids)))
|
2010-03-18 17:22:30 -04:00
|
|
|
(push unique-id (car unique-ids))
|
|
|
|
(setcar path unique-id))
|
2010-03-17 09:13:03 -04:00
|
|
|
((> previous-level level)
|
|
|
|
(dotimes (tmp (- previous-level level))
|
|
|
|
(pop unique-ids)
|
2010-03-17 10:02:01 -04:00
|
|
|
(pop path))
|
2010-03-17 11:36:36 -04:00
|
|
|
(setq unique-id (org-taskjuggler-get-unique-id task (car unique-ids)))
|
2010-03-19 12:13:17 -04:00
|
|
|
(push unique-id (car unique-ids))
|
|
|
|
(setcar path unique-id)))
|
2010-03-17 09:13:03 -04:00
|
|
|
(push (cons "unique-id" unique-id) task)
|
|
|
|
(push (cons "path" (mapconcat 'identity (reverse path) ".")) task)
|
|
|
|
(setq previous-level level)
|
|
|
|
(setq resolved-tasks (append resolved-tasks (list task)))))))
|
|
|
|
|
2010-03-19 12:35:33 -04:00
|
|
|
(defun org-taskjuggler-assign-resource-ids (resources &optional unique-ids)
|
2010-03-18 05:22:49 -04:00
|
|
|
"Given a list of resources return the same list, assigning a
|
|
|
|
unique id to each resource."
|
2010-03-19 12:35:33 -04:00
|
|
|
(cond
|
|
|
|
((null resources) nil)
|
|
|
|
(t
|
|
|
|
(let* ((resource (car resources))
|
|
|
|
(unique-id (org-taskjuggler-get-unique-id resource unique-ids)))
|
2010-03-17 10:44:54 -04:00
|
|
|
(push (cons "unique-id" unique-id) resource)
|
2010-03-19 12:35:33 -04:00
|
|
|
(cons resource (org-taskjuggler-assign-resource-ids (cdr resources)
|
|
|
|
(cons unique-id unique-ids)))))))
|
2010-03-17 10:44:54 -04:00
|
|
|
|
2010-03-17 09:13:03 -04:00
|
|
|
(defun org-taskjuggler-resolve-dependencies (tasks)
|
|
|
|
(let ((previous-level 0)
|
|
|
|
siblings
|
|
|
|
task resolved-tasks)
|
|
|
|
(dolist (task tasks resolved-tasks)
|
2010-03-18 17:22:30 -04:00
|
|
|
(let* ((level (cdr (assoc "level" task)))
|
|
|
|
(depends (cdr (assoc "depends" task)))
|
|
|
|
(parent-ordered (cdr (assoc "parent-ordered" task)))
|
|
|
|
(blocker (cdr (assoc "BLOCKER" task)))
|
|
|
|
(blocked-on-previous (and blocker (string-match "previous-sibling" blocker)))
|
|
|
|
(dependencies
|
|
|
|
(org-taskjuggler-resolve-explicit-dependencies
|
|
|
|
(append
|
|
|
|
(and depends (split-string depends "[, \f\t\n\r\v]+" t))
|
|
|
|
(and blocker (split-string blocker "[, \f\t\n\r\v]+" t))) tasks))
|
|
|
|
previous-sibling)
|
|
|
|
; update previous sibling info
|
2010-03-17 09:13:03 -04:00
|
|
|
(cond
|
|
|
|
((< previous-level level)
|
|
|
|
(dotimes (tmp (- level previous-level))
|
|
|
|
(push task siblings)))
|
|
|
|
((= previous-level level)
|
|
|
|
(setq previous-sibling (car siblings))
|
|
|
|
(setcar siblings task))
|
|
|
|
((> previous-level level)
|
|
|
|
(dotimes (tmp (- previous-level level))
|
|
|
|
(pop siblings))
|
|
|
|
(setq previous-sibling (car siblings))
|
|
|
|
(setcar siblings task)))
|
2010-03-18 17:22:30 -04:00
|
|
|
; insert a dependency on previous sibling if the parent is
|
|
|
|
; ordered or if the tasks has a BLOCKER attribute with value "previous-sibling"
|
|
|
|
(when (or (and previous-sibling parent-ordered) blocked-on-previous)
|
|
|
|
(push (format "!%s" (cdr (assoc "unique-id" previous-sibling))) dependencies))
|
|
|
|
; store dependency information
|
|
|
|
(when dependencies
|
|
|
|
(push (cons "depends" (mapconcat 'identity dependencies ", ")) task))
|
2010-03-17 09:13:03 -04:00
|
|
|
(setq previous-level level)
|
|
|
|
(setq resolved-tasks (append resolved-tasks (list task)))))))
|
|
|
|
|
2010-03-18 17:22:30 -04:00
|
|
|
(defun org-taskjuggler-resolve-explicit-dependencies (dependencies tasks)
|
|
|
|
(let (path)
|
|
|
|
(cond
|
|
|
|
((null dependencies) nil)
|
|
|
|
; ignore previous sibling dependencies
|
|
|
|
((equal (car dependencies) "previous-sibling")
|
|
|
|
(org-taskjuggler-resolve-explicit-dependencies (cdr dependencies) tasks))
|
|
|
|
; if the id is found in another task use its path
|
|
|
|
((setq path (org-taskjuggler-find-task-with-id (car dependencies) tasks))
|
|
|
|
(cons path (org-taskjuggler-resolve-explicit-dependencies (cdr dependencies) tasks)))
|
|
|
|
; silently ignore all other dependencies
|
|
|
|
(t (org-taskjuggler-resolve-explicit-dependencies (cdr dependencies) tasks)))))
|
|
|
|
|
|
|
|
(defun org-taskjuggler-find-task-with-id (id tasks)
|
|
|
|
"Find ID in tasks. If found return the path of task. Otherwise return nil."
|
2010-03-19 12:35:33 -04:00
|
|
|
(let ((task-id (cdr (assoc "ID" (car tasks))))
|
|
|
|
(path (cdr (assoc "path" (car tasks)))))
|
|
|
|
(cond
|
|
|
|
((null tasks) nil)
|
|
|
|
((equal task-id id) path)
|
|
|
|
(t (org-taskjuggler-find-task-with-id id (cdr tasks))))))
|
2010-03-18 17:22:30 -04:00
|
|
|
|
2010-03-18 05:22:49 -04:00
|
|
|
(defun org-taskjuggler-get-unique-id (item unique-ids)
|
|
|
|
"Return a unique id for an ITEM which can be a task or a resource.
|
|
|
|
The id is derived from the headline and made unique against
|
|
|
|
UNIQUE-IDS. If the first part of the headline is not unique try to add
|
|
|
|
more parts of the headline or finally add more underscore characters (\"_\")."
|
|
|
|
(let* ((headline (cdr (assoc "headline" item)))
|
2010-03-17 09:13:03 -04:00
|
|
|
(parts (split-string headline))
|
2010-03-23 08:11:09 -04:00
|
|
|
(id (org-taskjuggler-clean-id (downcase (pop parts)))))
|
2010-03-17 09:13:03 -04:00
|
|
|
; try to add more parts of the headline to make it unique
|
|
|
|
(while (member id unique-ids)
|
2010-03-23 08:11:09 -04:00
|
|
|
(setq id (concat id "_" (org-taskjuggler-clean-id (downcase (pop parts))))))
|
2010-03-17 09:13:03 -04:00
|
|
|
; if its still not unique add "_"
|
|
|
|
(while (member id unique-ids)
|
|
|
|
(setq id (concat id "_")))
|
2010-03-23 08:11:09 -04:00
|
|
|
id))
|
2010-03-17 09:13:03 -04:00
|
|
|
|
2010-03-16 05:11:52 -04:00
|
|
|
(defun org-taskjuggler-clean-id (id)
|
2010-03-18 05:22:49 -04:00
|
|
|
"Clean and return ID to make it acceptable for taskjuggler."
|
2010-03-16 05:11:52 -04:00
|
|
|
(and id (replace-regexp-in-string "[^a-zA-Z0-9_]" "_" id)))
|
|
|
|
|
|
|
|
(defun org-taskjuggler-open-project (project)
|
2010-03-23 09:02:48 -04:00
|
|
|
"Insert a the beginning of project declaration. All valid
|
|
|
|
attributes from the PROJECT alist are inserted. If no end date is
|
|
|
|
specified it is calculated
|
|
|
|
`org-export-taskjuggler-default-project-duration' days from now."
|
|
|
|
(let* ((unique-id (cdr (assoc "unique-id" project)))
|
2010-03-16 05:11:52 -04:00
|
|
|
(headline (cdr (assoc "headline" project)))
|
|
|
|
(version (cdr (assoc "version" project)))
|
|
|
|
(start (cdr (assoc "start" project)))
|
2010-03-23 10:40:02 -04:00
|
|
|
(end (cdr (assoc "end" project))))
|
2010-03-16 05:11:52 -04:00
|
|
|
(insert
|
2010-03-23 10:40:02 -04:00
|
|
|
(format "project %s \"%s\" \"%s\" %s +%sd {\n }\n"
|
|
|
|
unique-id headline version start
|
|
|
|
org-export-taskjuggler-default-project-duration))))
|
2010-03-23 09:02:48 -04:00
|
|
|
|
|
|
|
(defun org-taskjuggler-get-attributes (item attributes)
|
|
|
|
"Return all attribute as a single formated string. ITEM is an alist
|
|
|
|
representing either a resource or a task. ATTRIBUTES is a list of
|
|
|
|
symbols. Only entries from ITEM are considered that are listed in
|
|
|
|
ATTRIBUTES."
|
|
|
|
(mapconcat
|
|
|
|
'identity
|
|
|
|
(remq
|
|
|
|
nil
|
|
|
|
(mapcar
|
|
|
|
(lambda (attribute)
|
|
|
|
(let ((value (cdr (assoc (symbol-name attribute) item))))
|
|
|
|
(and value
|
|
|
|
(if (equal attribute 'limits)
|
|
|
|
(format "%s { %s }" (symbol-name attribute) value)
|
|
|
|
(format "%s %s" (symbol-name attribute) value)))))
|
|
|
|
attributes)) "\n"))
|
2010-03-16 05:11:52 -04:00
|
|
|
|
|
|
|
(defun org-taskjuggler-open-resource (resource)
|
|
|
|
(let ((id (org-taskjuggler-clean-id (cdr (assoc "ID" resource))))
|
2010-03-17 10:44:54 -04:00
|
|
|
(unique-id (org-taskjuggler-clean-id (cdr (assoc "unique-id" resource))))
|
2010-03-17 11:01:23 -04:00
|
|
|
(headline (cdr (assoc "headline" resource)))
|
2010-03-23 06:09:10 -04:00
|
|
|
(attributes '(limits vacation shift booking efficiency journalentry rate)))
|
2010-03-16 05:11:52 -04:00
|
|
|
(insert
|
2010-03-23 06:09:10 -04:00
|
|
|
(concat
|
|
|
|
"resource " (or id unique-id) " \"" headline "\" {\n "
|
2010-03-23 09:02:48 -04:00
|
|
|
(org-taskjuggler-get-attributes resource attributes) "\n"))))
|
2010-03-16 05:11:52 -04:00
|
|
|
|
|
|
|
(defun org-taskjuggler-clean-effort (effort)
|
2010-03-18 05:07:38 -04:00
|
|
|
"Translate effort strings into a format acceptable to taskjuggler,
|
|
|
|
i.e. REAL UNIT. If the effort string is something like 5:00 it
|
|
|
|
will be assumed to be hours and will be translated into 5.0h.
|
|
|
|
Otherwise if it contains something like 3.0 it is assumed to be
|
|
|
|
days and will be translated into 3.0d. Other formats that taskjuggler
|
|
|
|
supports (like weeks, months and years) are currently not supported."
|
2010-03-16 05:11:52 -04:00
|
|
|
(cond
|
|
|
|
((null effort) effort)
|
|
|
|
((string-match "\\([0-9]+\\):\\([0-9]+\\)" effort)
|
2010-03-18 05:07:38 -04:00
|
|
|
; FIXME: translate the minutes to a decimal
|
2010-03-16 05:11:52 -04:00
|
|
|
(concat (match-string 1 effort) "." (match-string 2 effort) "h"))
|
|
|
|
((string-match "\\([0-9]+\\).\\([0-9]+\\)" effort) (concat effort "d"))
|
|
|
|
(t (error "Not a valid effort (%s)" effort))))
|
|
|
|
|
2010-03-23 10:40:52 -04:00
|
|
|
(defun org-taskjuggler-get-priority (priority)
|
|
|
|
"Return a priority between 1 and 1000 based on PRIORITY, an
|
|
|
|
org-mode priority string."
|
|
|
|
(max 1 (/ (* 1000 (- org-lowest-priority (string-to-char priority)))
|
|
|
|
(- org-lowest-priority org-highest-priority))))
|
|
|
|
|
2010-03-16 05:11:52 -04:00
|
|
|
(defun org-taskjuggler-open-task (task)
|
2010-03-17 12:05:28 -04:00
|
|
|
(let* ((unique-id (cdr (assoc "unique-id" task)))
|
2010-03-16 05:11:52 -04:00
|
|
|
(headline (cdr (assoc "headline" task)))
|
2010-03-16 05:35:29 -04:00
|
|
|
(effort (org-taskjuggler-clean-effort (cdr (assoc org-effort-property task))))
|
2010-03-16 05:11:52 -04:00
|
|
|
(depends (cdr (assoc "depends" task)))
|
|
|
|
(allocate (cdr (assoc "allocate" task)))
|
2010-03-23 10:40:52 -04:00
|
|
|
(priority-raw (cdr (assoc "PRIORITY" task)))
|
|
|
|
(priority (and priority-raw (org-taskjuggler-get-priority priority-raw)))
|
2010-03-17 12:05:28 -04:00
|
|
|
(state (cdr (assoc "TODO" task)))
|
|
|
|
(complete (or (and (member state org-done-keywords) "100")
|
|
|
|
(cdr (assoc "complete" task))))
|
2010-03-17 09:13:03 -04:00
|
|
|
(parent-ordered (cdr (assoc "parent-ordered" task)))
|
2010-03-23 09:02:48 -04:00
|
|
|
(previous-sibling (cdr (assoc "previous-sibling" task)))
|
|
|
|
(attributes
|
|
|
|
'(account start note duration endbuffer endcredit end
|
|
|
|
flags journalentry, length maxend maxstart milestone
|
|
|
|
minend minstart period reference responsible
|
|
|
|
scheduling startbuffer startcredit statusnote)))
|
2010-03-16 05:11:52 -04:00
|
|
|
(insert
|
|
|
|
(concat
|
2010-03-23 09:02:48 -04:00
|
|
|
"task " unique-id " \"" headline "\" {\n"
|
2010-03-17 09:13:03 -04:00
|
|
|
(if (and parent-ordered previous-sibling)
|
2010-03-23 09:02:48 -04:00
|
|
|
(format " depends %s\n" previous-sibling)
|
|
|
|
(and depends (format " depends %s\n" depends)))
|
|
|
|
(and allocate (format " purge allocations\n allocate %s\n" allocate))
|
|
|
|
(and complete (format " complete %s\n" complete))
|
|
|
|
(and effort (format " effort %s\n" effort))
|
|
|
|
(and priority (format " priority %s\n" priority))
|
|
|
|
|
|
|
|
(org-taskjuggler-get-attributes task attributes)
|
2010-03-16 05:11:52 -04:00
|
|
|
"\n"))))
|
|
|
|
|
|
|
|
(defun org-taskjuggler-close-maybe (level)
|
|
|
|
(while (> old-level level)
|
|
|
|
(insert "}\n")
|
|
|
|
(setq old-level (1- old-level)))
|
|
|
|
(when (= old-level level)
|
|
|
|
(insert "}\n")))
|
|
|
|
|
2010-03-16 09:14:24 -04:00
|
|
|
(defun org-taskjuggler-insert-reports ()
|
|
|
|
(let (report)
|
|
|
|
(dolist (report org-export-taskjuggler-default-reports)
|
|
|
|
(insert report "\n"))))
|
2010-03-16 05:11:52 -04:00
|
|
|
|
|
|
|
(provide 'org-taskjuggler)
|
|
|
|
|
|
|
|
;;; org-taskjuggler.el ends here
|