-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdokuwikiBildIndex.py
More file actions
executable file
·132 lines (118 loc) · 4.57 KB
/
dokuwikiBildIndex.py
File metadata and controls
executable file
·132 lines (118 loc) · 4.57 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" write a DokuWike Page with Pictureinfos """
import os
import sys
import argparse
class Pictodokuwiki(object):
def __init__(self, wikipath, picturepath):
"""
Example:
central = 084-koebenerstr-gruenewald:bilddokumentation:0084-2013-04-09-begehung:'
picturepath = './'
"""
self.central = wikipath
if self.isdir(picturepath):
self.dirlist = os.listdir(picturepath)
self.picsize = '500'
def isdir(self, path):
"""
Test if Path is Directory
"""
if os.path.isdir(path):
return True
else:
print("[Error] No such file or directory: %s ( -h --help )" %path)
quit()
def get_imgdict(self):
"""
iterates nextlevel directorys and collects
the inhereted Imagefilenames in a dict.
dict-key is = dirname
"""
fileinf = {}
for element in self.dirlist:
path = './' + element + '/'
if os.path.isdir(path):
fileinf[element] = os.listdir(path)
return fileinf
def write_alldir_to_wikipicturelists(self):
"""
creates separate DokuWikePages for every
Directory as a List of images for Textdokumantation
"""
fileinf = self.get_imgdict()
for key in fileinf.keys():
filepath = './' + key + '.txt'
datei = open(filepath, 'w')
path = './' + key + '/'
header = '^ Datum | ' + key + ' |'
print(header, file=datei)
print('', file=datei)
for element in fileinf[key]:
text = '| {{:' + self.central + element + '?' + self.picsize + '|}} |'
text2 = ' | | '
print(text, file=datei)
print(text2, file=datei)
datei.close()
def write_dir_to_wikipicturelist(self, dirname):
"""
creates DokuWikePage for given Directory
as a List of images for Textdokumantation
"""
info = False
fileinf = self.get_imgdict()
for key in fileinf.keys():
if key == dirname:
info = True
filepath = './' + key + '.txt'
datei = open(filepath, 'w')
path = './' + key + '/'
header = '^ Datum | ' + key + ' |'
print(header, file=datei)
print('', file=datei)
for element in fileinf[key]:
text = '| {{:' + self.central + element + '?' + self.picsize + '|}} |'
text2 = '| | '
print(text, file=datei)
print(text2, file=datei)
datei.close()
if not info:
text = "There is no Directory: " + dirname
print(text)
def main():
# some Options on Toolstart
parser = argparse.ArgumentParser()
parser.add_argument("-wp", "--wikipath=",
dest="wikipath",
help= "Example '084-koebenerstr-gruenewald:bilddokumentation:0084-2013-04-09-begehung:'",
default= "",)
parser.add_argument("-pp", "--picturepath",
dest="picturepath",
help="Example './' ",
default= './',)
parser.add_argument("-d", "--directory",
dest="dirname",
help="Example '2013-05-06'",
default= "Nothing-to-dir",)
parser.add_argument("-a", "--alldirectory",
dest="alldirectory",
help="include all following Directorys from --directory",
action = 'store_true',)
# parse the options
args = parser.parse_args()
# get option infos
wikipath = args.wikipath
picturepath = args.picturepath
dirname = args.dirname
# instantiate Pictodokuwiki and include two Parameters
PicHelper = Pictodokuwiki(wikipath, picturepath)
if args.alldirectory:
PicHelper.write_alldir_to_wikipicturelists()
elif args.dirname != "Nothing-to-dir":
# write one DokuWikipage to given parameters
PicHelper.write_dir_to_wikipicturelist(dirname)
else:
print(" Error less Parameter.... use --help or -h")
if __name__ == "__main__":
main()