mise en place des scripts pour la génération du package python et deb

This commit is contained in:
Vincent BENOIT
2022-11-15 14:36:48 +01:00
parent 5ea494e645
commit f6c37733a0
16 changed files with 1973 additions and 218 deletions

38
build.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
#
# Author : vincent.benoit@benserv.fr
# Date : 11/2022
# Version : 1.0
# Brief : création des packages necessaires pour le processus KineIntercom
#
###########################################################################
create_deb() {
dirname=kineintercommisc-$1
/usr/bin/mkdir -p bdist_deb/$dirname
cd bdist_deb/$dirname
/usr/bin/dh_make -t $2/template -n -y -i -d
/usr/bin/find $2/misc -type f -exec /usr/bin/cp -a {} . \;
/usr/bin/dpkg-buildpackage -b -uc -us -rfakeroot
cd ..
if [ $? == "0" ] && [ ! -d "$2/dist" ]; then
/usr/bin/mkdir -p $2/dist
/usr/bin/find . -type f -name "*.deb" -exec /usr/bin/cp -a {} $2/dist \;
fi
}
create_wheel() {
cd $1
/usr/bin/python3 setup.py bdist_wheel --universal
}
echo "*** Remove old dirs ***"
/usr/bin/rm -rf bdist_deb build dist *.egg-info
echo "*** read version ***"
vers=`/usr/bin/cat src/VERSION`
rootpath=`pwd`
echo "*** Create Debian Misc Package ***"
create_deb "$vers" "$rootpath"
echo "*** Create Python Package ***"
create_wheel "$rootpath"
echo "*** that's All Folks ...***"

1389
misc/database_origin.json Normal file

File diff suppressed because it is too large Load Diff

406
misc/db.json.schema Normal file
View File

@@ -0,0 +1,406 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://git.nas.benserv.fr/vincent/Kine-backend/src/branch/master/db.json",
"type": "object",
"title": "KineIntercom database",
"description": "This document records the parameters of KineIntercom process",
"required": [
"CODE_PIN",
"DTMF_CODE",
"DTMF_DURATION",
"HORAIRES",
"INFOS",
"NUM_AUTORISE",
"OPERATION",
"PIN_ACTIF",
"TONE_DURATION",
"utilisateur"
],
"properties": {
"CODE_PIN": {
"type": "string",
"title": "Le code pin de la carte SIM",
"examples": [
"1234"
]
},
"DTMF_CODE": {
"type": "string",
"title": "Le code DTMF a envoyer par le module GSM",
"examples": [
"*"
]
},
"DTMF_DURATION": {
"type": "integer",
"title": "La duree du code DTMF a envoyer par le module GSM",
"examples": [
10
]
},
"HORAIRES": {
"type": "object",
"title": "Les horaires d'ouverture et de fermeture du module GSM",
"required": [
"Friday",
"Monday",
"Saturday",
"Sunday",
"Thursday",
"Tuesday",
"Wednesday"
],
"properties": {
"Friday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Vendredi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Monday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Lundi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Saturday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Samedi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Sunday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Dimanche",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Thursday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Jeudi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Tuesday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Mardi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Wednesday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Mercredi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
}
}
},
"INFOS": {
"type": "object",
"title": "Les infos du module GSM",
"required": [
"control",
"manufacturer"
],
"properties": {
"control": {
"type": "object",
"title": "The control Schema",
"required": [
"call_ready",
"operator",
"service_provider",
"signal_dbm",
"signal_qos",
"sim_inserted"
],
"properties": {
"call_ready": {
"type": "boolean",
"default": false,
"title": "The call_ready Schema",
"examples": [
true,
false
]
},
"operator": {
"type": "string",
"default": "",
"title": "The operator Schema",
"examples": [
"SFR"
]
},
"service_provider": {
"type": "string",
"default": "",
"title": "The service_provider Schema",
"examples": [
"La poste mobile"
]
},
"signal_dbm": {
"type": "string",
"default": "",
"title": "The signal_dbm Schema",
"examples": [
"-75"
]
},
"signal_qos": {
"type": "string",
"default": "",
"title": "The signal_qos Schema",
"examples": [
"excellent"
]
},
"sim_inserted": {
"type": "boolean",
"default": false,
"title": "The sim_inserted Schema",
"examples": [
true,
false
]
}
}
},
"manufacturer": {
"type": "object",
"title": "The manufacturer Schema",
"required": [
"hardware_rev",
"identification",
"model",
"serial_number"
],
"properties": {
"hardware_rev": {
"type": "string",
"title": "The hardware_rev Schema",
"examples": [
"1418B02SIM868M32_BT_EAT"
]
},
"identification": {
"type": "string",
"title": "The identification Schema",
"examples": [
"SIMCOM_Ltd"
]
},
"model": {
"type": "string",
"title": "The model Schema",
"examples": [
"SIMCOM_SIM868"
]
},
"serial_number": {
"type": "string",
"title": "The serial_number Schema",
"examples": [
"864866057705260"
]
}
}
}
}
},
"NUM_AUTORISE": {
"type": "string",
"title": "The NUM_AUTORISE Schema",
"examples": [
"670100036"
]
},
"OPERATION": {
"type": "string",
"title": "The OPERATION Schema",
"examples": [
"Horaires"
]
},
"PIN_ACTIF": {
"type": "boolean",
"title": "The PIN_ACTIF Schema",
"examples": [
true,
false
]
},
"TONE_DURATION": {
"type": "integer",
"title": "The TONE_DURATION Schema",
"examples": [
2
]
},
"utilisateur": {
"type": "object",
"title": "L'utilisateur du configurateur",
"required": [
"id",
"password"
],
"properties": {
"id": {
"type": "string",
"title": "The id Schema",
"examples": [
"admin"
]
},
"password": {
"type": "string",
"title": "The password Schema",
"examples": [
"9ac564e9a29c952a3ddeffd8635adb0c252dbd1d58f3efde265e028f7f808aa9"
]
}
}
}
}
}

