First wheel package version.
This commit is contained in:
43
samples/Net2Scripting.config
Normal file
43
samples/Net2Scripting.config
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||
</configSections>
|
||||
<appSettings>
|
||||
<add key="user_script" value="samples/user_script.py" />
|
||||
<add key="confirm_wait" value="true" />
|
||||
<add key="log_stacktrace" value="true" />
|
||||
<add key="enable_linecache" value="true" />
|
||||
</appSettings>
|
||||
<log4net>
|
||||
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<param name="File" value="${SystemDrive}/Net2 Access Control/Net2Scripting.log"/>
|
||||
<param name="AppendToFile" value="true"/>
|
||||
<param name="rollingStyle" value="Size"/>
|
||||
<param name="maxSizeRollBackups" value="10"/>
|
||||
<param name="maximumFileSize" value="10MB"/>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<param name="Header" value=""/>
|
||||
<param name="Footer" value=""/>
|
||||
<param name="ConversionPattern" value="%d [%c,%t] %-5p %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<param name="Header" value="[Header]\r\n" />
|
||||
<param name="Footer" value="[Footer]\r\n" />
|
||||
<param name="ConversionPattern" value="%d [%c,%t] %-5p %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="RollingFileAppender" />
|
||||
<appender-ref ref="ConsoleAppender" />
|
||||
</root>
|
||||
<logger name="Paxton">
|
||||
<level value="ERROR" />
|
||||
<appender-ref ref="RollingFileAppender" />
|
||||
<appender-ref ref="ConsoleAppender" />
|
||||
</logger>
|
||||
</log4net>
|
||||
</configuration>
|
55
samples/add_user.py
Normal file
55
samples/add_user.py
Normal file
@ -0,0 +1,55 @@
|
||||
"""
|
||||
Sample script to add a new user
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Uncomment to use dotnet DateTime objects
|
||||
# from System import DateTime
|
||||
|
||||
# Uncomment to use python datetime objects
|
||||
# from datetime import datetime
|
||||
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Add new user
|
||||
res = net2.add_user(
|
||||
access_level_id=1, # Always, all doors
|
||||
department_id=0, # No department
|
||||
anti_passback_ind=False,
|
||||
alarm_user_ind=False,
|
||||
first_name="John",
|
||||
middle_name=None,
|
||||
sur_name="Doe",
|
||||
telephone_no="12345678",
|
||||
telephone_extension=None,
|
||||
pin_code=None,
|
||||
activation_date=None, # Now
|
||||
# Or supply a dotnet DateTime object (also see import)
|
||||
# activation_date=DateTime(2018, 1, 2),
|
||||
# Or supply a python datetime object (also see import)
|
||||
# activation_date=datetime(2018, 1, 2),
|
||||
active=True,
|
||||
fax_no=None,
|
||||
expiry_date=None) # Never expire (also see activation_date)
|
||||
|
||||
if res:
|
||||
print("Success")
|
||||
else:
|
||||
print("Failure")
|
51
samples/add_users_with_card.py
Normal file
51
samples/add_users_with_card.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""
|
||||
Sample script to add many users with cards
|
||||
"""
|
||||
from net2xs import Net2XS
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
|
||||
# Add 1000 users
|
||||
for i in range(1, 1001):
|
||||
first_name = "Test"
|
||||
sur_name = "User #%04d" % (i)
|
||||
card_nr = 77770000 + i
|
||||
|
||||
# Add user
|
||||
res = net2.add_user(
|
||||
first_name=first_name,
|
||||
sur_name=sur_name)
|
||||
if not res:
|
||||
print("Failed to add user %s %s: %s" %
|
||||
(first_name, sur_name, net2.last_error_message))
|
||||
continue
|
||||
|
||||
# Get user id
|
||||
user_id = net2.get_user_id_by_name((first_name, sur_name))
|
||||
if user_id < 0:
|
||||
print("Failed to find user %s %s" % (first_name, sur_name))
|
||||
continue
|
||||
|
||||
# Create card
|
||||
res = net2.add_card(card_nr, 1, user_id)
|
||||
if not res:
|
||||
print("Failed to add card to user %s %s: %s" %
|
||||
(first_name, sur_name, net2.last_error_message))
|
36
samples/direct_db_query.py
Normal file
36
samples/direct_db_query.py
Normal file
@ -0,0 +1,36 @@
|
||||
"""
|
||||
Sample script to query the database directly
|
||||
"""
|
||||
|
||||
from Net2Scripting.net2dbxs import Net2DBXS
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
with Net2DBXS() as net2db:
|
||||
# Connect
|
||||
net2db.connect()
|
||||
# Get last log entry relating a device
|
||||
dataset = net2db.query_db(
|
||||
"select * from EventsEx "
|
||||
"where EventID = "
|
||||
"(select max(EventID) from sdk.EventsEx "
|
||||
" where SerialNumber is not NULL)")
|
||||
|
||||
# Non result
|
||||
if (not dataset
|
||||
or dataset.Tables.Count < 1
|
||||
or dataset.Tables[0].Rows.Count < 1):
|
||||
|
||||
print("Nothing relevant found")
|
||||
else:
|
||||
# Just to demonstrate how to get values from a dataset
|
||||
|
||||
# Typically Table[0]
|
||||
table = dataset.Tables[0]
|
||||
# In this case only interested in the first row
|
||||
row = dataset.Tables[0].Rows[0]
|
||||
# For each column
|
||||
for col in table.Columns:
|
||||
val = row.get_Item(col.ColumnName)
|
||||
print("%s = %s" % (col.ColumnName, val))
|
17
samples/find_modules.py
Normal file
17
samples/find_modules.py
Normal file
@ -0,0 +1,17 @@
|
||||
"""
|
||||
Sample script to detect Net2Plus modules
|
||||
"""
|
||||
|
||||
from Net2Scripting.network.net2plus import Net2PlusFinder
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
inst = Net2PlusFinder()
|
||||
print("Please wait for the modules to respond...")
|
||||
devs = inst.find()
|
||||
if devs:
|
||||
for d in devs:
|
||||
print(d)
|
||||
else:
|
||||
print("No devices detected")
|
17
samples/find_sqlserver.py
Normal file
17
samples/find_sqlserver.py
Normal file
@ -0,0 +1,17 @@
|
||||
"""
|
||||
Sample script to detect all SQLServer instances
|
||||
"""
|
||||
|
||||
from Net2Scripting.network.sqlserver import SqlServerFinder
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
inst = SqlServerFinder()
|
||||
print("Please wait for the servers to respond...")
|
||||
srvs = inst.find()
|
||||
if srvs:
|
||||
for s in srvs:
|
||||
print(s)
|
||||
else:
|
||||
print("No servers detected")
|
26
samples/get_access_levels.py
Normal file
26
samples/get_access_levels.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""
|
||||
Sample script to fetch all access levels
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Show all access levels and their details
|
||||
for al in net2.get_py_access_levels():
|
||||
print(al)
|
25
samples/get_cards.py
Normal file
25
samples/get_cards.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""
|
||||
Sample script to fetch all cards
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Obtain all Net2 cards
|
||||
print(Net2XS.dataset_to_str(net2.get_cards()))
|
26
samples/get_time_zones.py
Normal file
26
samples/get_time_zones.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""
|
||||
Sample script to fetch all time zones
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Show all time zones and their details
|
||||
for tz in net2.get_py_time_zones():
|
||||
print(tz)
|
25
samples/get_users.py
Normal file
25
samples/get_users.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""
|
||||
Sample script to fetch a dataset with all active users
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Obtain all Net2 users
|
||||
print(Net2XS.dataset_to_str(net2.get_users()))
|
51
samples/inheritance.py
Normal file
51
samples/inheritance.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""
|
||||
Sample script to demonstrate inheritance
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
class MyNet2XS(Net2XS):
|
||||
"""Inherited class for additional functionality
|
||||
"""
|
||||
global Net2XS
|
||||
|
||||
def get_current_user_id(self):
|
||||
"""Return logged on user id
|
||||
"""
|
||||
# Place a lock, for thread safety
|
||||
# (if you don't have threads you kan skip this)
|
||||
with Net2XS._lock:
|
||||
# Basic check if client connection is valid
|
||||
self._check_client()
|
||||
return self._client.CurrentUserID
|
||||
|
||||
def get_client_members(self):
|
||||
"""Return all Net2 client object members using the introspective
|
||||
Python dir function
|
||||
"""
|
||||
with Net2XS._lock:
|
||||
self._check_client()
|
||||
return dir(self._client)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with MyNet2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Show current user id
|
||||
print("Current used id:", net2.get_current_user_id())
|
||||
# Show all members
|
||||
print("Net2 client members:", net2.get_client_members())
|
51
samples/modify_user.py
Normal file
51
samples/modify_user.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""
|
||||
Sample script to modify a user.
|
||||
It assumes that a John Doe user exists (see add_user sample).
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
# First name
|
||||
FIRST_NAME = "John"
|
||||
# Surname
|
||||
SUR_NAME = "Doe"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
|
||||
# Get user id
|
||||
user_id = net2.get_user_id_by_name((FIRST_NAME, SUR_NAME))
|
||||
|
||||
print("Found user id %d" % (user_id))
|
||||
|
||||
# Found a valid user id
|
||||
if user_id >= 0:
|
||||
|
||||
# Modify expiration date
|
||||
res = net2.modify_user(
|
||||
user_id=user_id,
|
||||
expiry_date=datetime(2022, 12, 31))
|
||||
|
||||
if res:
|
||||
print("Success")
|
||||
else:
|
||||
print("Failure")
|
||||
|
||||
else:
|
||||
print("Failed to find user %s %s" % (FIRST_NAME, SUR_NAME))
|
51
samples/monitor_acu.py
Normal file
51
samples/monitor_acu.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""
|
||||
Sample script to monitor acu
|
||||
"""
|
||||
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
from time import sleep
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
# Acu to monitor
|
||||
ACU_ADDRESS = 1219195
|
||||
|
||||
|
||||
def handle_acu_event(sender, event_view):
|
||||
"""Handler for ACU event
|
||||
"""
|
||||
print("-----------------------")
|
||||
print("address=", event_view.Address)
|
||||
print("card=", event_view.CardNumber)
|
||||
print("department=", event_view.Department)
|
||||
print("userid=", event_view.UserId)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
|
||||
# Set function to handle ACU event
|
||||
net2.on_acu_event = handle_acu_event
|
||||
|
||||
res = net2.monitor_acu(ACU_ADDRESS)
|
||||
if not res:
|
||||
print("Failed to monitor ACU %d" % (ACU_ADDRESS))
|
||||
else:
|
||||
print("Monitoring ACU %d; press <ctrl>C to quit" % (ACU_ADDRESS))
|
||||
while True:
|
||||
try:
|
||||
sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
net2.stop_monitoring_acu(ACU_ADDRESS)
|
63
samples/open_all_doors.py
Normal file
63
samples/open_all_doors.py
Normal file
@ -0,0 +1,63 @@
|
||||
"""
|
||||
Sample script to hold all known doors open for a few seconds.
|
||||
Also shows how to use the logger function.
|
||||
"""
|
||||
import time
|
||||
from Net2Scripting import init_logging
|
||||
from Net2Scripting.net2xs import Net2XS
|
||||
from Net2Scripting.pylog4net import Log4Net
|
||||
|
||||
# Operator id 0 is System Engineer
|
||||
OPERATOR_ID = 0
|
||||
# Default Net2 password
|
||||
OPERATOR_PWD = "net2"
|
||||
# When running on the machine where Net2 is installed
|
||||
NET2_SERVER = "localhost"
|
||||
|
||||
|
||||
def get_doors(net2):
|
||||
"""Obtain a list of all known doors
|
||||
"""
|
||||
res = []
|
||||
dataset = net2.get_doors()
|
||||
if dataset and dataset.Tables.Count > 0:
|
||||
for row in dataset.Tables[0].Rows:
|
||||
res.append(row.Address)
|
||||
return res
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Init log4net
|
||||
init_logging()
|
||||
|
||||
# Create logger object
|
||||
logger = Log4Net.get_logger('open_all_doors')
|
||||
|
||||
with Net2XS(NET2_SERVER) as net2:
|
||||
# Authenticate
|
||||
net2.authenticate(OPERATOR_ID, OPERATOR_PWD)
|
||||
# Get list off door addresses
|
||||
doors = get_doors(net2)
|
||||
# Open each door
|
||||
for door in doors:
|
||||
if not net2.hold_door_open(door):
|
||||
logger.Error(
|
||||
"Failed to hold door %d open: %s." %
|
||||
(door, net2.last_error_message))
|
||||
else:
|
||||
logger.Info("Set door %d open." % (door))
|
||||
|
||||
logger.Info("Now all doors are open...")
|
||||
time.sleep(3)
|
||||
|
||||
# Close each door
|
||||
for door in doors:
|
||||
if not net2.close_door(door):
|
||||
logger.Error(
|
||||
"Failed to close door %d: %s." %
|
||||
(door, net2.last_error_message))
|
||||
else:
|
||||
logger.Info("Set door %d closed." % (door))
|
||||
|
||||
logger.Info("Now all doors are closed again")
|
Reference in New Issue
Block a user