-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlabgen-module-init
executable file
·61 lines (52 loc) · 1.69 KB
/
mlabgen-module-init
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
#! /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)
QRpath = module+"/doc/img/"+module+'_QRcode.png'
print("Saving QR to path:", QRpath)
qr.make_image().save(QRpath)
except Exception as e: print("QRerr> ",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)