Skip to content

Commit

Permalink
Python PEP8
Browse files Browse the repository at this point in the history
Refs rockstor#735 rockstor#1306 rockstor#1036 - Flake8 for some files

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
  • Loading branch information
MFlyer committed Feb 27, 2017
1 parent cf53886 commit 7be7d26
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/rockstor/scripts/scheduled_tasks/reboot_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import sys
import json
from datetime import (datetime, timedelta)
import time
import crontabwindow # load crontabwindow module
from smart_manager.models import (Task, TaskDefinition)
from cli.api_wrapper import APIWrapper
from django.utils.timezone import utc
from django.conf import settings
import logging
logger = logging.getLogger(__name__)

Expand All @@ -51,9 +49,9 @@ def main():
validate_shutdown_meta(meta)

now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=utc)
schedule = now + timedelta(minutes = 3)
schedule = now + timedelta(minutes=3)
t = Task(task_def=tdo, state='scheduled', start=now, end=schedule)

try:
# set default command url before checking if it's a shutdown
# and if we have an rtc wake up
Expand All @@ -65,18 +63,19 @@ def main():
# command url adding wake up epoch time
if (tdo.task_type in ['shutdown', 'suspend'] and meta['wakeup']):
crontab_fields = tdo.crontab.split()
crontab_time = int(crontab_fields[1]) * 60 + int(crontab_fields[0])
crontab_time = (int(crontab_fields[1]) * 60 +
int(crontab_fields[0]))
wakeup_time = meta['rtc_hour'] * 60 + meta['rtc_minute']
# rtc wake up requires UTC epoch, but users on WebUI set time
# thinking to localtime, so first we set wake up time,
# update it if wake up is on next day, finally move it to UTC
# and get its epoch
epoch = datetime.now().replace(hour=int(meta['rtc_hour']),
minute=int(meta['rtc_minute']),
second = 0, microsecond = 0)
second=0, microsecond=0)
# if wake up < crontab time wake up will run next day
if (crontab_time > wakeup_time):
epoch += timedelta(days = 1)
epoch += timedelta(days=1)

epoch = epoch.strftime('%s')
url = ('%s/%s' % (url, epoch))
Expand All @@ -98,6 +97,7 @@ def main():
logger.debug('Cron scheduled task not executed because outside '
'time/day window ranges')


if __name__ == '__main__':
# takes two arguments. taskdef object id and crontabwindow.
main()
2 changes: 1 addition & 1 deletion src/rockstor/smart_manager/views/task_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _refresh_crontab():
(tab, settings.ROOT_DIR, td.id))
elif (td.task_type in ['reboot', 'shutdown', 'suspend']):
tab = ('%s %s/bin/st-system-power %d' %
(tab, settings.ROOT_DIR, td.id))
(tab, settings.ROOT_DIR, td.id))
else:
logger.error('ignoring unknown task_type: %s'
% td.task_type)
Expand Down
3 changes: 3 additions & 0 deletions src/rockstor/system/osi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,18 +1076,21 @@ def system_reboot(delta='now'):
# for scheduled tasks reboot/shutdown
return run_command([SHUTDOWN, '-r', delta])


def system_suspend():
# This function perform system suspend to RAM via systemctl
# while reboot and shutdown, both via shutdown command, can be delayed
# systemctl suspend miss this option
return run_command([SYSTEMCTL_BIN, 'suspend'])


def clean_system_rtc_wake():
# Every time we write to rtc alarm file this get locked and
# we have to clean it with a 0 before writing another epoch
with open(RTC_WAKE_FILE, 'w') as rtc:
rtc.write('%d' % 0)


def set_system_rtc_wake(wakeup_epoch):
# This new function receive desired current and wake up time
# and set right epoch time to rtc alarm file.
Expand Down

0 comments on commit 7be7d26

Please sign in to comment.