Skip to content

Commit

Permalink
python: Merge test/pytest/testlib as main python package
Browse files Browse the repository at this point in the history
... and prepare for publishing to pypi. The old "raw wrapper" is now
called osdp_sys and testlib replaces it the main osdp module.

Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Nov 22, 2023
1 parent af47df7 commit b9b04c7
Show file tree
Hide file tree
Showing 33 changed files with 318 additions and 243 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ config.make
__pycache__/
.cache/
*.pyc
.venv/

## Rust
/Cargo.lock
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ include(GitSubmodules)
add_subdirectory(utils)
add_subdirectory(src)
if (NOT CONFIG_OSDP_STATIC_PD AND NOT CONFIG_OSDP_LIB_ONLY)
add_subdirectory(tests/pytest)
add_subdirectory(tests/unit-tests)
add_subdirectory(samples/c)
add_subdirectory(samples/cpp)
Expand Down
3 changes: 3 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.egg-info/
build/
dist/
41 changes: 0 additions & 41 deletions python/CMakeLists.txt

This file was deleted.

File renamed without changes.
71 changes: 71 additions & 0 deletions python/osdp/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Copyright (c) 2021-2023 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

import osdp_sys

class LibFlag:
EnforceSecure = osdp_sys.FLAG_ENFORCE_SECURE
InstallMode = osdp_sys.FLAG_INSTALL_MODE
IgnoreUnsolicited = osdp_sys.FLAG_IGN_UNSOLICITED

class LogLevel:
Emergency = osdp_sys.LOG_EMERG
Alert = osdp_sys.LOG_ALERT
Critical = osdp_sys.LOG_CRIT
Error = osdp_sys.LOG_ERROR
Warning = osdp_sys.LOG_WARNING
Notice = osdp_sys.LOG_NOTICE
Info = osdp_sys.LOG_INFO
Debug = osdp_sys.LOG_DEBUG

class Command:
Output = osdp_sys.CMD_OUTPUT
Buzzer = osdp_sys.CMD_BUZZER
LED = osdp_sys.CMD_LED
Comset = osdp_sys.CMD_COMSET
Text = osdp_sys.CMD_TEXT
Manufacturer = osdp_sys.CMD_MFG
Keyset = osdp_sys.CMD_KEYSET
FileTransfer = osdp_sys.CMD_FILE_TX

class CommandLEDColor:
Black = osdp_sys.LED_COLOR_NONE
Red = osdp_sys.LED_COLOR_RED
Green = osdp_sys.LED_COLOR_GREEN
Amber = osdp_sys.LED_COLOR_AMBER
Blue = osdp_sys.LED_COLOR_BLUE

class CommandFileTxFlags:
Cancel = osdp_sys.CMD_FILE_TX_FLAG_CANCEL

class Event:
CardRead = osdp_sys.EVENT_CARDREAD
KeyPress = osdp_sys.EVENT_KEYPRESS
ManufacturerReply = osdp_sys.EVENT_MFGREP
InputOutput = osdp_sys.EVENT_IO
Status = osdp_sys.EVENT_STATUS

class CardFormat:
Unspecified = osdp_sys.CARD_FMT_RAW_UNSPECIFIED
Wiegand = osdp_sys.CARD_FMT_RAW_WIEGAND
ASCII = osdp_sys.CARD_FMT_ASCII

