-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlabgen-module-init-guide
59 lines (50 loc) · 1.63 KB
/
mlabgen-module-init-guide
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
#! /usr/bin/python3
import mlabgen
import qrcode
from os.path import basename, isdir
from os import mkdir
import os
from shutil import copyfile
from sys import argv
import json
if ("-h" in argv) or (len(argv) < 2):
print("usage: mlabgen-module-init [-h] [MODULE] [TEMPLATE optional]")
exit()
module = argv[1]
root = os.getcwd()
try: mkdir(argv[1])
except FileExistsError: pass
try: template = argv[2]
except IndexError: template = "/usr/share/mlabgen/module"
for item in mlabgen.lspath(template):
if isdir(item):
try: mkdir(item[item.find("module"):].replace("module", module))
except FileExistsError: pass
else:
copyfile(item, item[item.find("module"):].replace("module", module))
try:
qr = qrcode.QRCode( version=4, error_correction=qrcode.constants.ERROR_CORRECT_Q, box_size=15, border=4)
qr.add_data('https://www.mlab.cz/PermaLink/'+module)
qr.make(fit=True)
qr.make_image().save(module+"/doc/img/"+module+'_QRcode.png')
except Exception as e: print(e)
data = {
'wiki': "None",
'status': 1,
'name': module,
'longname_en': '%s module'%(module),
'longname_cs': 'Modul %s'%(module),
'short_en': '%s module'%(module),
'short_cs': 'Modul %s'%(module),
'image': "/doc/img/"+module+'_QRcode.png',
'autor[]': [],
'parameters': [],
'ust': 'None',
'doc_cs':"",
'doc_en':"",
'category[]':[],
'root': root[root.find('/Modules')+9:],
}
print (module+'/%s.json' %(module))
with open(module+'/%s.json' %(module), 'w') as outfile:
json.dump(data, outfile, sort_keys=True, indent=4)