12
misc/kineintercom.service Normal file
View File

@@ -0,0 +1,12 @@
[Unit]
Description=Démarrage du processus KineIntercom
[Service]
Type=simple
User=pi
Group=pi
ExecStart=/usr/bin/python3 /usr/local/lib/python3.9/dist-packages/kineintercom/src/intercom.py
[Install]
WantedBy=multi-user.target

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
RPi.GPIO==0.7.0
jsonschema==4.17.0
pyserial==3.5
APScheduler==3.9.1

38
setup.py Normal file
View File

@@ -0,0 +1,38 @@
import io, os
from setuptools import find_packages, setup
def read(*paths, **kwargs):
"""Read the contents of a text file safely.
>>> read("project_name", "VERSION")
'0.1.0'
>>> read("README.md")
...
"""
content = ""
with io.open(
os.path.join(os.path.dirname(__file__), *paths),
encoding=kwargs.get("encoding", "utf8"),
) as open_file:
content = open_file.read().strip()
return content
def read_requirements(path):
ret = []
with open(path, "r") as f:
ret = f.read().splitlines()
return ret
setup(
name='kineintercom',
version=read("src", "VERSION"),
author='vincent.benoit',
author_email='vincent.benoit@benserv.fr',
description='Processus d\'envoi de code DTMF via le module GSM',
long_description=read("README.md"),
long_description_content_type="text/markdown",
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=read_requirements("requirements.txt")
)

View File

@@ -1,71 +0,0 @@
{
"CODE_PIN": 1234,
"NUM_AUTORISE": "0607297154",
"DTMF_CODE": "*",
"DTMF_DURATION": 1,
"HORAIRES": {
"Monday":{
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Tuesday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Wednesday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Thursday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Friday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Saturday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":0,"06h30":0,
"07h00":0,"07h30":0,"08h00":0,"08h30":0,"09h00":0,"09h30":0,"10h00":0,
"10h30":0,"11h00":0,"11h30":0,"12h00":0,"12h30":0,"13h00":0,"13h30":0,
"14h00":0,"14h30":0,"15h00":0,"15h30":0,"16h00":0,"16h30":0,"17h00":0,
"17h30":0,"18h00":0,"18h30":0,"19h00":0,"19h30":0,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Sunday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":0,"06h30":0,
"07h00":0,"07h30":0,"08h00":0,"08h30":0,"09h00":0,"09h30":0,"10h00":0,
"10h30":0,"11h00":0,"11h30":0,"12h00":0,"12h30":0,"13h00":0,"13h30":0,
"14h00":0,"14h30":0,"15h00":0,"15h30":0,"16h00":0,"16h30":0,"17h00":0,
"17h30":0,"18h00":0,"18h30":0,"19h00":0,"19h30":0,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
}
}
}

1
src/VERSION Normal file
View File

@@ -0,0 +1 @@
1.0.0

View File

@@ -19,7 +19,6 @@ import json
import jsonschema
import socket
import shutil
from signal import signal, SIGINT
from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler
@@ -709,7 +708,7 @@ def main():
logger = log.getLogger("Intercom")
logger.setLevel(log.DEBUG)
fl = log.StreamHandler()
hl = log.FileHandler(os.path.join('/var/log/KineIntercom','Intercom.log'))
hl = log.FileHandler(os.path.join('/var/log/kineintercom','Intercom.log'))
fl.setLevel(log.DEBUG)
hl.setLevel(log.INFO)
formatter = log.Formatter('%(asctime)s - %(funcName)s - %(levelname)s - %(message)s')

