Re: [concordance-devel] Latest Python bindings

2008-04-08 Thread Phil Dibowitz
Stephen Warren wrote:
> Attached is the latest libconcord.py file, to match recent libconcord.h
> changes.
> 
> Also included is a setup.py file, to go in the same directory. This is
> essentially an install script; a standard thing to include when
> distributing any Python module.

Applied, thanks.

-- 
Phil Dibowitz [EMAIL PROTECTED]
Open Source software and tech docsInsanity Palace of Metallica
http://www.phildev.net/   http://www.ipom.com/

"Never write it in C if you can do it in 'awk';
 Never do it in 'awk' if 'sed' can handle it;
 Never use 'sed' when 'tr' can do the job;
 Never invoke 'tr' when 'cat' is sufficient;
 Avoid using 'cat' whenever possible" -- Taylor's Laws of Programming




signature.asc
Description: OpenPGP digital signature
-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Register now and save $200. Hurry, offer ends at 11:59 p.m., 
Monday, April 7! Use priority code J8TLD2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone___
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel


[concordance-devel] Latest Python bindings

2008-04-07 Thread Stephen Warren
Attached is the latest libconcord.py file, to match recent libconcord.h
changes.

Also included is a setup.py file, to go in the same directory. This is
essentially an install script; a standard thing to include when
distributing any Python module.
# This code NOT copyright Stephen Warren <[EMAIL PROTECTED]>
# This code is released into the public domain.

from ctypes import *
import platform
import sys

# Internal DLL handle
if platform.system() == 'Windows':
_dll = cdll.LoadLibrary('libconcord.dll')
else:
_dll = cdll.LoadLibrary('libconcord.so.0')

# This exception may be raised by any function that returns an LC_ERROR_*.
class LibConcordException(Exception):
def __init__(self, func, result):
self.func = func
self.result = result
try:
self.result_str = c_char_p(_dll.lc_strerror(c_int(self.result))).value
except:
self.result_str = 'Unknown'

def __str__(self):
return 'libconcord function %s failed with error code %s (%s)' % (
repr(self.func),
repr(self.result),
repr(self.result_str)
)

# Internal function result checking functionality
class _CheckRetCode(object):
def __init__(self, func_name):
self.func_name = func_name

def __call__(self, *args):
result = args[0]
if result != 0:
raise LibConcordException(self.func_name, result)

# Internal ctypes function wrapper creation
def _create_func(
func_name,
error_checker,
*args
):
ftype = CFUNCTYPE(*args)
f = ftype((func_name, _dll))
if error_checker:
f.errcheck = error_checker(func_name)
return f

# typedef void (*lc_callback)(uint32_t, uint32_t, uint32_t, void*);
callback_type = CFUNCTYPE(None, c_uint, c_uint, c_uint, py_object)

# const char *get_mfg();
get_mfg = _create_func(
'get_mfg',
None,
c_char_p
)

# const char *get_model();
get_model = _create_func(
'get_model',
None,
c_char_p
)

# const char *get_codename();
get_codename = _create_func(
'get_codename',
None,
c_char_p
)

# int get_skin();
get_skin = _create_func(
'get_skin',
None,
c_int
)

# int get_fw_ver_maj();
get_fw_ver_maj = _create_func(
'get_fw_ver_maj',
None,
c_int
)

# int get_fw_ver_min();
get_fw_ver_min = _create_func(
'get_fw_ver_min',
None,
c_int
)

# int get_fw_type();
get_fw_type = _create_func(
'get_fw_type',
None,
c_int
)

# int get_hw_ver_maj();
get_hw_ver_maj = _create_func(
'get_hw_ver_maj',
None,
c_int
)

# int get_hw_ver_min();
get_hw_ver_min = _create_func(
'get_hw_ver_min',
None,
c_int
)

# int get_flash_size();
get_flash_size = _create_func(
'get_flash_size',
None,
c_int
)

# int get_flash_mfg();
get_flash_mfg = _create_func(
'get_flash_mfg',
None,
c_int
)

# int get_flash_id();
get_flash_id = _create_func(
'get_flash_id',
None,
c_int
)

# const char *get_flash_part_num();
get_flash_part_num = _create_func(
'get_flash_part_num',
None,
c_char_p
)

# int get_arch();
get_arch = _create_func(
'get_arch',
None,
c_int
)

# int get_proto();
get_proto = _create_func(
'get_proto',
None,
c_int
)

# const char *get_hid_mfg_str();
get_hid_mfg_str = _create_func(
'get_hid_mfg_str',
None,
c_char_p
)

# const char *get_hid_prod_str();
get_hid_prod_str = _create_func(
'get_hid_prod_str',
None,
c_int
)

# int get_hid_irl();
get_hid_irl = _create_func(
'get_hid_irl',
None,
c_int
)

# int get_hid_orl();
get_hid_orl = _create_func(
'get_hid_orl',
None,
c_int
)

# int get_hid_frl();
get_hid_frl = _create_func(
'get_hid_frl',
None,
c_int
)

# int get_usb_vid();
get_usb_vid = _create_func(
'get_usb_vid',
None,
c_int
)

# int get_usb_pid();
get_usb_pid = _create_func(
'get_usb_pid',
None,
c_int
)

# int get_usb_bcd();
get_usb_bcd = _create_func(
'get_usb_bcd',
None,
c_int
)

SERIAL_COMPONENT_1 = 1
SERIAL_COMPONENT_2 = 2
SERIAL_COMPONENT_3 = 3

# char *get_serial(int p);
get_serial = _create_func(
'get_serial',
None,
c_char_p,
c_int
)

# int get_config_bytes_used();
get_config_bytes_used = _create_func(
'get_config_bytes_used',
None,
c_int
)

# int get_config_bytes_total();
get_config_bytes_total = _create_func(
'get_config_bytes_total',
None,
c_int
)

# int get_time_second();
get_time_second = _create_func(
'get_time_second',
None,
c_int
)

# int get_time_minute();
get_time_minute = _create_func(
'get_time_minute',
None,
c_int
)

# int get_time_hour();
get_time_hour = _create_func(
'get_time_hour',
None,
c_int
)

# int get_time_day();
get_time_day = _create_func(
'get_time_day',
None,
c_int
)

# int get_time_dow();
get_time_dow = _create_func(
'get_time_dow',
None,
c_int
)

# int get_time_month();
get_time_month = _create_