-
Notifications
You must be signed in to change notification settings - Fork 0
/
Folder.py
52 lines (47 loc) · 1.22 KB
/
Folder.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pretty print
import pprint
pp = pprint.PrettyPrinter(indent=2)
import Bookmark
def getDepth(item):
if 'depth' in item:
return item['depth']
return ''
def getPath(item):
if 'path' in item:
return item['path']
return ''
def getChildren(item):
if 'children' in item:
return item['children']
return ''
def collect_list(parent, current):
# このフォルダのパスと子供一覧をリストに追加
children = Bookmark.gatherUrlOrHash(current)
folder = {
'depth': getDepth(parent),
'path': getPath(parent),
'children': children
}
outlist = [folder]
# 子フォルダから再帰的にパスと子供一覧を集める
child_list = filter(Bookmark.isFolder, Bookmark.getChildren(current))
def collect_child(child):
newPath = getPath(parent) + '/' + Bookmark.getTitle(child)
child_folder = {
'depth': getDepth(parent) + 1,
'path': newPath
}
children = collect_list(child_folder, child)
outlist.extend(children)
map(collect_child, child_list)
return outlist
def collect(root):
# フォルダの一覧を得る
folder = {
'depth': 0,
'path': ''
}
list = collect_list(folder, root)
return list