__author__ = 'Dilum Bandara'
__version__ = '0.1'
__date__ = '1/3/2011'
__copyright__ = 'Copyright(c) 2011, Dilum Bandara'
__license__ = 'GPL'

import BaseConfig

class Queries:
    """
    Queries class. Queries from file
    """
    def __init__(self):
        self.fdIn = open(BaseConfig.QUERY_FILE, 'r')

    def __del__(self):
        self.fdIn.close()

    def get_query(self):
    #  Read attribute set of a node
        tmp_line = self.fdIn.readline().split()
        if len(tmp_line) == 0: return []
        query = [[tmp_line[0], tmp_line[1]]] #set no of required resources
        tmp_attrib = []
        for i in range(2, len(tmp_line)):
            if (i % 3) == 2: tmp_attrib.append(tmp_line[i])
            else: tmp_attrib.append(tmp_line[i])
            if (i % 3) == 1:
                query.append(tmp_attrib)
                tmp_attrib = [] 
        return query

