Skip to content

Commit

Permalink
Merge pull request #15 from PerryWerneck/python
Browse files Browse the repository at this point in the history
Add Python module
  • Loading branch information
PerryWerneck authored Jul 26, 2023
2 parents 420bff1 + 0fa9669 commit 55cc830
Show file tree
Hide file tree
Showing 16 changed files with 858 additions and 19 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/winpkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: WinPackage
on:
push:
branches:
- python
pull_request:
branches:
- master
jobs:
win32-pack:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: oprypin/find-latest-tag@v1
id: gettag
with:
repository: PerryWerneck/dmiget # The repository to scan.
releases-only: true # We know that all relevant tags have a GitHub release for them.
- uses: ilammy/msvc-dev-cmd@v1.4.1
- name: Set up Python
uses: actions/setup-python@v4
- name: Build installer
run: python setup.py bdist_wininst
- uses: ncipollo/release-action@v1
with:
tag: ${{ steps.gettag.outputs.tag }}
artifacts: "dist/*.exe"
allowUpdates: true
draft: false
makeLatest: true
omitBody: true
omitPrereleaseDuringUpdate: true
replacesArtifacts: true

55 changes: 46 additions & 9 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@

PACKAGE_NAME=@PACKAGE_NAME@
PRODUCT_NAME=@PRODUCT_NAME@
PYTHON_MODULE=smbios

