write_status_watchdog()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import logging
5
logger = logging.getLogger(__name__)
6
logger.debug("%s loaded", __name__)
7
8
from doorpi.action.base import SingleAction
9
import doorpi
0 ignored issues
show
Unused Code introduced by
The import doorpi seems to be unused.
Loading history...
10
11
def write_status_watchdog(watchdog_path, timeout):
12
    timeout = int(timeout)
13
14
    try:
15
        watchdog = open(watchdog_path, "w+")
16
    except:
17
        logger.warning("while action write_status_watchdog - error opening watchdog file")
18
        return False
19
20
    try:
21
        watchdog.write('\n')
22
        watchdog.flush()
23
    finally:
24
        watchdog.close()
25
26
    return True
27
28
def get(parameters):
29
    parameter_list = parameters.split(',')
30
    if len(parameter_list) is not 1 and len(parameter_list) is not 2: return None
31
32
    watchdog = parameter_list[0]
33
    timeout = 5
34
35
    if len(parameter_list) is 2:
36
        timeout = int(parameter_list[1])
37
38
    return SleepAction(write_status_watchdog, watchdog, timeout)
39
40
class SleepAction(SingleAction):
41
    pass