-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathupdate_archive.py
More file actions
48 lines (41 loc) · 1.36 KB
/
update_archive.py
File metadata and controls
48 lines (41 loc) · 1.36 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
"""
Adds a twanager command to upgrade the current store so that each space gains an
*_archive bag
"""
from tiddlyweb.commands import make_command
from tiddlyweb.model.bag import Bag
from tiddlyweb.store import NoBagError
from tiddlywebplugins.utils import get_store
@make_command()
def add_archive(args):
"""add archive bags to the store: twanager add_archive"""
store = get_store(config)
bags = store.list_bags()
for bag in bags:
if bag.name.endswith('_private'):
space_name = bag.name.rsplit('_', 1)[0]
archive = Bag('%s_archive' % space_name)
try:
archive = store.get(archive)
except NoBagError:
archive.policy = bag.policy
store.put(archive)
@make_command()
def update_archive(args):
"""update archive bags to have the right perms"""
store = get_store(config)
bags = store.list_bags()
for bag in bags:
if bag.name.endswith('_archive'):
space_name = bag.name.rsplit('_', 1)[0]
private = Bag('%s_private' % space_name)
private = store.get(private)
try:
archive = store.get(bag)
archive.policy = private.policy
store.put(archive)
except NoBagError:
pass
def init(config_in):
global config
config = config_in