~george-edison55/audataserver-proxy/trunk

« back to all changes in this revision

Viewing changes to audataserver-proxy

  • Committer: Nathan Osman
  • Date: 2011-10-30 22:57:46 UTC
  • Revision ID: admin@quickmediasolutions.com-20111030225746-my5rq9u0u62q5mfe
Converted to plugin and implemented initial API sync. Also added the data dump as a dependency to the package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
class DataServerApp (object):
33
33
    
34
 
    data_dump    = '/opt/se-data-dumps/askubuntu.ddi'
35
 
    data_manager = None
36
 
    
37
34
    @cherrypy.expose
38
35
    def index(self):
39
36
        return "[Instructions and configuration go here.]"
41
38
    @cherrypy.expose
42
39
    def similar(self, title):
43
40
        cherrypy.response.headers["Content-Type"] = "application/json"
44
 
        search_results = self.data_manager.search_json(title);
 
41
        search_results = cherrypy.engine.data_manager.search(title)
45
42
        return search_results.encode()
46
43
 
47
44
 
 
45
class DataManager (cherrypy.process.plugins.SimplePlugin):
 
46
    
 
47
    data_dump = '/opt/se-data-dumps/askubuntu.ddi'
 
48
    
 
49
    def __init__(self, engine, data_manager):
 
50
        super(DataManager, self).__init__(engine)
 
51
        self.data_manager = data_manager
 
52
    
 
53
    def start(self):
 
54
        print 'Loading DDI file...'
 
55
        if not self.data_manager.load_ddi_file(self.data_dump):
 
56
            raise Exception('There was an error loading the data dump file.')
 
57
        print 'Performing initial API sync...'
 
58
        self.data_manager.blocking_api_update()
 
59
    
 
60
    def stop(self):
 
61
        # TODO: store the synced data dump
 
62
        # self.data_manager.store_ddi_file()
 
63
        pass
 
64
    
 
65
    def search(self, search_terms):
 
66
        return self.data_manager.search_json(search_terms)
 
67
 
 
68
 
48
69
with aulibrary() as lib:
49
70
    with lib.create_data_manager() as manager:
50
 
        # Load the data dump
51
 
        print "Loading data dump..."
52
 
        manager.load_ddi_file(DataServerApp.data_dump)
53
 
        DataServerApp.data_manager = manager
 
71
        cherrypy.engine.data_manager = DataManager(cherrypy.engine, manager)
54
72
        cherrypy.quickstart(DataServerApp(), config={'global': {
55
73
            'tools.encode.encoding': 'utf-8',
56
74
            'server.socket_host': '0.0.0.0',
57
75
            'server.socket_port': 19115,
 
76
            'engine.data_manager.on': True,
58
77
        }})