code quality improvements

* change os.system to subprocess
- removed overshadow of system functions
This commit is contained in:
nico 2019-04-27 15:06:03 +02:00
parent db36781cba
commit 051f450f50
1 changed files with 10 additions and 9 deletions

19
main.py
View File

@ -7,6 +7,7 @@ import requests
import os import os
import sys import sys
import argparse import argparse
import subprocess
from ruamel.yaml import YAML, scalarstring from ruamel.yaml import YAML, scalarstring
@ -33,8 +34,8 @@ class BlacklistImporter:
local_etag = "" local_etag = ""
else: else:
# if both files are present continue normally # if both files are present continue normally
with open(etag_path, "r") as file: with open(etag_path, "r") as local_file:
local_etag = file.read() local_etag = local_file.read()
else: else:
local_etag = "" local_etag = ""
@ -47,8 +48,8 @@ class BlacklistImporter:
if local_etag == etag or head.status_code != 200: if local_etag == etag or head.status_code != 200:
# if local cache is present overwrite blacklist var # if local cache is present overwrite blacklist var
if os.path.isfile(blacklist_path): if os.path.isfile(blacklist_path):
with open(blacklist_path, "r", encoding="utf-8") as file: with open(blacklist_path, "r", encoding="utf-8") as local_file:
self.blacklist = file.read() self.blacklist = local_file.read()
# in any other case request a new file # in any other case request a new file
else: else:
@ -57,11 +58,11 @@ class BlacklistImporter:
local_etag = head.headers['etag'] local_etag = head.headers['etag']
self.blacklist = r.content.decode() self.blacklist = r.content.decode()
with open(blacklist_path, "w") as file: with open(blacklist_path, "w") as local_file:
file.write(self.blacklist) local_file.write(self.blacklist)
with open(etag_path, 'w') as file: with open(etag_path, 'w') as local_file:
file.write(local_etag) local_file.write(local_etag)
def main(self): def main(self):
# first check if blacklist is updated # first check if blacklist is updated
@ -76,7 +77,7 @@ class BlacklistImporter:
# reload config if changes have been applied # reload config if changes have been applied
if self.change: if self.change:
os.system("ejabberdctl reload_config") subprocess.call('/usr/sbin/ejabberdctl reload_config', shell=False)
def process(self): def process(self):
""" """