From 051f450f501c9e1921ef3fb9db4835c8db2d8536 Mon Sep 17 00:00:00 2001 From: nico Date: Sat, 27 Apr 2019 15:06:03 +0200 Subject: code quality improvements * change os.system to subprocess - removed overshadow of system functions --- main.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 87d0a2b..5f1ea7e 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import requests import os import sys import argparse +import subprocess from ruamel.yaml import YAML, scalarstring @@ -33,8 +34,8 @@ class BlacklistImporter: local_etag = "" else: # if both files are present continue normally - with open(etag_path, "r") as file: - local_etag = file.read() + with open(etag_path, "r") as local_file: + local_etag = local_file.read() else: local_etag = "" @@ -47,8 +48,8 @@ class BlacklistImporter: if local_etag == etag or head.status_code != 200: # if local cache is present overwrite blacklist var if os.path.isfile(blacklist_path): - with open(blacklist_path, "r", encoding="utf-8") as file: - self.blacklist = file.read() + with open(blacklist_path, "r", encoding="utf-8") as local_file: + self.blacklist = local_file.read() # in any other case request a new file else: @@ -57,11 +58,11 @@ class BlacklistImporter: local_etag = head.headers['etag'] self.blacklist = r.content.decode() - with open(blacklist_path, "w") as file: - file.write(self.blacklist) + with open(blacklist_path, "w") as local_file: + local_file.write(self.blacklist) - with open(etag_path, 'w') as file: - file.write(local_etag) + with open(etag_path, 'w') as local_file: + local_file.write(local_etag) def main(self): # first check if blacklist is updated @@ -76,7 +77,7 @@ class BlacklistImporter: # reload config if changes have been applied if self.change: - os.system("ejabberdctl reload_config") + subprocess.call('/usr/sbin/ejabberdctl reload_config', shell=False) def process(self): """ -- cgit v1.2.3-18-g5258