class Capability:
Unused = osdp_sys.CAP_UNUSED
ContactStatusMonitoring = osdp_sys.CAP_CONTACT_STATUS_MONITORING
OutputControl = osdp_sys.CAP_OUTPUT_CONTROL
CardDataFormat = osdp_sys.CAP_CARD_DATA_FORMAT
LEDControl = osdp_sys.CAP_READER_LED_CONTROL
AudibleControl = osdp_sys.CAP_READER_AUDIBLE_OUTPUT
TextOutput = osdp_sys.CAP_READER_TEXT_OUTPUT
TimeKeeping = osdp_sys.CAP_TIME_KEEPING
CheckCharacter = osdp_sys.CAP_CHECK_CHARACTER_SUPPORT
CommunicationSecurity = osdp_sys.CAP_COMMUNICATION_SECURITY
ReceiveBufferSize = osdp_sys.CAP_RECEIVE_BUFFERSIZE
CombinedMessageSize = osdp_sys.CAP_LARGEST_COMBINED_MESSAGE_SIZE
SmartCard = osdp_sys.CAP_SMART_CARD_SUPPORT
Readers = osdp_sys.CAP_READERS
Biometrics = osdp_sys.CAP_BIOMETRICS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import os
import tempfile
import osdp
import osdp_sys
import time
import queue
import threading
Expand All @@ -25,9 +25,9 @@ def __init__(self, pd_info_list, log_level: LogLevel=LogLevel.Info,
info_list.append(pd_info.get())
self.event_queue = [ queue.Queue() for i in self.pd_addr ]
if master_key:
self.ctx = osdp.ControlPanel(info_list, master_key=master_key)
self.ctx = osdp_sys.ControlPanel(info_list, master_key=master_key)
else:
self.ctx = osdp.ControlPanel(info_list)
self.ctx = osdp_sys.ControlPanel(info_list)
self.ctx.set_event_callback(self.event_handler)
self.ctx.set_loglevel(log_level)
self.event = None
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0
#

import osdp
import osdp_sys
import time
import queue
import threading
Expand All @@ -17,7 +17,7 @@ def __init__(self, pd_info: PDInfo, pd_cap: PDCapabilities,
log_level: LogLevel=LogLevel.Info):
self.command_queue = queue.Queue()
self.address = pd_info.address
self.ctx = osdp.PeripheralDevice(pd_info.get(), capabilities=pd_cap.get())
self.ctx = osdp_sys.PeripheralDevice(pd_info.get(), capabilities=pd_cap.get())
self.ctx.set_loglevel(log_level)
self.ctx.set_command_callback(self.command_handler)
self.event = None
Expand Down
2 changes: 1 addition & 1 deletion python/pyosdp_base.c → python/osdp_sys/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "pyosdp.h"
#include "module.h"

#define TAG "pyosdp_base"

Expand Down
2 changes: 1 addition & 1 deletion python/pyosdp_cp.c → python/osdp_sys/cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "pyosdp.h"
#include "module.h"

#define TAG "pyosdp_cp"

Expand Down
2 changes: 1 addition & 1 deletion python/pyosdp_data.c → python/osdp_sys/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "pyosdp.h"
#include "module.h"

/* ------------------------------- */
/* COMMANDS */
Expand Down
10 changes: 5 additions & 5 deletions python/pyosdp.c → python/osdp_sys/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "pyosdp.h"
#include "module.h"
#include <stdio.h>

static PyModuleDef osdp_module = {
static PyModuleDef osdp_sys_module = {
PyModuleDef_HEAD_INIT,
.m_name = "osdp",
.m_name = "osdp_sys",
.m_doc = "Open Supervised Device Protocol",
.m_size = -1,
};
Expand Down Expand Up @@ -90,11 +90,11 @@ void pyosdp_add_module_constants(PyObject *module)
#undef ADD_CONST
}

PyMODINIT_FUNC PyInit_osdp(void)
PyMODINIT_FUNC PyInit_osdp_sys(void)
{
PyObject *module;

module = PyModule_Create(&osdp_module);
module = PyModule_Create(&osdp_sys_module);
if (module == NULL)
return NULL;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion python/pyosdp_pd.c → python/osdp_sys/pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "pyosdp.h"
#include "module.h"

#define TAG "pyosdp_pd"

Expand Down
4 changes: 2 additions & 2 deletions python/pyosdp_utils.c → python/osdp_sys/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "pyosdp.h"
#include "module.h"

int pyosdp_dict_add_bool(PyObject *dict, const char *key, bool val)
{
Expand Down Expand Up @@ -226,4 +226,4 @@ int pyosdp_dict_get_object(PyObject *dict, const char *key, PyObject **obj)
return -1;

return 0;
}
}
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools >= 57.2.0", "wheel"]
requires = ["setuptools >= 57.2.0"]
build-backend = "setuptools.build_meta"
Loading

0 comments on commit b9b04c7

Please sign in to comment.