Example #1
0
def main():
    """
    Start-up web server.
    """
    parser = OptionParser()
    parser.add_option("-c", "--config", dest="config", default=False,
        help="provide cherrypy configuration file")
    opts, _ = parser.parse_args()

    # Read server configuration
    conf_file = opts.config
    config = {}
    if  conf_file:
        fdesc  = open(conf_file, 'r')
        config = yaml.load(fdesc.read())
        fdesc.close()
    else:
        config = readconfig()
    config['port'] = config['server_port']

    root = Root(config)
    print root.config
    # subscribe plugins
    cherrypy.engine.qbm = QueryBuilderBus(cherrypy.engine, \
                           root.config['db_url'], root.config['map_file'])

    cherrypy.engine.qbm.subscribe()


    # Start PyQB server
    root.start()
Example #2
0
def configurelog():
    """Log configuration"""
    logfile = None
    try:
        config = readconfig()
        logfile = config['logconfig']
    except:
        print "taking default log config"
        basedir = imp.find_module('pyquerybuilder')[1]
        logfile = os.path.join(basedir, 'config/logging.conf')

    logging.config.fileConfig(logfile)

    #create logger
    logger = logging.getLogger("ConstructQuery")
    logger.setLevel(logging.DEBUG)
Example #3
0
def main():
    """
    Start-up web server.
    """
    parser = OptionParser()
    parser.add_option("-c", "--config", dest="config", default=False,
        help="provide cherrypy configuration file")
    opts, _ = parser.parse_args()

    # Read server configuration
    conf_file = opts.config
    config = {}
    if  conf_file:
        fdesc  = open(conf_file, 'r')
        config = yaml.load(fdesc.read())
        fdesc.close()

    config = readconfig()
    config['port'] = config['server_port']

    # Start DAS server
    root = Root(config)
    root.start()
Example #4
0
    def recognize_schema(self, mapper, dbmanager=None, db_alias=None):
        """
        # Step 1. Recognize three types of tables and links.
        # Step 2. Detect recursive cases, and create Alias table to
        #         To resolve recursive cases.
        # Step 3. Generate lookup table for Entity -> Attribute link.
        #         This will resolve the issue such as Person table.
        #         generate simplified graph
        # Step 4. Calculate each links type, by default foreign key link
        #         other format of link are acceptable. Such as OUTER
        #         JOIN
        # Step 5. Detect dividings and accept input from administrator.
        #         Load split.yaml file
        # Step 6. Generate sub graphs from each sub sets.
        """
        self._schema.recognize_type(mapper)

        # Step 2. Detect recursive cases, and create Alias table to
        #         To resolve recursive cases.
        #   1. entity table link to itself
        #   2. rel table double link to entity table
        #   3. Error:
        #       . ent table double link to entity table ?
        #           . composite key has been handled by FKCons
        #   4. not sure:
        #       . rel table point to itself ? remove?
        #       . ent/rel table point to rel table with double link
        #       ---> pick one or both ?
        #   5. safe to egnore: 
        #     attr table will not involing in path generation
        #       . any table double link to attr table is fine
        #       . attr table point to itself

        self._schema.handle_alias()
        config = {'alias_mapfile':None, 'split_file':None}
        if dbmanager != None and db_alias != None:
            self.load_statistics(dbmanager, db_alias)
            config = readconfig()
            self.further_map(mapper, config['alias_mapfile'])

        # Step 3. Generate lookup table for Entity -> Attribute link.
        #         This will resolve the issue such as person table.
        #         get simplified graph
        #         We need a function map(key.attribute) ==> table name
        #         on core schema
        self.attr_table = self._schema.v_attr
        self.attr_path, self.attr_path_tables = \
            self._schema.gen_attr_links(mapper)
        for name, path in self.attr_path.items():
            for pat in path:
                _LOGGER.debug("path %s is %s.%s --> %s.%s" % (name, \
                pat.ltable, pat.lcolumn, pat.rtable, pat.rcolumn))

        if dbmanager != None and db_alias != None:
            self.left_joins = load_left_join(config['left_join'])
            for idx in range(len(self.left_joins)):
                key = self.left_joins[idx]
                if key != None and key.find('.') == -1:
                    table = mapper.get_table(key)
                    self.left_joins.pop(idx)
                    self.left_joins.insert(idx, table)
            _LOGGER.debug('left_joins is %s' % str(self.left_joins))
        simschemas = self._schema.gen_simschema()

        if dbmanager != None and db_alias != None:
            self._schema.recognize_shortcut()

        _LOGGER.debug("%d simschemas are generated" % len(simschemas))
        for simschema in simschemas:
            simschema.update_nodelist()

        self._simschemas = simschemas

        # Step 4. Calculate each links type, by default foreign key link
        #         other format of link are acceptable. Such as OUTER
        #         JOIN

        # Step 5. Detect dividings and accept input from administrator.
        #         Load split.yaml file
        splition = False
        if dbmanager != None and db_alias != None:
            splition = load_split(config['split_file'])
        if splition:
            for simschema in simschemas:
                self.subconstructors.append([])
                self.subnodes.append([])
                subgraphs, subnodes = simschema.gen_subgraph(splition)
        # Step 6. Generate sub graphs from each sub sets.
        #         self.sub_schema.add(tables)
        #         self.sub_graphs.add(self.graph_from_schema(tables,
        #           links))
        #         ? construct_query instance?
                for subgraph in subgraphs:
                    self.subconstructors[-1].append(\
                      ConstructQuery(subgraph._graph, weighted=True))
                for nodes in subnodes:
                    self.subnodes[-1].append(nodes)
        else:
            for simschema in simschemas:
                graph = simschema.get_wgraph_from_schema()
                self.subconstructors.append([ConstructQuery(graph, weighted=True)])
                nodes = set(range(len(simschema.ordered)))
                self.subnodes.append([nodes])