Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
add -r option to remove cronjobs and do not connect if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dynasticorpheus committed Apr 21, 2015
1 parent 8ec73aa commit 4c992eb
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions gigasetelements-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
gc.disable()

_author_ = 'dynasticorpheus@gmail.com'
_version_ = '1.1.2'
_version_ = '1.1.3'

parser = argparse.ArgumentParser(description='Gigaset Elements - Command-line Interface by dynasticorpheus@gmail.com')
parser.add_argument('-c', '--config', help='fully qualified name of configuration-file', required=False)
Expand All @@ -32,6 +32,7 @@
parser.add_argument('-e', '--events', help='show last <number> of events', type=int, required=False)
parser.add_argument('-d', '--date', help='filter events on begin date - end date', required=False, nargs=2, metavar='DD/MM/YYYY')
parser.add_argument('-o', '--cronjob', help='schedule cron job at HH:MM (requires -m option)', required=False, metavar='HH:MM')
parser.add_argument('-r', '--remove', help='remove all cron jobs linked to this program', action='store_true', required=False)
parser.add_argument('-f', '--filter', help='filter events on type', required=False, choices=('door', 'motion', 'siren', 'homecoming', 'intrusion', 'systemhealth'))
parser.add_argument('-m', '--modus', help='set modus', required=False, choices=('home', 'away', 'custom'))
parser.add_argument('-s', '--status', help='show sensor status', action='store_true', required=False)
Expand Down Expand Up @@ -243,6 +244,23 @@ def add_cron(schedule):
return


def remove_cron():
exist_module('crontab', 'python-crontab')
origin = command = os.path.realpath(__file__)
from crontab import CronTab
cron = CronTab(user=True)
iter = cron.find_command(origin)
count = 0
for i in iter:
log('Cron job removed | ' + str(i))
count = count + 1
cron.remove_all(origin)
cron.write()
if count == 0:
log('No cron jobs found for removal | ' + origin)
return


def pb_message(pbmsg):
if args.notify is not None and args.quiet is not True:
exist_module('pushbullet', 'pushbullet.py')
Expand Down Expand Up @@ -309,6 +327,18 @@ def status():
print 'Gigaset Elements - Command-line Interface'
print

if args.cronjob is not None:
add_cron(args.cronjob)
if args.status is False and args.events is None:
print
sys.exit()

if args.remove and args.cronjob is None:
remove_cron()
if args.status is False and args.events is None:
print
sys.exit()

configure()
connect()

Expand All @@ -321,9 +351,6 @@ def status():
status()
pb_message('Status ' + status_data['home_state'].upper() + ' | Modus ' + basestation_data[0]['intrusion_settings']['active_mode'].upper())

if args.cronjob is not None:
add_cron(args.cronjob)

if args.events is None and args.date is None:
pass
else:
Expand Down

0 comments on commit 4c992eb

Please sign in to comment.