Пример #1
0
     json.dump(data, output, indent=1)
     output.close()
     if args.erase:
         erase_device(conn, serialnumber, args.clear_attendance)
 else:
     print ('Reading file {}'.format(filename))
     infile = open(filename, 'r')
     data = json.load(infile)
     infile.close()
     #compare versions...
     if data['version'] != '1.00jut':
         raise BasicException("file with different version... aborting!")
     if data['fp_version'] != fp_version:
         raise BasicException("fingerprint version mismmatch {} != {} ... aborting!".format(fp_version, data['fp_version']))
     #TODO: check data consistency...
     users = [User.json_unpack(u) for u in data['users']]
     #print (users)
     print ("INFO: ready to write {} users".format(len(users)))
     templates = [Finger.json_unpack(t) for t in data['templates']]
     #print (templates)
     print ("INFO: ready to write {} templates".format(len(templates)))
     erase_device(conn, serialnumber, args.clear_attendance)
     print ('Restoring Data...')
     for u in users:
         #look for Templates
         temps = list(filter(lambda f: f.uid ==u.uid, templates))
         #print ("user {} has {} fingers".format(u.uid, len(temps)))
         conn.save_user_template(u,temps)
     conn.enable_device()
     print ('--- final sizes & capacity ---')
     conn.read_sizes()
def backup_attendance():
    def erase_device(conn, serialnumber, clear_attendance=False):
        """input serial number to corroborate."""
        print('WARNING! the next step will erase the current device content.')
        conn.disable_device()
        print('Erasing device...')
        conn.clear_data()
        if clear_attendance:
            print('Clearing attendance too!')
            conn.clear_attendance()
        conn.read_sizes()
        print(conn)

    zk = connect_zk()
    try:
        print('Connecting to device ...')
        conn = zk.connect()
        serialnumber = conn.get_serialnumber()
        fp_version = conn.get_fp_version()
        print('Serial Number    : {}'.format(serialnumber))
        print('Finger Version   : {}'.format(fp_version))
        filename = "../{}.json.bak".format(serialnumber)
        print('')

        print('Reading file {}'.format(filename))
        infile = open(filename, 'r')
        data = json.load(infile)
        infile.close()
        #compare versions...
        if data['version'] != '1.00jut':
            raise BasicException("file with different version... aborting!")
        if data['fp_version'] != fp_version:
            raise BasicException(
                "fingerprint version mismmatch {} != {} ... aborting!".format(
                    fp_version, data['fp_version']))
        #TODO: check data consistency...
        users = [User.json_unpack(u) for u in data['users']]
        #print (users)
        print("INFO: ready to write {} users".format(len(users)))
        templates = [Finger.json_unpack(t) for t in data['templates']]
        #print (templates)
        print("INFO: ready to write {} templates".format(len(templates)))
        erase_device(conn, serialnumber, False)
        print('Restoring Data...')
        for u in users:
            #look for Templates
            temps = list(filter(lambda f: f.uid == u.uid, templates))
            #print ("user {} has {} fingers".format(u.uid, len(temps)))
            conn.save_user_template(u, temps)
        conn.enable_device()
        print('--- final sizes & capacity ---')
        conn.read_sizes()
        print(conn)
        return "success"

    except BasicException as e:
        print(e)
        print('')
    except Exception as e:
        print("Process terminate : {}".format(e))
        print("Error: %s" % sys.exc_info()[0])
        print('-' * 60)
        traceback.print_exc(file=sys.stdout)
        print('-' * 60)
    finally:
        if conn:
            print('Enabling device ...')
            conn.enable_device()
            conn.disconnect()
            print('ok bye!')
            print('')
Пример #3
0
     if args.erase:
         erase_device(conn, serialnumber, args.clear_attendance)
 else:
     print('Reading file {}'.format(filename))
     infile = open(filename, 'r')
     data = json.load(infile)
     infile.close()
     #compare versions...
     if data['version'] != '1.00jut':
         raise BasicException("file with different version... aborting!")
     if data['fp_version'] != fp_version:
         raise BasicException(
             "fingerprint version mismmatch {} != {} ... aborting!".format(
                 fp_version, data['fp_version']))
     #TODO: check data consistency...
     users = [User.json_unpack(u) for u in data['users']]
     #print (users)
     print("INFO: ready to write {} users".format(len(users)))
     templates = [Finger.json_unpack(t) for t in data['templates']]
     #print (templates)
     print("INFO: ready to write {} templates".format(len(templates)))
     erase_device(conn, serialnumber, args.clear_attendance)
     print('Restoring Data...')
     for u in users:
         #look for Templates
         temps = list(filter(lambda f: f.uid == u.uid, templates))
         #print ("user {} has {} fingers".format(u.uid, len(temps)))
         conn.save_user_template(u, temps)
     conn.enable_device()
     print('--- final sizes & capacity ---')
     conn.read_sizes()