File: generate_test_notebook.py

package info (click to toggle)
zim 0.62-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,660 kB
  • ctags: 6,996
  • sloc: python: 52,094; xml: 1,135; makefile: 45; sh: 36
file content (53 lines) | stat: -rwxr-xr-x 977 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/python

import sys
import os

if len(sys.argv) != 4:
	print 'Usage: %s directory with depth' % sys.argv[0]
	sys.exit(1)

root, width, depth = sys.argv[1:]
width = int(width)
depth = int(depth)

assert not os.path.exists(root), 'Need new directory'

name = 'some_page_%i_%i'
content = '''\
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.26

====== Some Page ======
//Some test data//

Foooo Bar!

TODO: insert random links here
'''
content += ('la la laaa'*20 + '\n') * 10

def populate_level(path, j):
    path += os.path.sep
    os.mkdir(path)
    d = 1
    
    for i in range(width):
        myname = name % (j, i)
        
        file = path + myname + '.txt'
        print '>', file
        fh = open(file, 'w')
        fh.write(content)
        fh.close()
        
        if j < depth:
            d += populate_level(path + myname, j+1)

    return d

d = populate_level(root, 0)
f = d * width

print 'Total %i files %i directories' % (f, d)
print 'Done'