예제 #1
0
def _run(port,**xtraargs):
    
    print "launching service... pid=",os.getpid()
    
    _dbname,refdbname = sswizard_utils.getdatabase()

    globals()['dbname'] = _dbname

    urls = (
        '/(\w+)', 'Student',
        '/student/(\w+)', 'Student',
        '/subject/(\w+)', 'Subject',
        '/adult/(\w+)', 'Adult',
        '/list/(\w+)', 'List',
        '/load/(\w+)', 'Load',
        '/schema/(\w+)', 'Schema',
        '/id/(\w+)', 'SearchID',
        '/criteria/(\w+)', 'SearchCriteria',
        '/add/(\w+)', 'Add',
        '/new/(\w+)', 'New',
        '/command/(\w+)','Command',
        '/update/(\w+)','UpdateID',
        '/updateuid/(\w+)','UpdateUID',
        '/refdata/(\w+)','Refdata',
        '/form/(\w+)','Form',
        '/last/(\w+)','Last'
    )
    
    globals()['database'] = Database(dbname)
    refdatabase = Database(refdbname)
    #of = ObjFactory(True)
    #enums = sswizard_utils.setenums(dow="all",prep=-1,database=refdatabase)
    
    globals()['of'] = ObjFactory(True)
    globals()['enums'] = sswizard_utils.setenums(dow="all",prep=-1,database=refdatabase)
    globals()['prepmap'] = sswizard_utils._loadprepmapper(database)
    
    args = dict(database=database,refdatabase=refdatabase,
                saveversion=1,of=of,enums=enums,keepversion=True)

    if xtraargs<>{}:
        for k,v in xtraargs.iteritems():
            args[k] = v
            
    ssviewer_utils.dataset_load(**args)

    # get a mapping of userobjid to db refid (__id) as of uses the former to index but the web page
    # uses __id as they are easier to pass in URL
    with database:
        globals()['dbidlookup'] = sswizard_query_utils._dbid2userdefid(database,asdict=True)

    #app = web.application(urls, locals())
    globals()['app'] = web.application(urls, globals())
    #globals()['app'].add_processor(mutex_processor())
    
    sys.argv.append(str(port))    
    app.run()
예제 #2
0
    def setUp(self):
        
        self.dbname='test_ssviewer_rest_dump'
        self.database = Database(self.dbname)
        self.of = ObjFactory(True)
        self.enums = sswizard_utils.setenums(dow="all",prep=-1,database=self.database)
        self.prepmap = sswizard_utils._loadprepmapper(self.database)

        args = dict(database=self.database,refdatabase=self.database,saveversion=1,of=self.of,enums=self.enums)
        ssviewer_utils.dataset_load(**args)
예제 #3
0
    def setUp(self):

        self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'test_ssviewer_rest_dump'
        self.database = Database(self.dbname)
        self.of = ObjFactory(True)
        self.enums = sswizard_utils.setenums(dow="all",
                                             prep=-1,
                                             database=self.database)
        self.prepmap = sswizard_utils._loadprepmapper(self.database)

        args = dict(database=self.database,
                    refdatabase=self.database,
                    saveversion=1,
                    of=self.of,
                    enums=self.enums)
        ssviewer_utils.dataset_load(**args)
예제 #4
0
    def GET(self,cmd):
        
        web.header('Access-Control-Allow-Origin','*')
        web.header('Access-Control-Allow-Credientials','true')

        if cmd=="stop":
            print "bringing down service...."
            app.stop()
        elif cmd=="ping":
            return("ping")
        elif cmd=="stats":
            return(len(of.query('lesson')))
        elif cmd=="config":
            return(len(of.query('lesson')))
        elif cmd=="reload":
            
            data = web.input()
            
            xtraargs={}
            for attr,attr_val in data.iteritems():
                xtraargs[attr] = attr_val
    
            #globals()['dbname'] = _dbname
            globals()['database'] = Database(globals()['dbname'])
            refdatabase = globals()['database']

            globals()['of'] = ObjFactory(True)
            globals()['enums'] = sswizard_utils.setenums(dow="all",prep=-1,database=refdatabase)
            globals()['prepmap'] = sswizard_utils._loadprepmapper(database)
             
            args = dict(database=database,refdatabase=refdatabase,
                         saveversion=1,of=of,enums=enums,keepversion=True)
         
            if xtraargs<>{}:
                for k,v in xtraargs.iteritems():
                    args[k] = v
                     
            ssviewer_utils.dataset_load(**args)
         
            logstr = "reloading " + globals()['dbname']
            log.log(thisfuncname(),3,msg=logstr)            

            # get a mapping of userobjid to db refid (__id) as of uses the former to index but the web page
            # uses __id as they are easier to pass in URL
            with database:
                globals()['dbidlookup'] = sswizard_query_utils._dbid2userdefid(database,asdict=True)
            
        elif cmd=="dump":
            
            data = web.input()
            

            #objtypes = data['objtypes'].split(",")
            #fields = data['fields'].split(",")
            #pprint = data['pprint'].split(",")
            
            
            listfields = ['objtypes','omitfields','fields']
            dictfields = ['constraints']
            boolfields = ['fieldnames','objref']
            urldict = {}
            
            for field in listfields:
                try:
                    urldict[field] = data[field].split(",")
                except:
                    pass
                
            for field in boolfields:
                urldict[field] = False
                try:
                    if data[field] == "1":
                        urldict[field] = True
                        print field
                except:
                    pass
                
            for field in dictfields:
                try:
                    _urldict = {}
                    for nvp in data[field].split(","):
                        k,v = nvp.split("=")
                        _urldict[k]=v

                    urldict[field] = _urldict
                except:
                    pass
                
            if data.has_key('pprint'):
                if data['pprint']=="0":
                    pprint=False
                else:
                    pprint=True

            results = of.dumpobjrpt(**urldict)
            
            if data.has_key('count'):
                if data['count']=="0":
                    return(len(results))
                
            css = "body { width:3000px;}"
            css += "table { border: 1px solid #f00;}"
            css += "td {border: 1px solid #000;word-wrap:break-word;}"
           
            if pprint == True:
                #_o_str = "<html><style>"+css+"</style><body><table>"
                _o_str = "<table>"

                for _output in results:
                    _o_str = _o_str + "<tr>"
                    for _o in _output:
                        _o_str+="<td>"+str(_o)+"</td>"
                        #.ljust(15)[:15]
                    _o_str += "</tr>"
                #return _o_str+"</table></body></html>"
                return _o_str+"</table>"
            else:
                return(results)