コード例 #1
0
ファイル: sum_records.py プロジェクト: tulsluper/sanscript
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
ファイル: logs_clear.py プロジェクト: tulsluper/sanscript
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
ファイル: db_sql.py プロジェクト: tulsluper/sanscript
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
ファイル: san_db.py プロジェクト: tulsluper/sanscript
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