Skip to content

Commit

Permalink
code cleanning
Browse files Browse the repository at this point in the history
  • Loading branch information
EmixamPP committed Aug 7, 2021
1 parent 221b8d6 commit 33d618a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
13 changes: 7 additions & 6 deletions AUR/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Contributor: Antoine Bertin <[email protected]>

pkgname=linux-enable-ir-emitter
pkgver=2.0.0
pkgver=2.0.1
pkgrel=1
epoch=1
pkgdesc="Enables infrared cameras that are not directly enabled out-of-the box."
Expand All @@ -18,6 +18,7 @@ depends=(
'python'
'python-opencv'
'python-yaml'
'nano'
)
optdepends=(
'python-pyshark: full configuration setup support'
Expand All @@ -35,12 +36,12 @@ package() {

install -Dm 644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}"

install -Dm 755 sources/enable-ir-emitter "${pkgdir}"/usr/lib/linux-enable-ir-emitter/enable-ir-emitter
install -Dm 644 sources/config.yaml "${pkgdir}"/usr/lib/linux-enable-ir-emitter/config.yaml
install -Dm 755 sources/*.py "${pkgdir}"/usr/lib/linux-enable-ir-emitter/
install -Dm 755 sources/enable-ir-emitter -t "${pkgdir}"/usr/lib/linux-enable-ir-emitter/
install -Dm 644 sources/config.yaml -t "${pkgdir}"/usr/lib/linux-enable-ir-emitter/
install -Dm 755 sources/*.py -t "${pkgdir}"/usr/lib/linux-enable-ir-emitter/

install -Dm 644 sources/linux-enable-ir-emitter.service "${pkgdir}"/usr/lib/systemd/system/linux-enable-ir-emitter.service
install -Dm 644 sources/linux-enable-ir-emitter.service -t "${pkgdir}"/usr/lib/systemd/system/

install -dm 755 ${pkgdir}/usr/bin/
ln -s /usr/lib/linux-enable-ir-emitter/linux-enable-ir-emitter.py ${pkgdir}/usr/bin/linux-enable-ir-emitter
ln -fs /usr/lib/linux-enable-ir-emitter/linux-enable-ir-emitter.py ${pkgdir}/usr/bin/linux-enable-ir-emitter
}
63 changes: 36 additions & 27 deletions sources/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,39 @@
systemd_file_path = "/usr/lib/systemd/system/" + systemd_name


def run():
"""Run the config saved in irConfig.yaml
def _load_saved_config():
"""Load the ir config saved.
Returns:
IrConfiguration: the saved config
None: if a error occur
"""
try:
if os.path.exists(save_config_file_path):
ir_config = IrConfiguration.load(save_config_file_path)
ir_config.run()
return IrConfiguration.load(save_config_file_path)
else:
print("No configuration is currently saved", file=sys.stderr)
except yaml.YAMLError:
print("The config file is corrupted !", file=sys.stderr)

return None


def run():
"""Run the config saved in irConfig.yaml
"""
ir_config = _load_saved_config()
if ir_config:
ir_config.run()


def test():
"""Try to trigger the ir emitter with the current configuration
"""
ir_config = _load_saved_config()
if ir_config:
ir_config.trigger_ir(2)


def boot(status):
"""Enable or disable the systemd service which activates the ir emitter
Expand Down Expand Up @@ -51,27 +72,12 @@ def manual(video_path):
dummy_config.save(save_config_file_path)

os.system("/bin/nano " + save_config_file_path)
actual_config = IrConfiguration.load(save_config_file_path)
if actual_config == dummy_config:
if _load_saved_config() == dummy_config:
os.system("rm " + save_config_file_path)


def test():
"""Try to trigger the ir emitter with the current configuration
"""
try:
if os.path.exists(save_config_file_path):
ir_config = IrConfiguration.load(save_config_file_path)
ir_config.run()
ir_config.trigger_ir(2)
else:
print("No configuration is currently saved", file=sys.stderr)
except yaml.YAMLError:
print("The config file is corrupted !", file=sys.stderr)


def _show_config_test(ir_config):
"""Test the configuration and ask the user if it works. In this case the coinfiguration is saved.
"""Test the configuration and ask the user if it works. In this case the configuration is saved.
Args:
ir_config (IrConfiguration): configuration to test
Expand Down Expand Up @@ -103,15 +109,16 @@ def quick(video_path):

if _show_config_test(ir_config):
print("A configuration have been found. Here is what you can do:")
print("\t- activate the emitter at system startup : 'linux-ir-emitter boot enable'")
print("\t- manually activate the emitter for one session : 'linux-ir-emitter run'")
print("\t- activate the emitter at system startup : 'linux-enable-ir-emitter boot enable'")
print("\t- manually activate the emitter for one session : 'linux-enable-ir-emitter run'")
return

print("No configuration was found please execute : 'linux-ir-emitter full'", file=sys.stderr)
print("No configuration was found please execute : 'linux-enable-ir-emitter full'", file=sys.stderr)


def _show_contribution(ir_config):
"""Check if the configuration does not exist is not in the configuration file. Then the user is invited to share it on Github
"""Check if the configuration does not exist is not in the configuration file.
Then the user is invited to share it on Github
Args:
ir_config (IrConfiguration): the configuration to be compared with those in the YAML config file
Expand All @@ -133,20 +140,22 @@ def _show_contribution(ir_config):
def full(video_path):
"""Try to find the ir emitter configuration by capturing the bus.
On condition that the ir emitter is triggered via a Windows VM.
Exit if pysharsk is not installed.
Args:
video_path (string): Path to the infrared camera e.g : "/dev/video2"
"""
try:
from IrConfigCapture import IrConfigCapture
except ImportError:
print("The 'pyshark' python dependency is required for this command", file=sys.stderr)
print("The 'pyshark' python dependency is required for this command.", file=sys.stderr)
print("Please consult https://github.com/EmixamPP/linux-enable-ir-emitter/wiki/Semi-automatic-configuration.")
sys.exit(1)

input("Please read and folow this tutorial : https://github.com/EmixamPP/linux-enable-ir-emitter/wiki/Semi-automatic-configuration. Press enter when you'r ready")
capture = IrConfigCapture(video_path)
capture.start(45)
input("The capturing is finished, make sure the camera is connected to the host os. Press enter when it's done ")
input("The capturing is finished, make sure the camera is connected to the host os. Press enter when it's done")

for ir_config in capture.config_list:
if _show_config_test(ir_config):
Expand Down

0 comments on commit 33d618a

Please sign in to comment.