added erase to backup (to clean tests)
This commit is contained in:
parent
7a97e382c7
commit
1233ec86f3
@ -272,6 +272,7 @@ optional arguments:
|
|||||||
Device code/password
|
Device code/password
|
||||||
-f, --force-udp Force UDP communication
|
-f, --force-udp Force UDP communication
|
||||||
-v, --verbose Print debug information
|
-v, --verbose Print debug information
|
||||||
|
-E, --erase clean the device after writting backup!
|
||||||
-r, --restore Restore from backup
|
-r, --restore Restore from backup
|
||||||
-c, --clear-attendance
|
-c, --clear-attendance
|
||||||
On Restore, also clears the attendance [default keep
|
On Restore, also clears the attendance [default keep
|
||||||
|
@ -36,6 +36,8 @@ parser.add_argument('-f', '--force-udp', action="store_true",
|
|||||||
help='Force UDP communication')
|
help='Force UDP communication')
|
||||||
parser.add_argument('-v', '--verbose', action="store_true",
|
parser.add_argument('-v', '--verbose', action="store_true",
|
||||||
help='Print debug information')
|
help='Print debug information')
|
||||||
|
parser.add_argument('-E', '--erase', action="store_true",
|
||||||
|
help='clean the device after writting backup!')
|
||||||
parser.add_argument('-r', '--restore', action="store_true",
|
parser.add_argument('-r', '--restore', action="store_true",
|
||||||
help='Restore from backup')
|
help='Restore from backup')
|
||||||
parser.add_argument('-c', '--clear-attendance', action="store_true",
|
parser.add_argument('-c', '--clear-attendance', action="store_true",
|
||||||
@ -45,6 +47,21 @@ parser.add_argument('filename', nargs='?',
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
def erase_device(conn, serialnumber, clear_attendance=False):
|
||||||
|
"""input serial number to corroborate."""
|
||||||
|
print ('WARNING! the next step will erase the current device content.')
|
||||||
|
print ('Please input the serialnumber of this device [{}] to acknowledge the ERASING!'.format(serialnumber))
|
||||||
|
new_serial = input ('Serial Number : ')
|
||||||
|
if new_serial != serialnumber:
|
||||||
|
raise BasicException('Serial number mismatch')
|
||||||
|
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 = ZK(args.address, port=args.port, timeout=args.timeout, password=args.password, force_udp=args.force_udp, verbose=args.verbose)
|
zk = ZK(args.address, port=args.port, timeout=args.timeout, password=args.password, force_udp=args.force_udp, verbose=args.verbose)
|
||||||
@ -86,6 +103,8 @@ try:
|
|||||||
}
|
}
|
||||||
json.dump(data, output, indent=1)
|
json.dump(data, output, indent=1)
|
||||||
output.close()
|
output.close()
|
||||||
|
if args.erase:
|
||||||
|
erase_device(conn, serialnumber, args.clear_attendance)
|
||||||
else:
|
else:
|
||||||
print ('Reading file {}'.format(filename))
|
print ('Reading file {}'.format(filename))
|
||||||
infile = open(filename, 'r')
|
infile = open(filename, 'r')
|
||||||
@ -103,20 +122,7 @@ try:
|
|||||||
templates = [Finger.json_unpack(t) for t in data['templates']]
|
templates = [Finger.json_unpack(t) for t in data['templates']]
|
||||||
#print (templates)
|
#print (templates)
|
||||||
print ("INFO: ready to write {} templates".format(len(templates)))
|
print ("INFO: ready to write {} templates".format(len(templates)))
|
||||||
#input serial number to corroborate.
|
erase_device(conn, serialnumber, args.clear_attendance)
|
||||||
print ('WARNING! the next step will erase the current device content.')
|
|
||||||
print ('Please input the serialnumber of this device [{}] to acknowledge the ERASING!'.format(serialnumber))
|
|
||||||
new_serial = input ('Serial Number : ')
|
|
||||||
if new_serial != serialnumber:
|
|
||||||
raise BasicException('Serial number mismatch')
|
|
||||||
conn.disable_device()
|
|
||||||
print ('Erasing device...')
|
|
||||||
conn.clear_data()
|
|
||||||
if args.clear_attendance:
|
|
||||||
print ('Clearing attendance too!')
|
|
||||||
conn.clear_attendance()
|
|
||||||
conn.read_sizes()
|
|
||||||
print (conn)
|
|
||||||
print ('Restoring Data...')
|
print ('Restoring Data...')
|
||||||
for u in users:
|
for u in users:
|
||||||
#look for Templates
|
#look for Templates
|
||||||
|
Loading…
Reference in New Issue
Block a user