Example #1
0
 def handle(self, *args, **options):
     grp_instr = get_group_instrs('sim/')
     
     for g in grp_instr:
         try:
             group = InstrGroup.objects.get(name=g)
             print "group %s" % g
         except InstrGroup.DoesNotExist:
             group = InstrGroup(name=g)
             print "group %s created" % g
             group.save()
             print "group %s saved" % g
         
         for i in grp_instr[g]:
             displayname = i
             name = g + "_" + i
             try: 
                 instr = Instrument.objects.get(name=name)
             except Instrument.DoesNotExist:    
                 instr = Instrument(group=group, name=name, displayname=displayname)
                 print "instrument %s created" % i
             
             # update instr params
             instr.params = get_instr_params(os.path.join('sim', g, i))
             instr.save()
             print "instrument %s saved" % i
             
     print 'collect_instr run done'
Example #2
0
    def handle(self, *args, **options):
        grp_instr = get_group_instrs('sim/')

        for g in grp_instr:
            try:
                group = InstrGroup.objects.get(name=g)
                print "group %s" % g
            except InstrGroup.DoesNotExist:
                group = InstrGroup(name=g)
                print "group %s created" % g
                group.save()
                print "group %s saved" % g

            for i in grp_instr[g]:
                displayname = i
                name = g + "_" + i
                try:
                    instr = Instrument.objects.get(name=name)
                except Instrument.DoesNotExist:
                    instr = Instrument(group=group,
                                       name=name,
                                       displayname=displayname)
                    print "instrument %s created" % i

                # update instr params
                instr.params = get_instr_params(os.path.join('sim', g, i))
                instr.save()
                print "instrument %s saved" % i

        print 'collect_instr run done'
Example #3
0
    def handle(self, *args, **options):
        print 'collecting instruments one depth in sim/...'
        
        grp_instr = get_group_instrs('sim/')
        for g in grp_instr:
            try:
                group = InstrGroup.objects.get(name=g)
                print "group %s exists in db" % g
            except InstrGroup.DoesNotExist:
                group = InstrGroup(name=g)
                group.save()
                print "group %s created" % g
        
            mkdir_p( "static/doc/%s" % g )
            print "doc folder static/doc/%s touched" % g
            
            try:
                make_html_docs(g)
            except:
                raise Exception('make_html_docs failed')
                
            for i in grp_instr[g]:
                displayname = i
                name = g + "_" + i
                try: 
                    instr = Instrument.objects.get(name=name)
                    print "instrument %s exists in db" % i
                except Instrument.DoesNotExist:    
                    instr = Instrument(group=group, name=name, displayname=displayname)
                    print "instrument %s created" % i
                    
                if os.path.isfile('sim/' + g + '/' + i + '.png'):
                    instr.image = "/static/doc/" + g + "/" + i + ".png"
                    shutil.copyfile('sim/' + g + '/' + i + '.png','static/doc/' + g + '/' + i + '.png')
                    print "Adding image for instrument %s" % i
                else:
                    instr.image = '/static/noimage.png'

                # update instr params
                instr.params = get_instr_params(g, i)
                instr.save()
                print "instrument %s params updated" % i
                
        print 'collect_instr done.'
Example #4
0
    def handle(self, *args, **options):
        # global exception logging block
        try:

            print "<pre>\n"
            print datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S %Z %Y")
            print 'collecting instruments one depth in sim/...'

            # error log
            error_log = []

            grp_instr = get_group_instrs('sim/')
            for g in grp_instr:
                try:
                    group = InstrGroup.objects.get(name=g)
                    print "group %s exists in db" % g
                except InstrGroup.DoesNotExist:
                    group = InstrGroup(name=g)
                    group.save()
                    print "group %s created" % g

                mkdir_p( "static/doc/%s" % g )
                print "doc folder static/doc/%s touched" % g

                try:
                    make_html_docs(g)
                except:
                    raise Exception('make_html_docs failed')

                # instruments in group:
                for i in grp_instr[g]:

                    try:
                        displayname = i
                        name = g + "_" + i

                        try:
                            instr = Instrument.objects.get(name=name)
                            print "instrument %s exists in db" % i
                        except Instrument.DoesNotExist:    
                            instr = Instrument(group=group, name=name, displayname=displayname)
                            print "instrument %s created" % i

                        if os.path.isfile('sim/' + g + '/' + i + '.png'):
                            instr.image = "/static/doc/" + g + "/" + i + ".png"
                            shutil.copyfile('sim/' + g + '/' + i + '.png','static/doc/' + g + '/' + i + '.png')
                            print "Adding image for instrument %s" % i
                        else:
                            instr.image = '/static/noimage.png'

                        # update instr params
                        instr.params = get_instr_params_and_set_affiliation(g, i, instr)
                        instr.save()
                        print "instrument %s params updated" % i
                    except Exception as e:
                        error_str = "instrument %s: %s" % (i, e.__str__())
                        print error_str
                        error_log.append(error_str)
                        continue

            if len(error_log) > 0:
                print
                print "ERRORS: The following errors were encountered:"
                print
                print('\n'.join(error_log))

            print "</pre>\n"

        # global exception logging, appends to file "collectinstr_fail.log
        except Exception as e:
            msg = traceback.format_exc()

            _elog = logging.getLogger('collectinstr_fail')
            hdlr = logging.FileHandler('collectinstr_fail.log')
            hdlr.level = logging.ERROR
            hdlr.setFormatter(logging.Formatter('%(threadName)-22s: %(message)s'))

            hdlr2 = logging.StreamHandler(sys.stdout)
            hdlr2.level = logging.ERROR
            hdlr2.setFormatter(logging.Formatter('%(threadName)-22s: %(message)s'))

            _elog.addHandler(hdlr)
            _elog.addHandler(hdlr2)
            _elog.error(msg)