code best practices fixes for daemon file
@@ -11,39 +11,54 @@ from foglamp.controller import start
def do_something(logf):
- fh = logging.FileHandler(logf)
- fh.setLevel(logging.DEBUG)
+ """
+ :param logf: log file
+ :return:
+ """
+ file_handler = logging.FileHandler(logf)
+ file_handler.setLevel(logging.DEBUG)
formatstr = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
formatter = logging.Formatter(formatstr)
- fh.setFormatter(formatter)
+ file_handler.setFormatter(formatter)
logger = logging.getLogger('')
- logger.addHandler(fh)
+ logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
start()
-def start_daemon(pidf, logf, wd):
- """Launches the daemon"""
+def start_daemon(pidf, logf, wdir):
+ """
+ Launches the daemon
- # XXX pidfile is a context
+ :param pidf: pidfile
+ :param logf: log file
+ :param wdir: working directory
+ :return:
+ """
+
+ # XXX: pidfile is a context
with daemon.DaemonContext(
- working_directory=wd,
+ working_directory=wdir,
umask=0o002,
pidfile=pidfile.TimeoutPIDLockFile(pidf)
) as context:
do_something(logf)
-def safe_makedirs(dir):
- dir = os.path.expanduser(dir)
+def safe_makedirs(directory):
+ """
+ :param directory: working directory
+ :return:
+ """
+ directory = os.path.expanduser(directory)
try:
- os.makedirs(dir, 0o750)
+ os.makedirs(directory, 0o750)
except Exception as e:
- if not os.path.exists(dir):
+ if not os.path.exists(directory):
raise e
@@ -60,9 +75,9 @@ def main():
safe_makedirs(os.path.dirname(args.log_file))
# TODO: ['start', 'stop', 'restart', 'status', 'info']
- start_daemon(pidf=os.path.expanduser(args.pid_file), logf=os.path.expanduser(args.log_file), wd=os.path.expanduser(args.working_dir))
+ start_daemon(pidf=os.path.expanduser(args.pid_file), logf=os.path.expanduser(args.log_file),
+ wdir=os.path.expanduser(args.working_dir))
if __name__ == "__main__":
main()
-
