forked from CodethinkLabs/mustard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith-mustard
More file actions
executable file
·83 lines (64 loc) · 2.22 KB
/
with-mustard
File metadata and controls
executable file
·83 lines (64 loc) · 2.22 KB
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
#!/usr/bin/python
# -*- Python -*-
#
# Copyright (C) 2012-2013 Codethink Limited
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import code
import readline
import sys
import mustard
class Thingy(object):
pass
state_id = "UNCOMMITTED"
raw_tree_cache = mustard.rawtree.Cache()
element_tree_cache = mustard.elementtree.Cache(raw_tree_cache)
thingy = Thingy()
thingy.base_url = "http://localhost:8080/"
repository = mustard.repository.Repository(thingy, ".")
state_cache = mustard.state.Cache(thingy, repository)
state = state_cache.get(state_id)
raw_tree = mustard.rawtree.Tree(state)
element_tree = mustard.elementtree.Tree(raw_tree)
elt = element_tree
def fst(l):
return [f for (f,s) in l]
def snd(l):
return [s for (f,s) in l]
d = dict
s = set
def path(node):
revmap = dict([(v,k) for (k,v) in elt.elements.items()])
return revmap.get(node, None)
def has_todo(elt):
return "TODO" in elt.description
def showall(elts):
if type(elts) == dict:
elts = elts.itervalues()
mapping = {}
for elt in elts:
mapping[path(elt)] = elt.title
keys = mapping.keys()
keys.sort()
for k in keys:
print "%s : %s" % (k, mapping[k])
namespace = globals().copy()
namespace.update(locals())
code.InteractiveConsole(namespace).interact("""
The variable `elt' is the Mustard element tree.
Useful listish operations include 'fst' which given a list of tuples, returns a
list of the first element of the tuples, and 'snd' which does the same with the
second elements. 'd' is a short alias for 'dict' and 's' for 'set'. 'showall'
is a function which takes a collection of elements and lists them.
""")