configobj for runtime_config

This commit is contained in:
Thorsten S
2015-12-20 15:24:42 +01:00
parent c29ce94a3d
commit 6c3ba11eb6
9 changed files with 228 additions and 245 deletions

View File

@@ -2,14 +2,10 @@
""" Common functions for urlbot """
import html.parser
import logging
import os
import pickle
import re
import sys
import time
import urllib.request
from collections import namedtuple
import config
RATE_NO_LIMIT = 0x00
RATE_GLOBAL = 0x01
@@ -25,32 +21,6 @@ EVENTLOOP_DELAY = 0.100 # seconds
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) ' \
'Gecko/20100101 Firefox/31.0 Iceweasel/31.0'
def conf_save(obj):
with open(config.get('persistent_storage'), 'wb') as config_file:
return pickle.dump(obj, config_file)
def conf_load():
path = config.get('persistent_storage')
if os.path.isfile(path):
with open(path, 'rb') as fd:
fd.seek(0)
return pickle.load(fd)
else:
return {}
def conf_set(key, value):
blob = conf_load()
blob[key] = value
conf_save(blob)
def conf_get(key, default=None):
blob = conf_load()
return blob.get(key, default)
Bucket = namedtuple("BucketConfig", ["history", "period", "max_hist_len"])
buckets = {