github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

emilerl / emilerl

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: b08e8fa

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Site — Read more

  cancel

http://emilerl.github.com

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added the TaskPaper Python API 
emilerl (author)
Tue Jun 02 13:06:53 -0700 2009
commit  b08e8fa8b9d6b6eae0dbc6a51a81e97e72a65f1a
tree    6b0fa2883921347c62390f1160817c8529200cb7
parent  12951e41d2dd485efc72aee1f69371dc5d3cd0d8
emilerl / TaskPaper / taskpaper.py TaskPaper/taskpaper.py
100644 160 lines (121 sloc) 4.156 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python
# encoding: utf-8
"""
taskpaper.py
 
Created by Emil on 2009-06-02.
Copyright (c) 2009 Emil Erlandsson
 
This program 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.
 
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
"""
 
import sys
import os
 
class TaskPaperProject(object):
  """Representing a project in a TaskPaper file"""
  def __init__(self, line):
    self.line = line
    self.name = ""
    self.tasks = []
    self.notes = []
    self.__parse()
  
  def __parse(self):
    """Parses the line and sets up variables"""
    self.name = self.line[:-1]
   
  def add_note(self, note):
    """Adds a note to this project"""
    self.notes.append(note)
    
  def add_task(self, task):
    """Adds a task to this project"""
    self.tasks.append(task)
                          
                          
class TaskPaperTask(object):
  """Represents a task in a taskpaper"""
  def __init__(self, line):
    self.line = line
    self.tags = []
    self.project = None
    self.name = ""
    self.notes = []
    self.__parse()
  
  def __parse(self):
    """Parses the line and sets up variables"""
    tokens = self.line.replace("- ", "").split("@")
    self.name = tokens[0]
    self.tags = tokens[1:]
  
  def set_project(self, project):
    self.project = project
 
  def add_note(self, note):
    """Adds a note to this project"""
    self.notes.append(note)
    
  def add_tag(self, tag):
    self.tags.append(tag)
  
 
class TaskPaper(object):
  """A wrapper class for TaskPaper files"""
  def __init__(self, filename):
    self.filename = filename
    self.projects = []
    self.tasks = []
 
  def add_task(self, task):
    """Adds a no-parent task to this task paper"""
    self.tasks.append(task)
  
  def add_project(self, project):
    """Adds a project to the taskpaper"""
    self.projects.append(project)
 
  def __str__(self):
    return "TaskPaper with %d headless tasks and %d projects" \
    % (len(self.tasks), len(self.projects))
    
  def print_entries(self):
    """Prints all entries in the task paper"""
    
    print "Taskpaper: %s" % self.filename
    
    for project in self.projects:
      print "\n%s:" % project.name
      for note in project.notes:
        print note
        
      for task in project.tasks:
        rep = "- %s" % task.name.strip()
        for tag in task.tags:
          rep += " @%s" % tag.strip()
        print rep
        for note in task.notes:
          print "%s" % note
    print "\n\n"
    
  def print_stats(self):
    tasks = len(self.tasks)
    notes = 0
    
    for project in self.projects:
      tasks += len(project.tasks)
      notes += len(project.notes)
      for task in project.tasks:
        notes += len(task.notes)
    
    print "%s has: %d projects with %d tasks and %d notes." \
    % (self.filename, len(self.projects), tasks, notes)
    
 
 
def parse_task_paper(filename):
  """Parsing of a TaskPaper file"""
  handle = file(filename)
  
  taskpaper = TaskPaper(filename)
  project = None
  last = None
  for line in handle.readlines():
    line = unicode(line.strip(), "utf-8")
    
    if line.startswith("- "): # It is a task
      task = TaskPaperTask(line)
      last = task
      if project is not None:
        project.add_task(task)
        task.project = project
        
    elif line.endswith(":"): # It is a project
      project = TaskPaperProject(line)
      taskpaper.add_project(project)
      last = project
      
    else: # It is a note
      last.add_note(line)
  
  return taskpaper
    
 
if __name__ == '__main__':
  tp = parse_task_paper(sys.argv[1])
  tp.print_entries()
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server