]> Softwares of Agnibho - ddstorm.git/blob - ddstorm.py
First commit
[ddstorm.git] / ddstorm.py
1 #! /usr/bin/python3
2
3 # DDStorm
4 # -------
5 # Copyright (c) 2015 Agnibho Mondal
6 # All rights reserved
7
8 # This file is part of DDStorm.
9
10 # DDStorm is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # DDStorm is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
22
23 import sys, os
24 from compile import Compile
25 from conf import Conf
26 from index import Index
27
28 class DDStorm:
29 conf=False
30 def __init__(self, comp=False, conf=False):
31 if(conf):
32 self.conf=conf
33 else:
34 self.conf=Conf()
35 if(comp):
36 self.compiler=Compile(conf)
37 self.index=Index(conf)
38
39 def dd(self, symptoms):
40 if(not symptoms):
41 return
42 diff1=self._getDiff(symptoms.pop(0))
43 for s in symptoms:
44 diff2=self._getDiff(s)
45 temp=[]
46 if(len(diff1)>len(diff2)):
47 diff2+=[""]*(len(diff1)-len(diff2))
48 elif(len(diff2)>len(diff1)):
49 diff1+=[""]*(len(diff2)-len(diff1))
50 for (s1, s2) in zip(diff1, diff2):
51 if((s1 not in temp) and (len(s1)>0)):
52 if(s1 in diff2):
53 temp.append(s1)
54 else:
55 us=self.index.upstream(s1)
56 for i in us:
57 if(i in diff2):
58 temp.append(i)
59 if((s2 not in temp) and (len(s2)>0)):
60 if(s2 in diff1):
61 temp.append(s2)
62 else:
63 us=self.index.upstream(s2)
64 for i in us:
65 if(i in diff1):
66 temp.append(i)
67 diff1=list(temp)
68 return diff1
69
70 def _getDiff(self, symptom):
71 diff=[]
72 symptom=symptom.lower().replace("_"," ").replace("-", " ")
73 if(os.path.isfile(self.conf.get("module_path")+symptom+".module")):
74 with open(self.conf.get("module_path")+symptom+".module", "r") as mf:
75 for line in mf:
76 diff.append(line.strip())
77 return diff
78
79 def symptoms(self):
80 symp=[]
81 for n in os.listdir(self.conf.get("module_path")):
82 symp.append(os.path.splitext(os.path.basename(n))[0].capitalize())
83 return symp
84
85 def main():
86 s=DDStorm()
87 if(len(sys.argv)>1):
88 for d in s.dd(sys.argv[1:]):
89 print(d)
90 else:
91 for s in s.symptoms():
92 print(s)
93
94 if(__name__=="__main__"):
95 main()