View File

@@ -1,121 +0,0 @@
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
# @author: benoit.vince84@free.fr
# @date: Septembre 2022
# @brief: Programme Pwrkey pour le GNSS HAT
###################################################################
# Importation de modules externes #
import sys, os, re
import serial
import RPi.GPIO as GPIO
import time
import logging as log
import time
from datetime import datetime, date
import calendar
import json
import socket
###################################################################
# Class et Methods #
def get_conf(logger=None):
''' Get configuration
:return dict:
Configuration dictionnary
'''
config = None
try:
with open(os.path.join("/home/pi/KineIntercom/src", "KineIntercom.json"), 'r') as f:
try:
config = json.load(f)
except json.decoder.JSONDecodeError as e:
logger.error("Impossible de charger les données de configuration ({})".format(e))
except FileNotFoundError as e:
logger.error("Impossible d'ouvrir le fichier de configuation ({})".format(e))
return config
def verify_open_hours(conf=None, log=None):
''' Verify if GSM HAT must be opened with conf hours
:param conf:
configuration object
:param log:
logger object
:return bool:
True if authorized, False otherwise
'''
flag = False
my_date = date.today()
day = calendar.day_name[my_date.weekday()]
now = datetime.now()
for k,v in conf[day].items():
time_conf = int(k.split('h')[0])*60 + int(k.split('h')[1])
current_time = now.hour*60 + now.minute
if current_time >= time_conf:
if v == 1:
flag = True
elif v == 0:
flag = False
log.debug('Jour: {} - Temps courant: {} - Ouverture: {}'.format(day, now.strftime('%Hh%M'), flag))
return flag
def init_module():
''' initialisation of GNSS/GPS/GSM HAT Module
'''
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
return
def setup_module():
''' Setup module (Set/Reset)
'''
while True:
GPIO.output(7, GPIO.LOW)
time.sleep(2)
GPIO.output(7, GPIO.HIGH)
break
GPIO.cleanup()
def main():
''' main function
'''
logger = log.getLogger("pwrkey")
logger.setLevel(log.DEBUG)
fl = log.StreamHandler()
fl.setLevel(log.DEBUG)
formatter = log.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fl.setFormatter(formatter)
logger.addHandler(fl)
# get config dictionnary
config = get_conf(logger)
if not config:
exit(1)
# create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_addr = '/tmp/uds_socket'
try:
sock.connect(server_addr)
except socket.error as e:
logger.error("Erreur de connexion avec le serveur: {}".format(e))
sys.exit(1)
opened = verify_open_hours(conf=config['HORAIRES'], log=logger)
sock.sendall(str(opened))
sock.close()
#init_module()
#setup_module()
if __name__ == '__main__':
main()

5
template/changelog Normal file
View File

@@ -0,0 +1,5 @@
#PACKAGE# (#VERSION#-1) stable; urgency=medium
* Initial release
-- #USERNAME# <#EMAIL#> #DATE#

1
template/compat Normal file
View File

@@ -0,0 +1 @@
11

12
template/control Normal file
View File

@@ -0,0 +1,12 @@
Source: #PACKAGE#
Section: misc
Priority: optional
Maintainer: #USERNAME# <#EMAIL#>
Build-Depends: #BUILD_DEPS#
Standards-Version: #POLICY#
Homepage: https://git.nas.benserv.fr/vincent/KineIntercom
Package: #PACKAGE#
Architecture: all
Depends: ${misc:Depends}
Description: Installation des fichiers nécessaires au fonctionnement du processus KineIntercom

3
template/install Normal file
View File

@@ -0,0 +1,3 @@
db.json.schema /usr/share/kineintercom/
database_origin.json /usr/share/kineintercom/
kineintercom.service /lib/systemd/system/

View File

@@ -0,0 +1,27 @@
#!/bin/sh
# postinst script for sclesignrestfulmisc
#
# see: dh_installdeb(1)
set -e
user="root"
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
userpi="pi"
dirname="kineintercom"
# create conf directory
/usr/bin/mkdir -p /etc/$dirname
/usr/bin/chown -R $user:$userpi /etc/$dirname
/usr/bin/chmod -R 770 /etc/$dirname
# create log directory
/usr/bin/mkdir -p /var/log/$dirname
/usr/bin/chown -R $user:$userpi /var/log/$dirname
# Restart service
/usr/bin/systemctl restart kineintercom.service

12
template/rules Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
#RULES_START_TEXT#
%:
dh $@#DH_ADDON#
override_dh_auto_install:
#RULES_END_TEXT#