예제 #1
0
def main():

    try:
        SDicts = get_apps().get_model(app_label=APPNAME, model_name='SDicts')
        CDicts = get_apps().get_model(app_label=APPNAME, model_name='CDicts')
        Integers = get_apps().get_model(app_label=APPNAME, model_name='Integers')
        Last = get_apps().get_model(app_label=APPNAME, model_name='Last')

        tx_elements = SDicts.objects.last().values.get('TxElements', [])[-1]
        integer = Integers.objects.last().values['s']['TxElements']

        ports_values = CDicts.objects.last().values.get('TxElements')
        active_ports_number = len([1 for xlist in ports_values.values() if xlist[-1]])
    except:
        tx_elements = None
        integer = None
        active_ports_number = None

    data = {
        'tx_elements': tx_elements,
        'integer': integer,
        'active_ports_number': active_ports_number,
    }

    Last.objects.all().delete()
    obj = Last(values=data)
    obj.save()
예제 #2
0
def main():
    null_dt = datetime.now()-timedelta(days=1, hours=1)
    Portlog = get_apps().get_model(app_label='fc', model_name='Portlog')
    Portlog.objects.filter(dt__lt=null_dt).delete()
    null_dt = datetime.now()-timedelta(days=366, hours=1)
    Fabriclog = get_apps().get_model(app_label='fc', model_name='Fabriclog')
    Fabriclog.objects.filter(dt__lt=null_dt).delete()
    return
예제 #3
0
def main():

    if len(sys.argv) > 1:
        datestring = sys.argv[1]
    else:
        datestring = datetime.now().strftime('%Y-%m-%d')

    dirpath = os.path.join(DIFFSDIR, datestring)

    udiffs, xtimes, deltas = sum_udiffs(dirpath)
    cdicts, pdicts, sdicts = calc_dicts(udiffs, deltas)

    fdicts = sum_f_ports(cdicts)

    date = datetime.now().date()
    apps = get_apps()
    appname = 'bc'
    for values, modelname in [ 
        [xtimes, 'XTimes'],
        [deltas, 'Deltas'],
        [cdicts, 'CDicts'],
        [pdicts, 'PDicts'],
        [sdicts, 'SDicts'],
        [fdicts, 'FDicts'],
        [INTEGERS, 'Integers'],
    ]:
        model = apps.get_model(app_label=APPNAME, model_name=modelname)
        obj, created = model.objects.update_or_create(
            date=date, defaults={'values': values})
        logging.info('--- model: %s | %s records' %(
            modelname, len(values)))
    return
예제 #4
0
def run():

    apps = get_apps()
    fc_SwitchConnection = apps.get_model(app_label='fc', model_name='SwitchConnection')
    bc_SwitchConnection = apps.get_model(app_label='bc', model_name='SwitchConnection')

    bc_SwitchConnection.objects.all().delete()
    for obj in fc_SwitchConnection.objects.all():
        print(obj)
        bc_SwitchConnection(
                name=obj.name, address=obj.address,
                enabled=obj.enabled, order=obj.order
            ).save()

    return
예제 #5
0
def save(appname, relations):
    apps = get_apps()
    for filename, modelname, filters in relations:
        records = load_data(os.path.join(JSONDIR, filename), [])
        model = apps.get_model(app_label=appname, model_name=modelname)
        if filters.get('before_delete_all'):
            model.objects.all().delete()
        elif filters.get('before_delete'):
            model.objects.filter(**filters['before_delete']).delete()
        if debug_records_flag is False:
            model.objects.bulk_create([model(**record) for record in records])
        else:
            for record in records:
                try:
                    model(**record).save()
                except:
                    print('== {} =='.format(modelname))
                    for key in sorted(record.keys()):
                        print(key, record[key] if key in record else '')
                    print('\n')
        logging.info('--- file: %s -> model: %s | %s records' %(
            filename, modelname, len(records)))
    return