Skip to content

Commit 81c455b

Browse files
authored
Merge pull request #65 from kaulketh/develop
minor changes at imports
2 parents 661f4d0 + 21a9205 commit 81c455b

File tree

7 files changed

+52
-164
lines changed

7 files changed

+52
-164
lines changed

bot/conf/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .lib_english import *
33
from .lib_ext_greenhouse import *
44
from .greenhouse_config import *
5+
from .lib_global import *

bot/conf/lib_global.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
author: Thomas Kaulke, [email protected]
66
"""
77

8+
import sys
9+
810
empty = ''
911
space = ' '
1012
colon_space = ': '
@@ -33,17 +35,31 @@
3335
time_units_sign = ('s', 'm', 'h')
3436
time_conversion = time_units_conversion[time_units_index]
3537

38+
file_paths = {
39+
'file_log_greenhouse': '/greenhouse.log',
40+
'file_log_debug': '/greenhouse_console.log',
41+
'file_log_update': '/update_bot.log',
42+
'latest_release': '/greenhouseLatestRelease.id',
43+
'commit_id': '/greenhouseRepoCommit.id',
44+
'cloned_branch': '/greenhouseRepoBranch.name',
45+
'bot_dir': '/home/pi/scripts/TelegramBot/',
46+
'bot_backup': '/home/pi/backups/greenhouse.tgz'
47+
}
48+
49+
file_log_greenhouse = file_paths['file_log_greenhouse']
50+
file_log_debug = file_paths['file_log_debug']
51+
file_log_update = file_paths['file_log_update']
52+
latest_release = file_paths['latest_release']
53+
commit_id = file_paths['commit_id']
54+
cloned_branch = file_paths['cloned_branch']
55+
bot_dir = file_paths['bot_dir']
56+
bot_backup = file_paths['bot_backup']
57+
3658

37-
# TODO: make accessible in bash and vice versa!!!!
38-
file_log_greenhouse = '/greenhouse.log'
39-
file_log_debug = '/greenhouse_console.log'
40-
file_log_update = '/update_bot.log'
41-
latest_release = '/greenhouseLatestRelease.id'
42-
commit_id = '/greenhouseRepoCommit.id'
43-
cloned_branch = '/greenhouseRepoBranch.name'
44-
bot_dir = '/home/pi/scripts/TelegramBot/'
45-
bot_backup = '/home/pi/backups/greenhouse.tgz'
59+
def get_path(var):
60+
if file_paths.__contains__(var):
61+
print(file_paths[var])
4662

4763

4864
if __name__ == '__main__':
49-
pass
65+
get_path(sys.argv[1])

bot/ext_greenhouse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __init_and_start():
149149
apiToken = conf.token
150150
chat_id = sys.argv[1]
151151

152-
# kill the still running greenhouse bot script.
152+
""" kill the still running greenhouse bot script """
153153
pid1 = utils.read_cmd(lib.get_pid1, lib.tmp_file)
154154
utils.read_cmd('kill -9 {0}'.format(str(pid1)), lib.tmp_file)
155155

bot/greenhouse.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,12 @@ def __job_stop_and_restart(bot, job):
360360
# error
361361
def __error(bot, update, e):
362362
logger.error('Update "{0}" caused error "{1}"'.format(update, e))
363-
display.show_error()
364-
__cam_off()
365-
utils.GPIO.cleanup()
363+
try:
364+
display.show_error()
365+
__cam_off()
366+
utils.GPIO.cleanup()
367+
except Exception:
368+
logging.warning('Any error occurs!')
366369
return ConversationHandler.END
367370

368371

bot/peripherals/oled/display.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
author: Thomas Kaulke, [email protected]
66
"""
77

8-
# TODO: improve and fix imports, load vars from global lib!!!
9-
# from __future__ import absolute_import
10-
# import conf.lib_global as lib
8+
from __future__ import absolute_import
9+
from conf import get_path
1110
import subprocess
1211
from time import sleep
1312
from PIL import Image, ImageFont, ImageDraw
1413
from smbus import SMBus
1514
from lib_oled96 import Ssd1306
1615

1716

18-
latest_release = '/greenhouseLatestRelease.id'
19-
commit_id = '/greenhouseRepoCommit.id'
20-
cloned_branch = '/greenhouseRepoBranch.name'
21-
bot_dir = '/home/pi/scripts/TelegramBot/'
17+
latest_release = get_path('latest_release')
18+
commit_id = get_path('commit_id')
19+
cloned_branch = get_path('cloned_branch')
20+
bot_dir = get_path('bot_dir')
2221

2322

2423
# Display setup, methods and members

bot/test_bot.py

-134
This file was deleted.

bot/update_bot.sh

+12-9
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ bot=$1
88
chat=$2
99
project=greenhouse
1010
owner=kaulketh
11-
log='/update_bot.log'
12-
### Ensure same file names in peripherals/oled/display.py! ###
13-
### Ensure same file names in conf/ext_greenhouse.py! ###
14-
commit_id='/greenhouseRepoCommit.id'
15-
cloned_branch='/greenhouseRepoBranch.name'
16-
bot_dir='/home/pi/scripts/TelegramBot/'
17-
latest_release='/greenhouseLatestRelease.id'
11+
12+
# path to main config library
13+
config='/home/pi/scripts/TelegramBot/conf/lib_global.py'
14+
15+
log=$(python $config file_log_update)
16+
commit_id=$(python $config commit_id)
17+
cloned_branch=$(python $config cloned_branch)
18+
bot_dir=$(python $config bot_dir)
19+
latest_release=$(python $config latest_release)
20+
1821
wait=3
1922

2023
# function display usage
2124
display_usage() {
22-
echo "Failed! Paremeter is missing."
25+
echo "Failed! Parameter is missing."
2326
echo "Usage only possible at least with Telegram bot API token and Chat ID!"
2427
}
2528

@@ -48,7 +51,7 @@ fi
4851
commit=$(curl -s https://api.github.com/repos/${owner}/${project}/commits/${branch} --insecure | grep -Po '(?<="sha":)(.*?)(?=,)' -m 1 | sed "s/\"//g" | sed -e 's/^[[:space:]]*//' | sed -e 's/[.]*$//')
4952
# get saved commit
5053
last_commit=$(cat ${commit_id})
51-
#get latest release
54+
# get latest release
5255
release=$(curl -s https://api.github.com/repos/${owner}/${project}/releases/latest --insecure| grep -Po '"tag_name": "\K.*?(?=")')
5356
echo ${release} > ${latest_release}
5457

0 commit comments

Comments
 (0)