org-taskjuggler.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. ;;; org-taskjuggler.el --- TaskJuggler exporter for org-mode
  2. ;;
  3. ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
  4. ;;
  5. ;; Emacs Lisp Archive Entry
  6. ;; Filename: org-taskjuggler.el
  7. ;; Version: 6.34trans
  8. ;; Author: Christian Egli
  9. ;; Maintainer: Christian Egli
  10. ;; Keywords: org, taskjuggler, project planning
  11. ;; Description: Converts an org-mode buffer into a taskjuggler project plan
  12. ;; URL:
  13. ;; This file is part of GNU Emacs.
  14. ;; GNU Emacs is free software: you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation, either version 3 of the License, or
  17. ;; (at your option) any later version.
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  24. ;; Commentary:
  25. ;;
  26. ;; This library implements a TaskJuggler exporter for org-mode. It is
  27. ;; a bit different from other exporters, such as the HTML and LaTeX
  28. ;; exporters for example, in that it does not export all the nodes of
  29. ;; a document or strictly follow the order of the nodes in the
  30. ;; document.
  31. ;;
  32. ;; Instead the TaskJuggler exporter looks for a tree that defines the
  33. ;; tasks and a optionally tree that defines the resources for this
  34. ;; project. It then creates a TaskJuggler file based on these trees
  35. ;; and the attributes defined in all the nodes.
  36. ;;
  37. ;; * Installation
  38. ;;
  39. ;; Put this file into your load-path and the following line into your
  40. ;; ~/.emacs:
  41. ;;
  42. ;; (require 'org-taskjuggler)
  43. ;;
  44. ;; The interactive functions are similar to those of the HTML and LaTeX
  45. ;; exporters:
  46. ;;
  47. ;; M-x `org-export-as-taskjuggler'
  48. ;; M-x `org-export-as-taskjuggler-and-open'
  49. ;;
  50. ;; * Tasks
  51. ;;
  52. ;; Let's illustrate this with a small example. Create your tasks as
  53. ;; you usually do. Assign efforts to each task using properties (it's
  54. ;; easiest to do this in the column view). You should end up with
  55. ;; something similar to the example by Peter Jones in
  56. ;; http://www.contextualdevelopment.com/static/artifacts/articles/2008/project-planning/project-planning.org.
  57. ;; Now mark the top node of your tasks with a tag named
  58. ;; "taskjuggler_project" (or whatever you customized
  59. ;; `org-export-taskjuggler-project-tag' to). You are now ready to
  60. ;; export the project plan with `org-export-as-taskjuggler-and-open'
  61. ;; which will export the project plan and open a gant chart in
  62. ;; TaskJugglerUI.
  63. ;;
  64. ;; * Resources
  65. ;;
  66. ;; Next you can define resources and assign these to work on specific
  67. ;; tasks. You can group your resources hierarchically. Tag the top
  68. ;; node of the resources with "taskjuggler_resource" (or whatever you
  69. ;; customized `org-export-taskjuggler-resource-tag' to). You can
  70. ;; optionally assign an ID to the resources (using the standard org
  71. ;; properties commands) or you can let the exporter generate IDs
  72. ;; automatically (the exporter picks the first word of the headline as
  73. ;; the ID as long as it is unique). Using that ID you can then
  74. ;; allocate resources to tasks. This is again done with the "allocate"
  75. ;; property on the tasks. Do this in column view or when on the task
  76. ;; type
  77. ;;
  78. ;; C-c C-x p allocate RET <ID> RET
  79. ;;
  80. ;; Once the allocations are done you can again export to TaskJuggler
  81. ;; and check in the Resource Allocation Graph which person is working
  82. ;; on what task at what time.
  83. ;;
  84. ;; * Export of properties
  85. ;;
  86. ;; The exporter also takes TODO state information into consideration,
  87. ;; i.e. if a task is marked as done it will have the corresponding
  88. ;; attribute in TaskJuggler (complete 100). Also it will export any
  89. ;; property on a task resource or resource node which is known to
  90. ;; TaskJuggler, such as limits, vacation, shift, booking, efficiency,
  91. ;; journalentry, rate for resources or account, start, note, duration,
  92. ;; end, journalentry, milestone, reference, responsible, scheduling,
  93. ;; etc for tasks.
  94. ;;
  95. ;; * Dependecies
  96. ;;
  97. ;; The exporter will handle dependencies that are defined in the tasks
  98. ;; either with the ORDERED attribute (see TODO dependencies in the Org
  99. ;; mode manual) or with the BLOCKER attribute (see org-depend.el) or
  100. ;; alternatively with a depends attribute. Both the BLOCKER and the
  101. ;; depends attribute can be either "previous-sibling" or a reference
  102. ;; to an ID which is defined for another task in the project.
  103. ;;
  104. ;; * TODO
  105. ;; - Look at org-file-properties, org-global-properties and org-global-properties-fixed
  106. ;; - What about property inheritance and org-property-inherit-p?
  107. ;; - Use TYPE_TODO as an way to assign resources
  108. ;; - Make sure multiple dependency definitions (i.e. BLOCKER on
  109. ;; previous-sibling and on a specific ID) in multiple attributes are properly exported.
  110. ;;
  111. ;;; Code:
  112. (eval-when-compile
  113. (require 'cl))
  114. (require 'org)
  115. (require 'org-exp)
  116. ;;; User variables:
  117. (defgroup org-export-taskjuggler nil
  118. "Options for exporting Org-mode files to TaskJuggler."
  119. :tag "Org Export TaskJuggler"
  120. :group 'org-export)
  121. (defcustom org-export-taskjuggler-extension ".tjp"
  122. "Extension of TaskJuggler files."
  123. :group 'org-export-taskjuggler
  124. :type 'string)
  125. (defcustom org-export-taskjuggler-project-tag "taskjuggler_project"
  126. "Tag, property or todo used to find the tree containing all
  127. the tasks for the project."
  128. :group 'org-export-taskjuggler
  129. :type 'string)
  130. (defcustom org-export-taskjuggler-resource-tag "taskjuggler_resource"
  131. "Tag, property or todo used to find the tree containing all the
  132. resources for the project."
  133. :group 'org-export-taskjuggler
  134. :type 'string)
  135. (defcustom org-export-taskjuggler-default-project-version "1.0"
  136. "Default version string for the project."
  137. :group 'org-export-taskjuggler
  138. :type 'string)
  139. (defcustom org-export-taskjuggler-default-project-duration 180
  140. "Default project duration if no start and end date have been defined
  141. in the root node of the task tree, i.e. the tree that has been marked
  142. with `org-export-taskjuggler-project-tag'"
  143. :group 'org-export-taskjuggler
  144. :type 'integer)
  145. (defcustom org-export-taskjuggler-default-reports
  146. '("taskreport \"Gantt Chart\" {
  147. headline \"Project Gantt Chart\"
  148. columns hierarchindex, name, start, end, effort, duration, completed, chart
  149. timeformat \"%Y-%m-%d\"
  150. hideresource 1
  151. loadunit shortauto
  152. }"
  153. "resourcereport \"Resource Graph\" {
  154. headline \"Resource Allocation Graph\"
  155. columns no, name, utilization, freeload, chart
  156. loadunit shortauto
  157. sorttasks startup
  158. hidetask ~isleaf()
  159. }")
  160. "Default reports for the project."
  161. :group 'org-export-taskjuggler
  162. :type '(repeat (string :tag "Report")))
  163. (defcustom org-export-taskjuggler-default-global-properties
  164. "shift s40 \"Part time shift\" {
  165. workinghours wed, thu, fri off
  166. }
  167. "
  168. "Default global properties for the project. Here you typically
  169. define global properties such as shifts, accounts, rates,
  170. vacation, macros and flags. Any property that is allowed within
  171. the TaskJuggler file can be inserted. You could for example
  172. include another TaskJuggler file.
  173. The global properties are inserted after the project declaration
  174. but before any resource and task declarations."
  175. :group 'org-export-taskjuggler
  176. :type '(string :tag "Preamble"))
  177. ;;; Hooks
  178. (defvar org-export-taskjuggler-final-hook nil
  179. "Hook run at the end of TaskJuggler export, in the new buffer.")
  180. ;;; Autoload functions:
  181. ;;;###autoload
  182. (defun org-export-as-taskjuggler ()
  183. "Export parts of the current buffer as a TaskJuggler file.
  184. The exporter looks for a tree with tag, property or todo that
  185. matches `org-export-taskjuggler-project-tag' and takes this as
  186. the tasks for this project. The first node of this tree defines
  187. the project properties such as project name and project period.
  188. If there is a tree with tag, property or todo that matches
  189. `org-export-taskjuggler-resource-tag' this three is taken as
  190. resources for the project. If no resources are specified, a
  191. default resource is created and allocated to the project. Also
  192. the taskjuggler project will be created with default reports as
  193. defined in `org-export-taskjuggler-default-reports'."
  194. (interactive)
  195. (message "Exporting...")
  196. (setq-default org-done-keywords org-done-keywords)
  197. (let* ((tasks
  198. (org-taskjuggler-resolve-dependencies
  199. (org-taskjuggler-assign-task-ids
  200. (org-map-entries '(org-taskjuggler-components)
  201. org-export-taskjuggler-project-tag nil 'archive 'comment))))
  202. (resources
  203. (org-taskjuggler-assign-resource-ids
  204. (org-map-entries '(org-taskjuggler-components)
  205. org-export-taskjuggler-resource-tag nil 'archive 'comment)))
  206. (filename (expand-file-name
  207. (concat
  208. (file-name-sans-extension
  209. (file-name-nondirectory buffer-file-name))
  210. org-export-taskjuggler-extension)))
  211. (buffer (find-file-noselect filename))
  212. (old-level 0)
  213. task resource)
  214. ;; add a default resource
  215. (unless resources
  216. (setq resources
  217. `((("ID" . ,(user-login-name))
  218. ("headline" . ,user-full-name)
  219. ("level" . 1)))))
  220. ;; add a default allocation to the first task if none was given
  221. (unless (assoc "allocate" (car tasks))
  222. (let ((task (car tasks))
  223. (resource-id (cdr (assoc "ID" (car resources)))))
  224. (setcar tasks (push (cons "allocate" resource-id) task))))
  225. ;; add a default start date to the first task if none was given
  226. (unless (assoc "start" (car tasks))
  227. (let ((task (car tasks))
  228. (time-string (format-time-string "%Y-%m-%d")))
  229. (setcar tasks (push (cons "start" time-string) task))))
  230. ;; add a default version if none was given
  231. (unless (assoc "version" (car tasks))
  232. (let ((task (car tasks))
  233. (version org-export-taskjuggler-default-project-version))
  234. (setcar tasks (push (cons "version" version) task))))
  235. (with-current-buffer buffer
  236. (erase-buffer)
  237. (org-taskjuggler-open-project (car tasks))
  238. (insert org-export-taskjuggler-default-global-properties)
  239. (insert "\n")
  240. (dolist (resource resources)
  241. (let ((level (cdr (assoc "level" resource))))
  242. (org-taskjuggler-close-maybe level)
  243. (org-taskjuggler-open-resource resource)
  244. (setq old-level level)))
  245. (org-taskjuggler-close-maybe 1)
  246. (setq old-level 0)
  247. (dolist (task tasks)
  248. (let ((level (cdr (assoc "level" task))))
  249. (org-taskjuggler-close-maybe level)
  250. (org-taskjuggler-open-task task)
  251. (setq old-level level)))
  252. (org-taskjuggler-close-maybe 1)
  253. (org-taskjuggler-insert-reports)
  254. (save-buffer)
  255. (or (org-export-push-to-kill-ring "TaskJuggler")
  256. (message "Exporting... done"))
  257. (current-buffer))))
  258. ;;;###autoload
  259. (defun org-export-as-taskjuggler-and-open ()
  260. "Export the current buffer as a TaskJuggler file and open it with the TaskJuggler GUI."
  261. (interactive)
  262. (let ((file-name (buffer-file-name (org-export-as-taskjuggler)))
  263. (command "TaskJugglerUI"))
  264. (start-process-shell-command command nil command file-name)))
  265. (defun org-taskjuggler-parent-is-ordered-p ()
  266. "Return true if the parent of the current node has a property
  267. \"ORDERED\". Return nil otherwise."
  268. (save-excursion
  269. (and (org-up-heading-safe) (org-entry-get (point) "ORDERED"))))
  270. (defun org-taskjuggler-components ()
  271. "Return an alist containing all the pertinent information for
  272. the current node such as the headline, the level, todo state
  273. information, all the properties, etc."
  274. (let* ((props (org-entry-properties))
  275. (components (org-heading-components))
  276. (level (car components))
  277. (headline (nth 4 components))
  278. (parent-ordered (org-taskjuggler-parent-is-ordered-p)))
  279. (push (cons "level" level) props)
  280. (push (cons "headline" headline) props)
  281. (push (cons "parent-ordered" parent-ordered) props)))
  282. (defun org-taskjuggler-assign-task-ids (tasks)
  283. "Given a list of tasks return the same list assigning a unique id
  284. and the full path to each task. Taskjuggler takes hierarchical ids.
  285. For that reason we have to make ids locally unique and we have to keep
  286. a path to the current task."
  287. (let ((previous-level 0)
  288. unique-ids unique-id
  289. path
  290. task resolved-tasks tmp)
  291. (dolist (task tasks resolved-tasks)
  292. (let ((level (cdr (assoc "level" task))))
  293. (cond
  294. ((< previous-level level)
  295. (setq unique-id (org-taskjuggler-get-unique-id task (car unique-ids)))
  296. (dotimes (tmp (- level previous-level))
  297. (push (list unique-id) unique-ids)
  298. (push unique-id path)))
  299. ((= previous-level level)
  300. (setq unique-id (org-taskjuggler-get-unique-id task (car unique-ids)))
  301. (push unique-id (car unique-ids))
  302. (setcar path unique-id))
  303. ((> previous-level level)
  304. (dotimes (tmp (- previous-level level))
  305. (pop unique-ids)
  306. (pop path))
  307. (setq unique-id (org-taskjuggler-get-unique-id task (car unique-ids)))
  308. (push unique-id (car unique-ids))
  309. (setcar path unique-id)))
  310. (push (cons "unique-id" unique-id) task)
  311. (push (cons "path" (mapconcat 'identity (reverse path) ".")) task)
  312. (setq previous-level level)
  313. (setq resolved-tasks (append resolved-tasks (list task)))))))
  314. (defun org-taskjuggler-assign-resource-ids (resources &optional unique-ids)
  315. "Given a list of resources return the same list, assigning a
  316. unique id to each resource."
  317. (cond
  318. ((null resources) nil)
  319. (t
  320. (let* ((resource (car resources))
  321. (unique-id (org-taskjuggler-get-unique-id resource unique-ids)))
  322. (push (cons "unique-id" unique-id) resource)
  323. (cons resource (org-taskjuggler-assign-resource-ids (cdr resources)
  324. (cons unique-id unique-ids)))))))
  325. (defun org-taskjuggler-resolve-dependencies (tasks)
  326. (let ((previous-level 0)
  327. siblings
  328. task resolved-tasks)
  329. (dolist (task tasks resolved-tasks)
  330. (let* ((level (cdr (assoc "level" task)))
  331. (depends (cdr (assoc "depends" task)))
  332. (parent-ordered (cdr (assoc "parent-ordered" task)))
  333. (blocker (cdr (assoc "BLOCKER" task)))
  334. (blocked-on-previous (and blocker (string-match "previous-sibling" blocker)))
  335. (dependencies
  336. (org-taskjuggler-resolve-explicit-dependencies
  337. (append
  338. (and depends (split-string depends "[, \f\t\n\r\v]+" t))
  339. (and blocker (split-string blocker "[, \f\t\n\r\v]+" t))) tasks))
  340. previous-sibling)
  341. ; update previous sibling info
  342. (cond
  343. ((< previous-level level)
  344. (dotimes (tmp (- level previous-level))
  345. (push task siblings)))
  346. ((= previous-level level)
  347. (setq previous-sibling (car siblings))
  348. (setcar siblings task))
  349. ((> previous-level level)
  350. (dotimes (tmp (- previous-level level))
  351. (pop siblings))
  352. (setq previous-sibling (car siblings))
  353. (setcar siblings task)))
  354. ; insert a dependency on previous sibling if the parent is
  355. ; ordered or if the tasks has a BLOCKER attribute with value "previous-sibling"
  356. (when (or (and previous-sibling parent-ordered) blocked-on-previous)
  357. (push (format "!%s" (cdr (assoc "unique-id" previous-sibling))) dependencies))
  358. ; store dependency information
  359. (when dependencies
  360. (push (cons "depends" (mapconcat 'identity dependencies ", ")) task))
  361. (setq previous-level level)
  362. (setq resolved-tasks (append resolved-tasks (list task)))))))
  363. (defun org-taskjuggler-resolve-explicit-dependencies (dependencies tasks)
  364. (let (path)
  365. (cond
  366. ((null dependencies) nil)
  367. ; ignore previous sibling dependencies
  368. ((equal (car dependencies) "previous-sibling")
  369. (org-taskjuggler-resolve-explicit-dependencies (cdr dependencies) tasks))
  370. ; if the id is found in another task use its path
  371. ((setq path (org-taskjuggler-find-task-with-id (car dependencies) tasks))
  372. (cons path (org-taskjuggler-resolve-explicit-dependencies (cdr dependencies) tasks)))
  373. ; silently ignore all other dependencies
  374. (t (org-taskjuggler-resolve-explicit-dependencies (cdr dependencies) tasks)))))
  375. (defun org-taskjuggler-find-task-with-id (id tasks)
  376. "Find ID in tasks. If found return the path of task. Otherwise return nil."
  377. (let ((task-id (cdr (assoc "ID" (car tasks))))
  378. (path (cdr (assoc "path" (car tasks)))))
  379. (cond
  380. ((null tasks) nil)
  381. ((equal task-id id) path)
  382. (t (org-taskjuggler-find-task-with-id id (cdr tasks))))))
  383. (defun org-taskjuggler-get-unique-id (item unique-ids)
  384. "Return a unique id for an ITEM which can be a task or a resource.
  385. The id is derived from the headline and made unique against
  386. UNIQUE-IDS. If the first part of the headline is not unique try to add
  387. more parts of the headline or finally add more underscore characters (\"_\")."
  388. (let* ((headline (cdr (assoc "headline" item)))
  389. (parts (split-string headline))
  390. (id (org-taskjuggler-clean-id (downcase (pop parts)))))
  391. ; try to add more parts of the headline to make it unique
  392. (while (member id unique-ids)
  393. (setq id (concat id "_" (org-taskjuggler-clean-id (downcase (pop parts))))))
  394. ; if its still not unique add "_"
  395. (while (member id unique-ids)
  396. (setq id (concat id "_")))
  397. id))
  398. (defun org-taskjuggler-clean-id (id)
  399. "Clean and return ID to make it acceptable for taskjuggler."
  400. (and id (replace-regexp-in-string "[^a-zA-Z0-9_]" "_" id)))
  401. (defun org-taskjuggler-open-project (project)
  402. "Insert a the beginning of project declaration. All valid
  403. attributes from the PROJECT alist are inserted. If no end date is
  404. specified it is calculated
  405. `org-export-taskjuggler-default-project-duration' days from now."
  406. (let* ((unique-id (cdr (assoc "unique-id" project)))
  407. (headline (cdr (assoc "headline" project)))
  408. (version (cdr (assoc "version" project)))
  409. (start (cdr (assoc "start" project)))
  410. (end (cdr (assoc "end" project))))
  411. (insert
  412. (format "project %s \"%s\" \"%s\" %s +%sd {\n }\n"
  413. unique-id headline version start
  414. org-export-taskjuggler-default-project-duration))))
  415. (defun org-taskjuggler-filter-and-join (items)
  416. "Filter all nil elements from ITEMS and join the remaining ones
  417. with separator \"\n\"."
  418. (let ((filtered-items (remq nil items)))
  419. (and filtered-items (mapconcat 'identity filtered-items "\n"))))
  420. (defun org-taskjuggler-get-attributes (item attributes)
  421. "Return all attribute as a single formated string. ITEM is an alist
  422. representing either a resource or a task. ATTRIBUTES is a list of
  423. symbols. Only entries from ITEM are considered that are listed in
  424. ATTRIBUTES."
  425. (org-taskjuggler-filter-and-join
  426. (mapcar
  427. (lambda (attribute)
  428. (org-taskjuggler-filter-and-join
  429. (org-taskjuggler-get-attribute item attribute)))
  430. attributes)))
  431. (defun org-taskjuggler-get-attribute (item attribute)
  432. "Return a list of strings containing the properly formatted
  433. taskjuggler declaration for a given ATTRIBUTE in ITEM (an alist).
  434. If the ATTRIBUTE is not in ITEM return nil."
  435. (cond
  436. ((null item) nil)
  437. ((equal (symbol-name attribute) (car (car item)))
  438. (cons (format "%s %s" (symbol-name attribute) (cdr (car item)))
  439. (org-taskjuggler-get-attribute (cdr item) attribute)))
  440. (t (org-taskjuggler-get-attribute (cdr item) attribute))))
  441. (defun org-taskjuggler-open-resource (resource)
  442. (let ((id (org-taskjuggler-clean-id (cdr (assoc "ID" resource))))
  443. (unique-id (org-taskjuggler-clean-id (cdr (assoc "unique-id" resource))))
  444. (headline (cdr (assoc "headline" resource)))
  445. (attributes '(limits vacation shift booking efficiency journalentry rate)))
  446. (insert
  447. (concat
  448. "resource " (or id unique-id) " \"" headline "\" {\n "
  449. (org-taskjuggler-get-attributes resource attributes) "\n"))))
  450. (defun org-taskjuggler-clean-effort (effort)
  451. "Translate effort strings into a format acceptable to taskjuggler,
  452. i.e. REAL UNIT. If the effort string is something like 5:30 it
  453. will be assumed to be hours and will be translated into 5.5h.
  454. Otherwise if it contains something like 3.0 it is assumed to be
  455. days and will be translated into 3.0d. Other formats that taskjuggler
  456. supports (like weeks, months and years) are currently not supported."
  457. (cond
  458. ((null effort) effort)
  459. ((string-match "\\([0-9]+\\):\\([0-9]+\\)" effort)
  460. (let ((hours (string-to-number (match-string 1 effort)))
  461. (minutes (string-to-number (match-string 2 effort))))
  462. (format "%dh" (+ hours (/ minutes 60.0)))))
  463. ((string-match "\\([0-9]+\\).\\([0-9]+\\)" effort) (concat effort "d"))
  464. (t (error "Not a valid effort (%s)" effort))))
  465. (defun org-taskjuggler-get-priority (priority)
  466. "Return a priority between 1 and 1000 based on PRIORITY, an
  467. org-mode priority string."
  468. (max 1 (/ (* 1000 (- org-lowest-priority (string-to-char priority)))
  469. (- org-lowest-priority org-highest-priority))))
  470. (defun org-taskjuggler-open-task (task)
  471. (let* ((unique-id (cdr (assoc "unique-id" task)))
  472. (headline (cdr (assoc "headline" task)))
  473. (effort (org-taskjuggler-clean-effort (cdr (assoc org-effort-property task))))
  474. (depends (cdr (assoc "depends" task)))
  475. (allocate (cdr (assoc "allocate" task)))
  476. (priority-raw (cdr (assoc "PRIORITY" task)))
  477. (priority (and priority-raw (org-taskjuggler-get-priority priority-raw)))
  478. (state (cdr (assoc "TODO" task)))
  479. (complete (or (and (member state org-done-keywords) "100")
  480. (cdr (assoc "complete" task))))
  481. (parent-ordered (cdr (assoc "parent-ordered" task)))
  482. (previous-sibling (cdr (assoc "previous-sibling" task)))
  483. (attributes
  484. '(account start note duration endbuffer endcredit end
  485. flags journalentry, length maxend maxstart milestone
  486. minend minstart period reference responsible
  487. scheduling startbuffer startcredit statusnote)))
  488. (insert
  489. (concat
  490. "task " unique-id " \"" headline "\" {\n"
  491. (if (and parent-ordered previous-sibling)
  492. (format " depends %s\n" previous-sibling)
  493. (and depends (format " depends %s\n" depends)))
  494. (and allocate (format " purge allocations\n allocate %s\n" allocate))
  495. (and complete (format " complete %s\n" complete))
  496. (and effort (format " effort %s\n" effort))
  497. (and priority (format " priority %s\n" priority))
  498. (org-taskjuggler-get-attributes task attributes)
  499. "\n"))))
  500. (defun org-taskjuggler-close-maybe (level)
  501. (while (> old-level level)
  502. (insert "}\n")
  503. (setq old-level (1- old-level)))
  504. (when (= old-level level)
  505. (insert "}\n")))
  506. (defun org-taskjuggler-insert-reports ()
  507. (let (report)
  508. (dolist (report org-export-taskjuggler-default-reports)
  509. (insert report "\n"))))
  510. (provide 'org-taskjuggler)
  511. ;;; org-taskjuggler.el ends here