X-Git-Url: https://code.agnibho.com/repo?a=blobdiff_plain;f=alias.py;fp=alias.py;h=a1b9d104e709ba92b3cff0b1eeb8c0a821ee7475;hb=717bb15e56a14b4d814054c5bd5d15a9b4c9e20f;hp=d4e013ee069bb8dd66c5250998629c84ede38db1;hpb=ad3c926d180f5d843b77db44c2b2449cdffeec34;p=ddstorm.git
diff --git a/alias.py b/alias.py
index d4e013e..a1b9d10 100644
--- a/alias.py
+++ b/alias.py
@@ -1,32 +1,41 @@
#! /usr/bin/python3
-# DDStorm
-# -------
-# Copyright (c) 2015 Agnibho Mondal
-# All rights reserved
+''' This module handles the aliases of the symptoms. '''
+'''
+Copyright (c) 2015 Agnibho Mondal
+All rights reserved
-# This file is part of DDStorm.
+This file is part of DDStorm.
-# DDStorm is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+DDStorm is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
-# DDStorm is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+DDStorm is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with DDStorm. If not, see .
+You should have received a copy of the GNU General Public License
+along with DDStorm. If not, see .
+'''
-import sys, os
+import sys
+import os
from fnmatch import fnmatch
+
from conf import Conf
from const import *
class Alias:
+ ''' Provides the class to handle symptom aliases '''
+
def __init__(self, conf=False):
+ '''
+ Initiates the alias object
+ Accepts a Conf object as parameter
+ '''
self.data={}
if(conf):
self.conf=conf
@@ -35,19 +44,25 @@ class Alias:
self.compile()
def compile(self):
+ ''' Compile the plaintext index files to a program usable format '''
+ # Loop over the alias files
for path, subdirs, files in os.walk(self.conf.get("alias_path")):
for name in files:
if(fnmatch(name, "*.txt")):
+ # Open the *.txt files
with open(self.conf.get("alias_path")+name, "r") as f:
for line in f:
+ # Ignore lines starting with #
line=line.rstrip().split("#")[0]
if(len(line)==0):
pass
else:
terms=[]
+ # Split words separated by ; and add to the terms
for i in line.split(";"):
if(i.strip()):
terms.append(i.strip())
+ # If alias present, add terms to the data
if(len(terms)==2):
self.data[terms[-1]]=terms[0]
elif(len(terms)>2):
@@ -56,12 +71,22 @@ class Alias:
self.data[i]=t
def get(self, term):
+ '''
+ Return the alias of the queried symptom
+
+ Parameter:
+ term - Queried string
+
+ Return value:
+ String containing the alias of the term
+ '''
if(term in self.data):
return self.data[term]
else:
return term
def main():
+ ''' Print the alias of the command line argument '''
a=Alias()
if(len(sys.argv)>1):
print(a.get(sys.argv[1]))