','')
fff = codecs.open(out+fil+'.e.svg', mode='w', encoding='utf-8')
fff.write(rawsvg2)
fff.close
header=""
try:
numlev=level[level.rfind('/')+1:]
numrest=level[:level.rfind('/')]
headingraw=rootdfd+numrest+'/'+numlev+'.title.txt'
with open(headingraw,'r') as hdraw:
headr=hdraw.read()
heading=headr.replace('\n',' ')
except:
header=''
with open(rootdfd+'title.txt','r') as hdraw:
headr=hdraw.read()
heading=headr.replace('\n',' ')
f = codecs.open(out+fil+'.txt', mode='w', encoding='utf-8')
tp='
'
tp+='
'
f.write(tp+rawsvg)
f.close
def createflow(path):
print(path)
labels={}
global hd
graph=[]
for root,dirs,files in os.walk(rootdfd+path+'/', followlinks=False):
for fname in files:
if not fname.startswith('.') and fname[-11:]!='details.txt':
p=os.path.join(root,fname)
bits=re.compile(re.escape(rootdfd+path+'/')+r'(.+)/(has_component_destination)/(.+)')
try:
m = bits.match(p)
subject=m.group(1)
predicate=m.group(2)
objctraw=m.group(3)
ttl=objctraw.find('title.txt')
if ttl==-1:
objct=objctraw[:-4]
objctp=objctraw
else:
objct=objctraw[:ttl-1]
objctp=objctraw
lbl=''
lblline=''
if os.path.isfile(rootdfd+path+'/'+subject+'/'+predicate+'/'+objct+'.details.txt') and fname.find('^^')==-1 and fname.find('_has_specified')==-1 and fname.find('_flow_destination')==-1:
with open(rootdfd+path+'/'+subject+'/'+predicate+'/'+objct+'.details.txt','r') as linelbl:
lblline=linelbl.read().replace('\n',' ')
else:
lblline=''
graph.append('"'+subject+'" -> "'+objct+'" [dir="none" color="#012312" label="'+lblline+'"];')
lbls=''
with open(rootdfd+path+'/'+subject+'.txt','r') as label:
for line in label:
lbls+=line.rstrip()+r'\n'
with open(rootdfd+path+'/'+objct+'.txt','r') as label:
for line in label:
lbl+=line.rstrip()+r'\n'
if subject[0]=='N':
labels[subject]='"'+subject+'" [shape="network" peripheries="0" fontcolor="#012312" label="'+lbls+'" ];'
if objct[0]=='N':
labels[objct]='"'+objct+'" [shape="network" peripheries="0" fontcolor="#012312" label="'+lbl+'" ];'
if subject[0]=='R':
labels[subject]='"'+subject+'" [shape="square" style="diagonals" fontcolor="#012312" label="'+lbls+'" ];'
if objct[0]=='R':
labels[objct]='"'+objct+'" [shape="square" style="diagonals" fontcolor="#012312" label="'+lbl+'" ];'
if subject[0]=='S':
labels[subject]='"'+subject+'" [shape="box", style=rounded fontcolor="#012312" label="'+lbls+'" ];'
if objct[0]=='S':
labels[objct]='"'+objct+'" [shape="box", style=rounded fontcolor="#012312" label="'+lbl+'" ];'
if subject[0]=='D':
labels[subject]='"'+subject+'" [shape="cylinder" fontcolor="#012312" label="'+lbls+'" ];'
if objct[0]=='D':
labels[objct]='"'+objct+'" [shape="cylinder" fontcolor="#012312" label="'+lbl+'" ];'
lbl=''
with open(rootdfd+path+'/'+subject+'.title.txt','r') as label:
for line in label:
lbl+=line.rstrip()+r'\n'
try:
with open(rootdfd+path+'/'+subject+'.details.txt','r') as linelbl:
lblline=linelbl.read().replace('\n',' ')
lbllinel='*'
except:
lblline=''
lbllinel=''
end=('tooltip="'+lblline+'"];')
labels[subject]='"'+subject+'" [fontcolor="#012312" label="{
'+lbllinel+' '+subject+'| '+lbl+'\n\n\n}" shape=Mrecord '+end
except:
six=9
alll=''
for line in labels:
alll+=labels[line]+'\n'
for line in graph:
alll+=line+'\n'
with open(out+path.replace('/','.')+'.gv', 'w+') as fa:
fa.write(diaghead+alll+'}'+'\n')
rendergv(path)
def update(evt):
proc=''
hass=evt.find('/has_component_destination')
if hass !=-1:
subject=evt[:hass].rfind('/')
createflow(evt[len(rootdfd):subject])
class changes(FileSystemEventHandler):
def on_modified(self, event):
update(event.src_path)
def on_created(self, event):
update(event.src_path)
if __name__ == "__main__":
event_handler = changes()
observer = Observer()
observer.schedule(event_handler, rootdfd, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()