diff --git a/.gitignore b/.gitignore index b1aa47b..665cde9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ -build -dist -dist_installer -docs/*.html -docs/index.htm +/build +/Net2Scripting.egg-info +/dist/*.tar.gz *.pyc #*# *~ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cdeb864 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/Net2Scripting.exe.config b/Net2Scripting/Net2Scripting.config similarity index 93% rename from src/Net2Scripting.exe.config rename to Net2Scripting/Net2Scripting.config index d7f3606..a4fe45b 100644 --- a/src/Net2Scripting.exe.config +++ b/Net2Scripting/Net2Scripting.config @@ -11,7 +11,7 @@ - + diff --git a/Net2Scripting/__init__.py b/Net2Scripting/__init__.py new file mode 100644 index 0000000..2a725eb --- /dev/null +++ b/Net2Scripting/__init__.py @@ -0,0 +1,29 @@ +""" +Main program for Net2Scripting. +Basically just intializes the log4net. +""" +import sys +import Net2Scripting.settings + + +def init_logging(config_file=None): + """Init logging + """ + # If no config file is given, use the default + if not config_file: + config_file = settings.CONFIG_FILE + + # Setup logging first + from Net2Scripting.pylog4net import Log4Net + try: + Log4Net.read_config(config_file) + except Exception as e: + print('Log error: %s' % (str(e))) + sys.exit(1) + + from Net2Scripting.config import Config + try: + cfg = Config(settings.CONFIG_FILE) + except Exception as e: + print('Config error: %s' % (str(e))) + sys.exit(1) diff --git a/src/config.py b/Net2Scripting/config.py similarity index 100% rename from src/config.py rename to Net2Scripting/config.py diff --git a/src/libs/log4netdll/log4net.dll b/Net2Scripting/libs/log4netdll/log4net.dll similarity index 100% rename from src/libs/log4netdll/log4net.dll rename to Net2Scripting/libs/log4netdll/log4net.dll diff --git a/src/libs/paxton/Paxton.Cryptography.dll b/Net2Scripting/libs/paxton/Paxton.Cryptography.dll similarity index 100% rename from src/libs/paxton/Paxton.Cryptography.dll rename to Net2Scripting/libs/paxton/Paxton.Cryptography.dll diff --git a/src/libs/paxton/Paxton.Net2.OEMClientLibrary.dll b/Net2Scripting/libs/paxton/Paxton.Net2.OEMClientLibrary.dll similarity index 100% rename from src/libs/paxton/Paxton.Net2.OEMClientLibrary.dll rename to Net2Scripting/libs/paxton/Paxton.Net2.OEMClientLibrary.dll diff --git a/src/libs/paxton/Paxton.Net2.Utils.dll b/Net2Scripting/libs/paxton/Paxton.Net2.Utils.dll similarity index 100% rename from src/libs/paxton/Paxton.Net2.Utils.dll rename to Net2Scripting/libs/paxton/Paxton.Net2.Utils.dll diff --git a/src/libs/paxton/Paxton.Remoting.Channel.dll b/Net2Scripting/libs/paxton/Paxton.Remoting.Channel.dll similarity index 100% rename from src/libs/paxton/Paxton.Remoting.Channel.dll rename to Net2Scripting/libs/paxton/Paxton.Remoting.Channel.dll diff --git a/src/libs/paxton/Paxton.Remoting.RemotingLayerInterfaces.dll b/Net2Scripting/libs/paxton/Paxton.Remoting.RemotingLayerInterfaces.dll similarity index 100% rename from src/libs/paxton/Paxton.Remoting.RemotingLayerInterfaces.dll rename to Net2Scripting/libs/paxton/Paxton.Remoting.RemotingLayerInterfaces.dll diff --git a/src/net2base/__init__.py b/Net2Scripting/net2base/__init__.py similarity index 100% rename from src/net2base/__init__.py rename to Net2Scripting/net2base/__init__.py diff --git a/src/net2dbxs/__init__.py b/Net2Scripting/net2dbxs/__init__.py similarity index 97% rename from src/net2dbxs/__init__.py rename to Net2Scripting/net2dbxs/__init__.py index cd24956..9fdc42d 100644 --- a/src/net2dbxs/__init__.py +++ b/Net2Scripting/net2dbxs/__init__.py @@ -10,8 +10,8 @@ clr.AddReference('System.Data') from System.Data.SqlClient import SqlConnection, SqlDataAdapter, SqlCommand from System.Data import DataSet, CommandType, ParameterDirection -from net2base import Net2Base -from pylog4net import Log4Net +from Net2Scripting.net2base import Net2Base +from Net2Scripting.pylog4net import Log4Net class Net2DBXSException(Exception): diff --git a/src/net2xs/__init__.py b/Net2Scripting/net2xs/__init__.py similarity index 99% rename from src/net2xs/__init__.py rename to Net2Scripting/net2xs/__init__.py index f1d8500..da61312 100644 --- a/src/net2xs/__init__.py +++ b/Net2Scripting/net2xs/__init__.py @@ -5,12 +5,12 @@ import clr import os import sys -import settings -from net2xs.conversions import date_time_to_net, flex_date_time_to_net, \ +import Net2Scripting.settings +from Net2Scripting.net2xs.conversions import date_time_to_net, flex_date_time_to_net, \ time_zones_to_py, access_levels_to_py, access_level_detail_to_py from datetime import datetime -from net2base import Net2Base -from pylog4net import Log4Net +from Net2Scripting.net2base import Net2Base +from Net2Scripting.pylog4net import Log4Net from threading import RLock from System import Array from System.Data import DataSet @@ -53,7 +53,7 @@ try: # Not found: enable the packaged paxton libs else: # Add path lib path to search path - PAXTON_LIB_DIR = os.path.join(settings.LIB_DIR, 'paxton') + PAXTON_LIB_DIR = os.path.join(Net2Scripting.settings.LIB_DIR, 'paxton') if PAXTON_LIB_DIR not in sys.path: sys.path.append(PAXTON_LIB_DIR) diff --git a/src/net2xs/conversions.py b/Net2Scripting/net2xs/conversions.py similarity index 100% rename from src/net2xs/conversions.py rename to Net2Scripting/net2xs/conversions.py diff --git a/src/net2xs/deftypes.py b/Net2Scripting/net2xs/deftypes.py similarity index 100% rename from src/net2xs/deftypes.py rename to Net2Scripting/net2xs/deftypes.py diff --git a/Net2Scripting/network/__init__.py b/Net2Scripting/network/__init__.py new file mode 100644 index 0000000..89c7374 --- /dev/null +++ b/Net2Scripting/network/__init__.py @@ -0,0 +1,3 @@ +""" +The module that offers several Net2 related network utilities +""" diff --git a/src/network/net2plus.py b/Net2Scripting/network/net2plus.py similarity index 100% rename from src/network/net2plus.py rename to Net2Scripting/network/net2plus.py diff --git a/src/network/sqlserver.py b/Net2Scripting/network/sqlserver.py similarity index 100% rename from src/network/sqlserver.py rename to Net2Scripting/network/sqlserver.py diff --git a/src/pylog4net/__init__.py b/Net2Scripting/pylog4net/__init__.py similarity index 95% rename from src/pylog4net/__init__.py rename to Net2Scripting/pylog4net/__init__.py index 68fc65f..5792ec1 100644 --- a/src/pylog4net/__init__.py +++ b/Net2Scripting/pylog4net/__init__.py @@ -5,7 +5,7 @@ import os import clr import sys -import settings +import Net2Scripting.settings as settings # Add path lib to search path LOG4NET_LIB_DIR = os.path.join(settings.LIB_DIR, 'log4netdll') @@ -13,7 +13,7 @@ if LOG4NET_LIB_DIR not in sys.path: sys.path.append(LOG4NET_LIB_DIR) clr.AddReference('log4net') -import log4net +import log4net as log4net from log4net.Config import XmlConfigurator clr.AddReference('System.Xml') from System.Xml import XmlDocument diff --git a/Net2Scripting/settings.py b/Net2Scripting/settings.py new file mode 100644 index 0000000..fbc6242 --- /dev/null +++ b/Net2Scripting/settings.py @@ -0,0 +1,9 @@ +import os + +BASE_DIR = os.path.dirname(__file__) + +# Default config file to use for dotnet stuff +CONFIG_FILE = os.path.join(BASE_DIR, 'Net2Scripting.config') + +# Generic lib dir +LIB_DIR = os.path.join(BASE_DIR, 'libs') diff --git a/README.md b/README.md index 857be55..ea5a063 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,54 @@ Net2Scripting === -Python scripting for the Paxton Net2 SDK. +Python scripting package for the Paxton Net2 SDK. -This project builds a setup file, that will install a Python scripting environment -that can communicate with Paxton Net2, using the SDK (or a direct DB connection). +This project offers a Python interface to the Paxton Net2 Access Control +system, using the SDK or or a direct DB connection. +It was originally a closed source project, that used py2exe to create an +executable. V4.0 was made open source, but still used py2exe. +From V5.0 onwards it will be a Python wheel package. -### Read this first -The scripts in this package are currently quite inflexible, in that they assume -that packages are installed in particular directories. For future versions this -should be changed to maybe an environment setting or a 'user' file containg the -definitions. (this file should be in .gitignore) +Have a look at the samples directory (github) to get an idea how to use it. +Note that it has slightly changed after becoming an installable Python package. -For now, the install directories are specificly marked in the requirements. +For the original py2exe version, pull the v4.0 tag. ### Requirements The NetScripting project relies on the following: - * An x86 Windows environment (64-bit did not work). Windows7-32bit should be ok. - * DotNet 4.0 - - Installing Paxton Net2 V5.x should take care of that + * A Windows environment. + * DotNet 4.0 or higher. + - Installing Paxton Net2 V5.x or higher should take care of that. - The Paxton Net2 OEMClientLibrary dlls (v5.01) are included in this package. - * Python x86 3.4.4 - - Is the Python environment - - Download from http://www.python.org - - **Install in C:\WinPrg\Python34\ !!!** - * pythonnet-2.3.0-cp34-cp34m-win32.whl - - Is Python .net extension - - Download from http://pythonnet.sourceforge.net - - Install with pip install - * py2exe-0.9.2.2-py33.py34-none-any.whl - - To create a python executable - - Download from http://www.py2exe.org - - Install with pip install - - Remove 'clr' in c:/WinPrg/Python34/lib/site-packages/py2exe/hooks.py !!! - - Note that py2exe does/did not support 3.5 and up yet - * Inno Setup 5.4.2 (higher versions most likely also work) - - To create an installer (uses the inno_script.iss) - - Download from http://www.jrsoftware.org - - **Install in C:\Program Files\Inno Setup 5\ !!!** + * pythonnet + - Should be automatically installed as a dependency. -The following batch files are available: - * run.bat - - To run de scripting tool while testing sample code - - It will wait after execution and run again after pressing enter (ctrl C=exit) - - Do no just click it in explorer; this will not work - - Create a sendTo shortcut to it, to execute python scripts from the explorer. - + type "shell:sento" in the file explorer address bar to access the - SentTo folder - + Create shortcut to run.bat and call it "Test with Net2Scripting" - * make.bat - - Creates an exe-based distro in ./dist - - You can click it in explorer - * build_installer.bat - - Requires make.bat to run first - - Creates a 'SetupNet2Scripting.exe' in ./dist_installer - - You can click it in explorer - -Beware of the following: - * That the doc's generated, need to be defined in src/docgen.py - * That for py2exe, new modules must be defined in 'Net2Scripting.py', - to have py2exe include them in the exe generation. - * That the makefile.bat will show warnings (which we ignore for now): +### Configuration +To use the log4net logging, you need to call the init_logging() method before +doing anything else. If no parameter is given, the default log setting is +used, which sets the application log level to DEBUG, the Paxton loglevel to +ERROR and writes to both console and a rolling log file at +${SystemDrive}/Net2 Access Control/Net2Scripting.log. +If you require non default settings, provide a path to your own config file +as parameter. There is a sample config file in the samples directory. + +### Building the wheel package file +In the directory containing setup.py run: ``` - 8 missing Modules - ------------------ -? Paxton imported from net2xs -? _dbm imported from dbm.ndbm -? log4net imported from pylog4net -? multiprocessing.SimpleQueue imported from concurrent.futures.process -? netbios imported from uuid -? win32evtlog imported from logging.handlers -? win32evtlogutil imported from logging.handlers -? win32wnet imported from uuid +python setup.py sdist bdist_wheel ``` +The resulting wheel file should pop up in the dist directory. -### Configuration -Runtime configuration file is: src/Net2Scripting.exe.config -(complies to the dotnet standard) +### Install + * Download the whl file from the dist directory. + * pip install Net2Scripting-X.Y.Z-py3-none-any.whl -### Version updates -To update the version number, adjust the following files: - * inno_script.iss - * src/settings.py - * docs/README.txt +### Uninstall + * pip uninstall Net2Scripting ### Todo * Unit tests - * Fix hard Python & InnoSetup paths * Add SDK features ### License diff --git a/build_installer.bat b/build_installer.bat deleted file mode 100644 index 733d32a..0000000 --- a/build_installer.bat +++ /dev/null @@ -1,10 +0,0 @@ -@echo off -del dist_installer\* /s/q > nul - -rem taskkill /IM explorer.exe /F -rem cd /d %userprofile%\AppData\Local -rem del IconCache.db /a -rem start explorer.exe - -"C:\Program Files\Inno Setup 5\ISCC.exe" inno_script.iss -pause diff --git a/dist/Net2Scripting-5.0.0-py3-none-any.whl b/dist/Net2Scripting-5.0.0-py3-none-any.whl new file mode 100644 index 0000000..1cd3a68 Binary files /dev/null and b/dist/Net2Scripting-5.0.0-py3-none-any.whl differ diff --git a/docs/Net2Scripting.png b/docs/Net2Scripting.png deleted file mode 100644 index e5f6ca6..0000000 Binary files a/docs/Net2Scripting.png and /dev/null differ diff --git a/docs/README.txt b/docs/README.txt deleted file mode 100644 index 20690bd..0000000 --- a/docs/README.txt +++ /dev/null @@ -1,121 +0,0 @@ -Net2Scripting -============= - -The Net2Scripting program is an add-on for the Paxton Net2 software. -It offers the possibility to run Python scripts against the Net2 SDK or -straight against the Net2 database. -Using the SDK, you can access remote Net2 servers. Using the direct database -interface, only local access is possible. - -Scripting allows ad-hoc functionality to be created, without compilation. -Useful for proof of concepts, filling Net2 with test data, simple door -control, Net2 data exports, etc. - -REQUIREMENTS -* A PC running a recent Windows version. The software has been tested on - WinXP(SP3), Win7 and Win8. -* Administrator rights. -* The Net2 V5.1 or higher software package. - -INSTALLATION -* Run the installer program, which will create an IntoAccess folder in the - Programs menu with a shortcut to Net2Scripting, install the executable, - libraries, samples and documentation. -* Optionally edit the Net2Scripting.exe.config file that can be found in the - program installation folder. - (by default it contains a reference to a sample script - 'samples/user_script.py') - -USAGE -* Option 1: Edit the Net2Scripting.exe.config file, changing the - 'user_script' setting to point to your script. Run the Net2Scripting - program. -* Option 2: Edit the Net2Scripting.exe.config file, adding more entries to - the 'appSetting' section. Run the Net2Scripting program adding the parameter - /k=, where points to the script you want to execute. -* Option 3: Run the Net2Scripting program, adding the path to the script you - wish to execute as parameter. -* If you run the Net2Scripting using the explorer, you may want the window - containing the script result to remain open. Set the appSetting - 'confirm_wait' to 'true' to have it wait for the key before closing. - If you want to run a script using a scheduler, set this option to 'false'. -* By default, the application logs fairly much and both to the console as - well as to a (rolling) file. Change the root 'level' value from DEBUG to - INFO, WARN, ERROR or FATAL to make it less verbose. You can add or remove - any log4net conpatible log appenders to suit your needs. - Beware that the scripting program locks the log file, so if you run more - than one instance, it will complain about not being able to log. - -DOCUMENTATION / HELP -* Some pydoc generated 'help' for the API is placed in the 'docs' - subdirectory of the installation folder. It does not hurt however to also - keep the Net2 API doc at hand while scripting. -* A number of script samples are provided, meant for those with some basic - knowledge of Python. For a full Python language reference, check out - http://www.python.org/doc/ - Not all Net2 SDK functions are available through the python api yet. - If you would like to add stuff however, check out the'inheritance.py' - sample to get you started. -* The (free) Net2Query tool, available at http://www.intoaccess.com, can - also of use to get some insight on available tables, column names and - data types. - -BACKGROUND -* Originally created by CRC Value. -* Maintained (sort of) by IntoAccess from July 2017 - May 2018. -* Open source from May 2018 onward. -* The package websites: - - http://www.net2scripting.nl - - https://github.com/cor-kalis/Net2Scripting - -ACKNOWLEDGEMENTS -* The Net2Scripting program is created using the following libraries/tools: - - Python => http://www.python.org - - Python.Net => http://pythonnet.sourceforge.net - - Py2exe => http://www.py2exe.org - - Paxton.Net2.OEMClientLibrary => http://www.paxton.co.uk - - Inno Setup => http://www.jrsoftware.org - -LICENSE -* MIT - -DISCLAIMER -* You will use this software at your own risk. No responsibility is accepted for - any damage it may accidentally cause. - -HISTORY -* V1.0 was published in April 2013. Initial version -* V1.1 was published in July 2013. - - Fixes a module scope issue (imported modules not recognized in functions). - - User image manipulation. - - Confirm wait, even on a sys.exit(). - - Allow remote native db access. - - Net2Plus module detection using udp broadcasts. - - SQLServer detection using udp broadcasts. - - Default values for add_user and modify_user (less hassle). -* V1.2 was published in July 2013. - - Enable linecache.getline by default, so 'list' in pdb.set_trace() shows - something useful. (disable in config by setting 'linecache_enable' to false) - - Added __scripting_version__ var, to test script compatibility. - - Fixed bug in Net2XS.deactivate_user fuction. -* V1.3 was published in September 2013. - - Fix / implement acu monitoring - - Fix get_users / get_user_by_id bug -* V1.4 was published in October 2013. - - Fix password encryption on remote native database connection -* V2.0 was published in April 2014. - - Net2 V5 compatible. -* V2.1 was published in July 2014. - - Fix hard coded event and subtype bug in add_event_record. -* V2.2 was published in October 2014. - - Removed misplaced delete_image parameter in add_user -* V2.3 was published in December 2015. - - Upgraded to Python 2.7.10 and included most standard Python modules. -* V2.4 was published in August 2016. - - Added the option to use either a dotnet or python date time objects for - the add_user and modify_user methods. - - Added delete_card and get_cards methods. -* V3.0 was published in August 2017. - - Upgrade to Python 3.4.4 -* V4.0 was published in May 2018. - - Made open source. diff --git a/inno_script.iss b/inno_script.iss deleted file mode 100644 index 6556235..0000000 --- a/inno_script.iss +++ /dev/null @@ -1,47 +0,0 @@ -; Script generated by the Inno Setup Script Wizard. -; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! - -#define MyAppName "Net2Scripting" -#define MyAppVersion "4.0" -#define MyAppPublisher "Net2Scripting" -#define MyAppURL "http://www.net2scripting.nl/" - -[Setup] -; NOTE: The value of AppId uniquely identifies this application. -; Do not use the same AppId value in installers for other applications. -; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) -AppId={{3940C8D4-5D5F-43CF-B92E-4086ED2198B2} -AppName={#MyAppName} -AppVersion={#MyAppVersion} -;AppVerName={#MyAppName} {#MyAppVersion} -AppPublisher={#MyAppPublisher} -AppPublisherURL={#MyAppURL} -AppSupportURL={#MyAppURL} -AppUpdatesURL={#MyAppURL} -DefaultDirName={pf}\Paxton Access/{#MyAppName} -DefaultGroupName=Paxton Access -InfoAfterFile=.\dist\docs\README.txt -OutputDir=.\dist_installer -OutputBaseFilename=SetupNet2Scripting -SetupIconFile=.\dist\resources\Net2Scripting.ico -Compression=lzma -SolidCompression=yes - -[Languages] -Name: "english"; MessagesFile: "compiler:Default.isl" - -[Tasks] -Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked - -[Files] -Source: ".\dist\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs -; NOTE: Don't use "Flags: ignoreversion" on any shared system files - -[Icons] -Name: "{group}\Net2Scripting"; Filename: "{app}\{#MyAppName}.exe" -Name: "{group}\Net2Scripting API"; Filename: "{app}\docs\index.htm" -Name: "{commondesktop}\Net2Scripting"; Filename: "{app}\{#MyAppName}.exe"; Tasks: desktopicon - -[Run] - -[UninstallRun] diff --git a/make.bat b/make.bat deleted file mode 100644 index 3a43801..0000000 --- a/make.bat +++ /dev/null @@ -1,21 +0,0 @@ -@echo off - -echo --- Cleaning... -del build\* /s/q > nul -del dist\* /s/q > nul -del docs\*.html /s/q > nul -echo --- Cleaning done - -echo --- Generating docs -cd src -c:/WinPrg/Python34/python docgen.py -cd .. -echo --- Generating docs done - -echo --- Building executable -cd src -c:/WinPrg/Python34/python setup.py py2exe -cd .. -echo --- Building executable done - -pause diff --git a/resources/Net2Scripting.ico b/resources/Net2Scripting.ico deleted file mode 100644 index b0faed6..0000000 Binary files a/resources/Net2Scripting.ico and /dev/null differ diff --git a/run.bat b/run.bat deleted file mode 100644 index 01348fa..0000000 --- a/run.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -cd src -:again -c:\WinPrg\Python34\python Net2Scripting.py %1 -pause -goto again diff --git a/runtime/Python.Runtime.dll b/runtime/Python.Runtime.dll deleted file mode 100644 index c2d6627..0000000 Binary files a/runtime/Python.Runtime.dll and /dev/null differ diff --git a/samples/Net2Scripting.config b/samples/Net2Scripting.config new file mode 100644 index 0000000..a4fe45b --- /dev/null +++ b/samples/Net2Scripting.config @@ -0,0 +1,43 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/samples/add_user.py b/samples/add_user.py similarity index 92% rename from src/samples/add_user.py rename to samples/add_user.py index 9b04ddf..e4fbfe0 100644 --- a/src/samples/add_user.py +++ b/samples/add_user.py @@ -2,7 +2,8 @@ Sample script to add a new user """ -from net2xs import Net2XS +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Uncomment to use dotnet DateTime objects # from System import DateTime @@ -21,6 +22,9 @@ NET2_SERVER = "localhost" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/add_users_with_card.py b/samples/add_users_with_card.py similarity index 91% rename from src/samples/add_users_with_card.py rename to samples/add_users_with_card.py index 9a60728..56afe8c 100644 --- a/src/samples/add_users_with_card.py +++ b/samples/add_users_with_card.py @@ -3,6 +3,8 @@ 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 @@ -14,6 +16,9 @@ NET2_SERVER = "localhost" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/direct_db_query.py b/samples/direct_db_query.py similarity index 95% rename from src/samples/direct_db_query.py rename to samples/direct_db_query.py index 4c1fc86..437af0c 100644 --- a/src/samples/direct_db_query.py +++ b/samples/direct_db_query.py @@ -2,7 +2,8 @@ Sample script to query the database directly """ -from net2dbxs import Net2DBXS +from Net2Scripting.net2dbxs import Net2DBXS + if __name__ == "__main__": diff --git a/src/samples/find_modules.py b/samples/find_modules.py similarity index 83% rename from src/samples/find_modules.py rename to samples/find_modules.py index a8eae8d..f1bb231 100644 --- a/src/samples/find_modules.py +++ b/samples/find_modules.py @@ -2,7 +2,7 @@ Sample script to detect Net2Plus modules """ -from network.net2plus import Net2PlusFinder +from Net2Scripting.network.net2plus import Net2PlusFinder if __name__ == "__main__": diff --git a/src/samples/find_sqlserver.py b/samples/find_sqlserver.py similarity index 83% rename from src/samples/find_sqlserver.py rename to samples/find_sqlserver.py index 8843be8..e94d993 100644 --- a/src/samples/find_sqlserver.py +++ b/samples/find_sqlserver.py @@ -2,7 +2,7 @@ Sample script to detect all SQLServer instances """ -from network.sqlserver import SqlServerFinder +from Net2Scripting.network.sqlserver import SqlServerFinder if __name__ == "__main__": diff --git a/src/samples/get_access_levels.py b/samples/get_access_levels.py similarity index 80% rename from src/samples/get_access_levels.py rename to samples/get_access_levels.py index ce1999c..558cc4d 100644 --- a/src/samples/get_access_levels.py +++ b/samples/get_access_levels.py @@ -2,7 +2,8 @@ Sample script to fetch all access levels """ -from net2xs import Net2XS +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -14,6 +15,9 @@ NET2_SERVER = "localhost" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/get_cards.py b/samples/get_cards.py similarity index 79% rename from src/samples/get_cards.py rename to samples/get_cards.py index 271e2f0..fe30e37 100644 --- a/src/samples/get_cards.py +++ b/samples/get_cards.py @@ -2,7 +2,8 @@ Sample script to fetch all cards """ -from net2xs import Net2XS +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -14,6 +15,9 @@ NET2_SERVER = "localhost" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/get_time_zones.py b/samples/get_time_zones.py similarity index 80% rename from src/samples/get_time_zones.py rename to samples/get_time_zones.py index dea89bd..05ee532 100644 --- a/src/samples/get_time_zones.py +++ b/samples/get_time_zones.py @@ -2,7 +2,8 @@ Sample script to fetch all time zones """ -from net2xs import Net2XS +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -14,6 +15,9 @@ NET2_SERVER = "localhost" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/user_script.py b/samples/get_users.py similarity index 80% rename from src/samples/user_script.py rename to samples/get_users.py index fe3cdb2..9648dc9 100644 --- a/src/samples/user_script.py +++ b/samples/get_users.py @@ -2,7 +2,8 @@ Sample script to fetch a dataset with all active users """ -from net2xs import Net2XS +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -14,6 +15,9 @@ NET2_SERVER = "localhost" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/inheritance.py b/samples/inheritance.py similarity index 91% rename from src/samples/inheritance.py rename to samples/inheritance.py index f22a901..9d06e34 100644 --- a/src/samples/inheritance.py +++ b/samples/inheritance.py @@ -2,7 +2,8 @@ Sample script to demonstrate inheritance """ -from net2xs import Net2XS +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -38,6 +39,9 @@ class MyNet2XS(Net2XS): if __name__ == "__main__": + # Init log4net + init_logging() + with MyNet2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/modify_user.py b/samples/modify_user.py similarity index 90% rename from src/samples/modify_user.py rename to samples/modify_user.py index e15ab11..51818e0 100644 --- a/src/samples/modify_user.py +++ b/samples/modify_user.py @@ -3,9 +3,9 @@ Sample script to modify a user. It assumes that a John Doe user exists (see add_user sample). """ -from net2xs import Net2XS from datetime import datetime - +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -22,6 +22,9 @@ SUR_NAME = "Doe" if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/monitor_acu.py b/samples/monitor_acu.py similarity index 91% rename from src/samples/monitor_acu.py rename to samples/monitor_acu.py index 7d91f7a..54aa206 100644 --- a/src/samples/monitor_acu.py +++ b/samples/monitor_acu.py @@ -2,9 +2,9 @@ Sample script to monitor acu """ +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS from time import sleep -from net2xs import Net2XS - # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -28,6 +28,9 @@ def handle_acu_event(sender, event_view): if __name__ == "__main__": + # Init log4net + init_logging() + with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) diff --git a/src/samples/open_all_doors.py b/samples/open_all_doors.py similarity index 90% rename from src/samples/open_all_doors.py rename to samples/open_all_doors.py index 978e0b1..6ec64fa 100644 --- a/src/samples/open_all_doors.py +++ b/samples/open_all_doors.py @@ -3,9 +3,9 @@ Sample script to hold all known doors open for a few seconds. Also shows how to use the logger function. """ import time - -from net2xs import Net2XS -from pylog4net import Log4Net +from Net2Scripting import init_logging +from Net2Scripting.net2xs import Net2XS +from Net2Scripting.pylog4net import Log4Net # Operator id 0 is System Engineer OPERATOR_ID = 0 @@ -28,6 +28,9 @@ def get_doors(net2): if __name__ == "__main__": + # Init log4net + init_logging() + # Create logger object logger = Log4Net.get_logger('open_all_doors') diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8b2264f --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="Net2Scripting", + version="5.0.0", + author="Cor Kalis", + author_email="info@net2scripting.nl", + description="Python scripting for Paxton Net2", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/cor-kalis/Net2Scripting", + packages=setuptools.find_packages(), + install_requires=[ + 'pythonnet' + ], + package_data={ + '': ['libs/log4netdll/*.dll', + 'libs/paxton/*.dll', + 'Net2Scripting.config' + ] + }, + classifiers=( + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: Microsoft :: Windows", + ) +) diff --git a/src/Net2Scripting.py b/src/Net2Scripting.py deleted file mode 100644 index c48f22e..0000000 --- a/src/Net2Scripting.py +++ /dev/null @@ -1,329 +0,0 @@ -""" -Main program for Net2Scripting. -""" -import os -import sys -import settings -import traceback - -# This is just to force py2exe to include these packages -if False == True: - import net2xs - import net2dbxs - import network - # Not required but nice to have - import abc - import aifc - import antigravity - import argparse - import ast - import asynchat - import asyncio - import asyncore - import base64 - import bdb - import binhex - import bisect - import bz2 - import cProfile - import calendar - import cgi - import cgitb - import chunk - import cmd - import code - import codecs - import codeop - import collections - import colorsys - import compileall - import concurrent - import configparser - import contextlib - import copy - import copyreg -# import crypt - import csv - import ctypes -# import curses - import datetime -# import dbm - import decimal - import difflib - import dis - import distutils - import doctest - import threading - import email - import encodings -# import ensurepip - import enum - import filecmp - import fileinput - import fnmatch - import formatter - import fractions - import ftplib - import functools - import genericpath - import getopt - import getpass - import gettext - import glob - import gzip - import hashlib - import heapq - import hmac - import html - import http - import idlelib - import imaplib - import imghdr - import imp - import importlib - import inspect - import io - import ipaddress - import json - import keyword - import lib2to3 - import linecache - import locale - import logging - import lzma -# import macpath -# import macurl2path - import mailbox - import mailcap - import mimetypes - import modulefinder - import msilib -# import multiprocessing - import netrc - import nntplib - import ntpath - import nturl2path - import numbers - import opcode - import operator - import optparse - import os - import pathlib - import pdb - import pickle - import pickletools - import pipes - import pkgutil - import platform - import plistlib - import poplib - import posixpath - import pprint - import profile - import pstats - import pty - import pyclbr - import pydoc - import pydoc_data - import queue - import quopri - import random - import re - import reprlib - import rlcompleter - import runpy - import sched - import selectors - import shelve - import shlex - import shutil - import site -# import smtpd - import smtplib - import sndhdr - import socket - import socketserver - import sqlite3 -# import compile -# import constants -# import parse - import ssl - import stat - import statistics - import string - import stringprep - import struct - import subprocess - import sunau - import symbol - import symtable - import sysconfig - import tabnanny - import tarfile - import telnetlib - import tempfile - import test - import textwrap - import this - import threading - import timeit - import tkinter - import token - import tokenize - import trace - import traceback - import tracemalloc - import tty - import turtle - import turtledemo - import types - import unittest - import urllib - import uu - import uuid - import venv - import warnings - import wave - import weakref - import webbrowser - import wsgiref - import xdrlib - import xml - import xmlrpc - import zipfile - - -# Setup logging first -from pylog4net import Log4Net -try: - Log4Net.read_config(settings.CONFIG_FILE) -except Exception as e: - print('Log error: %s' % (str(e))) - sys.exit(1) - -from config import Config -try: - cfg = Config(settings.CONFIG_FILE) -except Exception as e: - print('Config error: %s' % (str(e))) - sys.exit(1) - -# Running as py2exe: check if linecache should be enabled -# if hasattr(sys, 'frozen'): -# if cfg.get("enable_linecache", True, bool): -# # Monkey patch it back to the original value -# import linecache -# linecache.getline = linecache.orig_getline -# del linecache - -# Log4net logger -logger = Log4Net.get_logger('Net2Scripting') - - -def run(script_file): - """Run script file - """ - try: - if not os.path.isfile(script_file): - raise Exception("User script '%s' does not exist!" % (script_file)) - - # Get script dir and add it to the module search path - sys.path.insert(0, os.path.dirname(script_file)) - - print("Press ' C' to quit...") - logger.Debug("Calling user script '%s'" % (script_file)) - try: - # Strip Net2Scripting param from arguments - sys.argv = sys.argv[1:] - # Explicitly provide dict, to prevent scope issues - with open(script_file) as f: - code = compile(f.read(), script_file, 'exec') - exec(code, - {"__name__": "__main__", - "__file__": script_file, - "__scripting_version__": settings.VERSION}) - except KeyboardInterrupt: - logger.Debug("User interrupt") - - except Exception as ex: - - msg = "Fatal error: " + str(ex) - if cfg.get("log_stacktrace", default=False, vtype=bool): - msg += "\n" + traceback.format_exc() - logger.Fatal(msg) - return 1 - - -def run_key(script_key): - """Run file referenced by setting keyword - """ - try: - script_key = script_key.strip() - if not script_key: - raise "The provided script keyword is empty!" - - # Fetch setting from config - cfg.check_required([(script_key, str)]) - - return run(cfg.get(script_key)) - - except Exception as ex: - logger.Fatal("Fatal error: " + str(ex)) - return 1 - - -def confirm_wait(): - """Wait for user confirmation - """ - # Fetch setting from config - wait = cfg.get("confirm_wait", default=False, vtype=bool) - if wait: - print() - input("Press enter to continue: ") - - -# Main program entry -if __name__ == '__main__': - - ret_val = 0 - - try: - if len(sys.argv) > 1: - arg = sys.argv[1] - - if arg == "/?": - print() - print("Net2Scripting V%s, by Net2 Solutions" % (settings.VERSION)) - print() - print(" /? = help") - print(" /k:keyword = run script referenced by appSettings keyword") - print("