Пример #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):
     
     dbname='service_getrecord_1lesson'
     self.database = Database(dbname)
     self.of = ObjFactory(True)
     enums = sswizard_utils.setenums(dow="all",prep=-1,database=self.database)
     
     args = dict(database=self.database,refdatabase=self.database,saveversion=1,
                 of=self.of,enums=enums)
     
     ssviewer_utils.dataset_load(**args)
Пример #4
0
    def setUp(self):

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

        args = dict(database=self.database,
                    refdatabase=self.database,
                    saveversion=1,
                    of=self.of,
                    enums=enums)

        ssviewer_utils.dataset_load(**args)
Пример #5
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)
Пример #6
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)
Пример #7
0
    def load(self,
             saveversion=None,
             dow=None,
             prep=None,
             period=None,
             teacher=None,
             student=None,
             source=None,
             unknown=None):

        self.of.reset()

        # database name
        if self.dbname_entry_sv.get() <> self.dbname:
            newdb = self.dbname_entry_sv.get()
            log.log(thisfuncname(),
                    3,
                    msg="switching databases",
                    olddb=self.dbname,
                    newdb=newdb)
            self.database = Database(newdb)
            self.dbname = newdb

        # saveversion
        if saveversion == None or saveversion == "":
            saveversion = self.dbload_entry_sv.get()
        if saveversion == "":
            log.log(thisfuncname(),
                    1,
                    msg="no saveversion set for load; exception")
            raise Exception("attempting to load without a saveversion set")

        # unknown
        if unknown == None:
            unknown = self.unknown_checkbutton_sv.get()

        # prep
        if prep == None: prep = self.prep_entry_sv.get()
        if prep == "":
            prep = -1

        # period
        if period == None: period = self.period_entry_sv.get()
        if period == "":
            period = "all"

        # dow
        if dow == None: dow = self.dow_entry_sv.get()
        if dow == "":
            dow = "all"

        # teacher
        if teacher == None: teacher = self.teacher_label_sv.get()
        if teacher == "":
            teacher = "all"

        # student
        if student == None: student = self.student_label_sv.get()
        if student == "":
            student = "all"

        # source
        if source == None: source = self.source_label_sv.get()
        if source == "":
            source = "dbinsert"

        # get enums
        self.enums = sswizard_utils.setenums(dow, prep, self.refdatabase)

        ssviewer_utils.dataset_load(self.database, self.refdatabase, self.of,
                                    self.enums, saveversion, unknown, prep,
                                    period, dow, teacher, student, source)

        # get enums
        self.enums = sswizard_utils.setenums(dow, prep, self.refdatabase)
Пример #8
0
    def load(self,saveversion=None, dow=None, prep=None, period=None, teacher=None, student=None, source=None,
             unknown=None):
        
        self.of.reset()
        
        # database name
        if self.dbname_entry_sv.get() <> self.dbname:
            newdb = self.dbname_entry_sv.get()
            log.log(thisfuncname(),3,msg="switching databases",olddb=self.dbname,newdb=newdb)
            self.database = Database(newdb)
            self.dbname = newdb
            
        # saveversion
        if saveversion==None or saveversion== "":
            saveversion = self.dbload_entry_sv.get()
        if saveversion == "":
            log.log(thisfuncname(),1,msg="no saveversion set for load; exception")
            raise Exception("attempting to load without a saveversion set")
        
        # unknown
        if unknown==None:
            unknown = self.unknown_checkbutton_sv.get()
            
        # prep
        if prep==None: prep=self.prep_entry_sv.get()
        if  prep == "":
            prep = -1
        
        # period
        if period==None: period=self.period_entry_sv.get()
        if period == "":
            period = "all"

        # dow
        if dow==None: dow = self.dow_entry_sv.get()
        if dow == "":
            dow = "all"
        
        # teacher
        if teacher==None: teacher = self.teacher_label_sv.get()
        if teacher == "":
            teacher = "all"    
        
        # student
        if student==None: student = self.student_label_sv.get()
        if student == "":
            student = "all"
        
        # source
        if source==None: source = self.source_label_sv.get()
        if source == "":
            source = "dbinsert"       

        # get enums
        self.enums = sswizard_utils.setenums(dow,prep,self.refdatabase)

        ssviewer_utils.dataset_load(self.database,self.refdatabase,self.of,self.enums,saveversion,unknown,prep,period,
                                    dow,teacher,student,source)
        
        # get enums
        self.enums = sswizard_utils.setenums(dow,prep,self.refdatabase)