Skip to content

Commit

Permalink
fix path to cupp.cfg, mentioned in Mebus#34
Browse files Browse the repository at this point in the history
  • Loading branch information
Mebus committed Feb 22, 2019
1 parent d640d61 commit 0905db7
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions cupp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,48 @@
CONFIG = {}


def read_config(filename="cupp.cfg"):
def read_config(filename):
"""Read the given configuration file and update global variables to reflect
changes (CONFIG)."""

# global CONFIG

# Reading configuration file
config = configparser.ConfigParser()
config.read(filename)

CONFIG["global"] = {
"years": config.get("years", "years").split(","),
"chars": config.get("specialchars", "chars").split(","),
"numfrom": config.getint("nums", "from"),
"numto": config.getint("nums", "to"),
"wcfrom": config.getint("nums", "wcfrom"),
"wcto": config.getint("nums", "wcto"),
"threshold": config.getint("nums", "threshold"),
"alectourl": config.get("alecto", "alectourl"),
"dicturl": config.get("downloader", "dicturl"),
}
if os.path.isfile(filename):

# global CONFIG

# Reading configuration file
config = configparser.ConfigParser()
config.read(filename)

CONFIG["global"] = {
"years": config.get("years", "years").split(","),
"chars": config.get("specialchars", "chars").split(","),
"numfrom": config.getint("nums", "from"),
"numto": config.getint("nums", "to"),
"wcfrom": config.getint("nums", "wcfrom"),
"wcto": config.getint("nums", "wcto"),
"threshold": config.getint("nums", "threshold"),
"alectourl": config.get("alecto", "alectourl"),
"dicturl": config.get("downloader", "dicturl"),
}

# 1337 mode configs, well you can add more lines if you add it to the
# config file too.
leet = functools.partial(config.get, "leet")
leetc = {}
letters = {"a", "i", "e", "t", "o", "s", "g", "z"}
# 1337 mode configs, well you can add more lines if you add it to the
# config file too.
leet = functools.partial(config.get, "leet")
leetc = {}
letters = {"a", "i", "e", "t", "o", "s", "g", "z"}

for letter in letters:
leetc[letter] = config.get("leet", letter)
for letter in letters:
leetc[letter] = config.get("leet", letter)

CONFIG["LEET"] = leetc

return True

else:
print("Configuration file " + filename + " not found!")
sys.exit("Exiting.")

CONFIG["LEET"] = leetc
return False


def make_leet(x):
Expand Down Expand Up @@ -998,7 +1008,7 @@ def mkdir_if_not_exists(dire):
def main():
"""Command-line interface to the cupp utility"""

read_config()
read_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), "cupp.cfg"))

parser = get_parser()
args = parser.parse_args()
Expand Down

0 comments on commit 0905db7

Please sign in to comment.