Config file loading bug
added /etc as a path
This commit is contained in:
parent
468655fb3b
commit
6cb0924ffa
@ -2,7 +2,7 @@
|
|||||||
from pysquidblacklists import *
|
from pysquidblacklists import *
|
||||||
|
|
||||||
config = PySquidBlacklistsConfig()
|
config = PySquidBlacklistsConfig()
|
||||||
config.get_config()
|
config.get_config(__file__)
|
||||||
|
|
||||||
bli = PySquidBlacklistsImporter(config)
|
bli = PySquidBlacklistsImporter(config)
|
||||||
bl = PySquidBlacklistsRunner(config, bli)
|
bl = PySquidBlacklistsRunner(config, bli)
|
||||||
|
@ -122,8 +122,8 @@ class PySquidBlacklistsConfig:
|
|||||||
self.config = configparser.RawConfigParser()
|
self.config = configparser.RawConfigParser()
|
||||||
self.config_path = None
|
self.config_path = None
|
||||||
|
|
||||||
def get_config(self):
|
def get_config(self, pwd):
|
||||||
self.get_path()
|
self.get_path(pwd)
|
||||||
self.config.read(self.config_path)
|
self.config.read(self.config_path)
|
||||||
self.url = str(self.config.get("main", "url"))
|
self.url = str(self.config.get("main", "url"))
|
||||||
self.filename = self.url.split("/").pop()
|
self.filename = self.url.split("/").pop()
|
||||||
@ -138,11 +138,14 @@ class PySquidBlacklistsConfig:
|
|||||||
def set_config(self, section, attr):
|
def set_config(self, section, attr):
|
||||||
self.config.set(section, attr)
|
self.config.set(section, attr)
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self, pwd):
|
||||||
filename = "py-squid-blacklists.conf"
|
filename = "py-squid-blacklists.conf"
|
||||||
config_path = "%s/%s" % (os.path.dirname(os.path.abspath(__name__)), filename)
|
config_path = "%s/%s" % (os.path.dirname(os.path.abspath(pwd)), filename)
|
||||||
|
default_config_path = "/etc/%s" % filename
|
||||||
|
|
||||||
if os.path.exists(config_path):
|
if os.path.exists(config_path):
|
||||||
self.config_path = config_path
|
self.config_path = config_path
|
||||||
|
elif os.path.exists(default_config_path):
|
||||||
|
self.config_path = default_config_path
|
||||||
else:
|
else:
|
||||||
exit("No config file available at common paths. Must initialize it")
|
exit("No config file available at common paths (current dir or /etc). Must initialize it")
|
||||||
|
Loading…
Reference in New Issue
Block a user