command line and config file management
This commit is contained in:
parent
ba1ac98a61
commit
cc051d7e9e
2
TODO
2
TODO
@ -3,7 +3,6 @@
|
||||
- add deb packaging
|
||||
- logging
|
||||
- message localization
|
||||
- put config in /etc, if doesn't exist, load local file
|
||||
- user settings (activation time, etc)
|
||||
- command extension (/record for recording audio)
|
||||
- unpair other usernames
|
||||
@ -12,6 +11,7 @@
|
||||
|
||||
dependencies:
|
||||
- python-watchdog
|
||||
- python-argparse
|
||||
- python-configparser
|
||||
- telepot???
|
||||
- datetime forse gia' incluso
|
||||
|
@ -8,6 +8,7 @@ import telepot
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
from telepot.loop import MessageLoop
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
@ -151,15 +152,46 @@ def checkFiles():
|
||||
for f in l:
|
||||
processFile("%s/%s" % (spool_dir,f) )
|
||||
|
||||
for arg in sys.argv:
|
||||
if arg=='-v' or arg=='--version':
|
||||
print 'telegram-notify version %s - Copyright (C) 2018 by Paolo Asperti.' % version
|
||||
sys.exit(0)
|
||||
|
||||
configFile = '/etc/telegram-notify/telegram-notify.conf'
|
||||
if not os.path.isfile(configFile) or not os.access(configFile, os.R_OK):
|
||||
configFile = './telegram-notify.conf'
|
||||
if not os.path.isfile(configFile) or not os.access(configFile, os.R_OK):
|
||||
configFile = ''
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Daemon for Telegram notification management')
|
||||
parser.add_argument('-c', '--config', nargs='?',
|
||||
help='start with specified config file')
|
||||
parser.add_argument('-V', '--version', action='store_true',
|
||||
help='show program version and quit')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.version:
|
||||
print 'telegram-notify version %s - Copyright (C) 2018 by Paolo Asperti.' % version
|
||||
sys.exit(0)
|
||||
|
||||
if args.config:
|
||||
if not os.path.isfile(args.config):
|
||||
print 'specified config file doesn\'t exists or is not a file'
|
||||
sys.exit(1)
|
||||
if not os.access(args.config, os.R_OK):
|
||||
print 'specified config file is not readable'
|
||||
sys.exit(1)
|
||||
if not os.access(args.config, os.W_OK):
|
||||
# TODO: logging
|
||||
print 'WARNING: specified config file is not wriable'
|
||||
configFile = args.config
|
||||
|
||||
if configFile == '':
|
||||
print 'no config file available'
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# TODO: logging
|
||||
print 'INFO: using config file: %s' % configFile
|
||||
configParser = ConfigParser.RawConfigParser()
|
||||
configParser.read('telegram-notify.conf')
|
||||
configParser.read(configFile)
|
||||
|
||||
spool_dir = configParser.get('general', 'spool_dir')
|
||||
if not os.path.isdir(spool_dir):
|
||||
@ -189,7 +221,6 @@ bot = telepot.Bot(token)
|
||||
MessageLoop(bot, handle).run_as_thread()
|
||||
print 'I am listening ...'
|
||||
|
||||
# TODO: send message if files present in spool at start
|
||||
checkFiles()
|
||||
|
||||
observer = Observer()
|
||||
|
Loading…
Reference in New Issue
Block a user