-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddBlock.py
53 lines (45 loc) · 1.24 KB
/
addBlock.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
53
from database import db
def convertToArray(s):
# function for converting a string to the array form
# speration is "_" or "__"
conv = []
if (len(s) == 0):
return [conv]
b = s.split(" ")
for i in b:
conv.append(i.split(" "))
return conv
def convertToDict(s):
# function to convert in the dict
# module for adding blocks for database
conv = dict()
if(len(s) == 0):
return conv
b = s.split(",")
c = []
for i in b:
c.append(i.split("="))
for j in c:
conv[j[0]] = j[1]
return conv
def addblock(blockName, args, ins, out, filePath):
args = convertToDict(args)
filePath = filePath.replace("\\", '/')
# python way to split the data
sect = filePath.split("/")
out = convertToArray(out)
# code change sigle array insted of multiple array
if(len(ins) != 0):
ins = ins.split(" ")
else:
ins = []
# explicit addition of / in the file path
block = {"blockName": blockName,
"args": args, "filePath": filePath, "out": out, "in": ins}
# Adding to database
c = db
for i in range(0, len(sect)-1):
c = c.child(sect[i])
c = c.child(blockName)
c.set(block)
return blockName