LIBRARY_SOURCES= \
$(wildcard src/libdmiget/*.cc) \
$(wildcard src/libdmiget/decoders/*.cc) \
$(wildcard src/libdmiget/os/@OSNAME@/*.cc)

PYTHON_SOURCES= \
$(wildcard src/python/*.c) \
$(wildcard src/python/*.cc)

APPLICATION_SOURCES= \
$(wildcard src/dmiget/*.cc)

BUILD_TARGETS=@BUILD_TARGETS@
TARGETS=@OSNAME@-lib devel application

#---[ Tools ]----------------------------------------------------------------------------

CXX=@CXX@
CC=@CC@
LD=@CXX@
LN_S=@LN_S@
MKDIR=@MKDIR_P@
Expand Down Expand Up @@ -65,11 +69,11 @@ PYTHON_SITELIB=@PYTHON_SITELIB@

BASEDIR=@BASEDIR@

OBJDIR=$(BASEDIR)/.obj
OBJDIR=.obj
OBJDBG=$(OBJDIR)/Debug
OBJRLS=$(OBJDIR)/Release

BINDIR=$(BASEDIR)/.bin
BINDIR=.bin
BINDBG=$(BINDIR)/Debug
BINRLS=$(BINDIR)/Release

Expand Down Expand Up @@ -114,6 +118,24 @@ $(OBJDBG)/%.o: \
-o $@ \
-c $<

$(OBJDBG)/%.o: \
%.c

@echo $< ...
@$(MKDIR) $(dir $@)

@$(CC) \
$(CFLAGS) \
-DDEBUG=1 \
-MM -MT $@ -MF $(patsubst %.o,%.d,$@) $<

@$(CC) \
$(CFLAGS) \
-Wall -Wextra -fstack-check \
-DDEBUG=1 \
-o $@ \
-c $<

$(OBJDBG)/%.o: \
%.rc

Expand Down Expand Up @@ -142,6 +164,24 @@ $(OBJRLS)/%.o: \
-o $@ \
-c $<

$(OBJRLS)/%.o: \
%.c

@echo $< ...
@$(MKDIR) $(dir $@)

@$(CC) \
$(CFLAGS) \
-DNDEBUG=1 \
-MM -MT $@ -MF $(patsubst %.o,%.d,$@) $<

@$(CC) \
$(CFLAGS) \
-Wall -Wextra -fstack-check \
-DNDEBUG=1 \
-o $@ \
-c $<

$(OBJRLS)/%.o: \
%.rc

Expand All @@ -152,13 +192,11 @@ $(OBJRLS)/%.o: \
#---[ Release Targets ]------------------------------------------------------------------

all: \
$(BINRLS)/@SONAME@ \
$(BINRLS)/$(PACKAGE_NAME)@EXEEXT@ \
$(foreach TARGET, $(BUILD_TARGETS), $(BINRLS)/$(TARGET)) \
$(BINRLS)/libdmiget.static.a

Release: \
$(BINRLS)/@SONAME@ \
$(BINRLS)/$(PACKAGE_NAME)@EXEEXT@
$(foreach TARGET, $(BUILD_TARGETS), $(BINRLS)/$(TARGET))

$(BINRLS)/@SONAME@: \
$(foreach SRC, $(basename $(LIBRARY_SOURCES)), $(OBJRLS)/$(SRC).o)
Expand Down Expand Up @@ -304,8 +342,7 @@ uninstall-devel:
#---[ Debug Targets ]--------------------------------------------------------------------

Debug: \
$(BINDBG)/$(PACKAGE_NAME)@EXEEXT@ \
$(BINDBG)/py$(PACKAGE_NAME)@DLLEXT@
$(foreach TARGET, $(BUILD_TARGETS), $(BINDBG)/$(TARGET))

$(BINDBG)/$(PACKAGE_NAME)@EXEEXT@: \
$(foreach SRC, $(basename $(APPLICATION_SOURCES)), $(OBJDBG)/$(SRC).o) \
Expand Down Expand Up @@ -336,7 +373,7 @@ $(BINDBG)/@SONAME@: \
$^ \
$(LIBS)

$(BINDBG)/py$(PACKAGE_NAME)@DLLEXT@: \
$(BINDBG)/$(PYTHON_MODULE)@LIBEXT@: \
$(foreach SRC, $(basename $(PYTHON_SOURCES)), $(OBJDBG)/$(SRC).o) \
$(BINDBG)/@SONAME@

Expand Down
2 changes: 1 addition & 1 deletion PKGBUILD.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ url="https://github.com/PerryWerneck/dmiget"
arch=(i686 x86_64)
license=(GPL)
depends=()
makedepends=(autoconf automake make libtool gzip python)
makedepends=(autoconf automake make libtool gzip)
checkdepends=()

provides=($pkgname)
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
You can download installation package for supported linux distributions in [Open Build Service](https://software.opensuse.org/download.html?project=home%3APerryWerneck%3Audjat&package=dmiget)

[<img src="https://raw.githubusercontent.com/PerryWerneck/pw3270/develop/branding/obs-badge-en.svg" alt="Download from open build service" height="80px">](https://software.opensuse.org/download.html?project=home%3APerryWerneck%3Audjat&package=dmiget)
[<img src="https://github.com/PerryWerneck/PerryWerneck/blob/master/badges/msys-msvc-badge.svg" alt="Download from githut" height="80px">](https://github.com/PerryWerneck/dmiget/releases)
[<img src="https://github.com/PerryWerneck/PerryWerneck/blob/master/badges/msys-msvc-python-badge.svg" alt="Download from githut" height="80px">](https://github.com/PerryWerneck/dmiget/releases)

## Examples:

Command-line:
### Command line

```shell
dmiget dmi://bios/vendor
```

### Python

```python
import smbios
value = smbios.value('chassis','serial')
print(value)
```
19 changes: 13 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ case "$host" in
CFLAGS="$CFLAGS -pthread "
LDFLAGS="$LDFLAGS -pthread"
DLL_LDFLAGS="$DLL_LDFLAGS -Wl,--output-def,\$(@D)/libdmiget.def"
BUILD_TARGETS="${BUILD_TARGETS} dmiget.exe"
AC_SUBST(LIBEXT,.dll)
AC_SUBST(EXEEXT,.exe)
AC_SUBST(SONAME,libdmiget.dll)
Expand All @@ -75,6 +76,7 @@ case "$host" in
CFLAGS="$CFLAGS -pthread"
CXXFLAGS="$CXXFLAGS -pthread -ffat-lto-objects"
LDFLAGS="$LDFLAGS -pthread"
BUILD_TARGETS="${BUILD_TARGETS} dmiget"
AC_SUBST(LIBEXT,.so)
AC_SUBST(EXEEXT)
AC_SUBST(SONAME,libdmiget.so.$app_vrs_major.$app_vrs_minor)
Expand Down Expand Up @@ -213,6 +215,16 @@ PKG_CHECK_MODULES( [PYTHON], [python3], app_cv_python="yes", AC_MSG_NOTICE([Pyth

if test "$app_cv_python" == "yes"; then

case "$host" in
*-mingw32)
BUILD_TARGETS="${BUILD_TARGETS} smbios.dll"
;;

*)
BUILD_TARGETS="${BUILD_TARGETS} smbios.so"

esac

AC_DEFINE(HAVE_PYTHON3,1,[ Do we have python3? ])

AC_SUBST(PYTHON_LIBS)
Expand All @@ -228,12 +240,6 @@ if test "$app_cv_python" == "yes"; then

fi

dnl ---------------------------------------------------------------------------
dnl Output config
dnl ---------------------------------------------------------------------------

AC_SUBST(BASEDIR,$ac_pwd)

dnl ---------------------------------------------------------------------------
dnl Configure which files to generate.
dnl ---------------------------------------------------------------------------
Expand All @@ -242,6 +248,7 @@ dnl AC_CONFIG_FILES(doxygen/doxyfile)
AC_CONFIG_FILES(Makefile)
AC_CONFIG_FILES(dmiget.pc)
AC_CONFIG_FILES(dmiget.static.pc)
AC_SUBST(BUILD_TARGETS)

dnl ---------------------------------------------------------------------------
dnl Output the generated config.status script.
Expand Down
10 changes: 10 additions & 0 deletions dmiget.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,26 @@
<Unit filename="src/libdmiget/include/dmiget/table.h" />
<Unit filename="src/libdmiget/include/dmiget/value.h" />
<Unit filename="src/libdmiget/include/internals.h" />
<Unit filename="src/libdmiget/include/pydmiget.h" />
<Unit filename="src/libdmiget/os/linux/file.cc" />
<Unit filename="src/libdmiget/os/linux/node.cc" />
<Unit filename="src/libdmiget/os/linux/private.h" />
<Unit filename="src/libdmiget/os/linux/reader.cc" />
<Unit filename="src/libdmiget/os/linux/table.cc" />
<Unit filename="src/libdmiget/os/linux/value.cc" />
<Unit filename="src/libdmiget/os/windows/file.cc" />
<Unit filename="src/libdmiget/os/windows/native_win32.h" />
<Unit filename="src/libdmiget/os/windows/table.cc" />
<Unit filename="src/libdmiget/string.cc" />
<Unit filename="src/libdmiget/table.cc" />
<Unit filename="src/libdmiget/value.cc" />
<Unit filename="src/python/init.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/python/moduleinfo.cc" />
<Unit filename="src/python/node.cc" />
<Unit filename="src/python/private.h" />
<Unit filename="src/python/value.cc" />
<Extensions />
</Project>
</CodeBlocks_project_file>
6 changes: 6 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
rm -fr build
python3 setup.py build

PYTHONPATH=$(readlink -f ./build/lib.linux-x86_64-3.6) python3

64 changes: 64 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/python
#-*- coding: utf-8

from setuptools import setup, Extension
import platform
import os
import glob

include_dirs = ['src/libdmiget/include']
library_dirs = []
extra_link_args = []
library_names = [ ]
src_files = [ ]

for filename in glob.glob("src/libdmiget/*.cc"):
src_files.append(filename)

for filename in glob.glob("src/libdmiget/decoders/*.cc"):
src_files.append(filename)

for filename in glob.glob("src/python/*.cc"):
src_files.append(filename)

for filename in glob.glob("src/python/*.c"):
src_files.append(filename)

if platform.system() == 'Windows':

for filename in glob.glob("src/libdmiget/os/windows/*.cc"):
src_files.append(filename)

else:

for filename in glob.glob("src/libdmiget/os/linux/*.cc"):
src_files.append(filename)

smbios = Extension(
'smbios',
include_dirs = include_dirs,
libraries = library_names,
library_dirs=library_dirs,
extra_link_args=extra_link_args,
sources=src_files
)

package_version='0.1'
with open(r'configure.ac', 'r') as fp:
lines = fp.readlines()
for line in lines:
if line.find('AC_INIT') != -1:
package_version = line.split('[')[2].split(']')[0].strip()
break;

setup ( name = 'smbios',
version = package_version,
description = 'Python library to read data from SMBIOS/DMI.',
author = 'Perry Werneck',
author_email = 'perry.werneck@gmail.com',
url = 'https://github.com/PerryWerneck/dmiget',
long_description = '''
This is an extension allowing smibios/dmi read for python applications.
''',
ext_modules = [ smbios ])

4 changes: 3 additions & 1 deletion src/libdmiget/include/dmiget/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
#include <dmiget/defs.h>
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus

#include <functional>
#include <string>
#include <memory>

#ifdef __cplusplus
extern "C" {
#endif

Expand Down
1 change: 1 addition & 0 deletions src/libdmiget/include/dmiget/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdint.h>
#include <functional>
#include <memory>
#include <iostream>

namespace DMIget {

Expand Down
Loading

0 comments on commit 55cc830

Please sign in to comment.