Exemplo n.º 1
0
    def test_defaults_read_ini(self):
        defaults = {'section': {'item': 'default'}}

        config = simpleconfigparser(defaults=defaults)
        config.read(join(test_path, 'not-default.ini'))
        assert config.section.item == 'not-default'
        assert config['section']['item'] == 'not-default'
Exemplo n.º 2
0
 def test_read_quote_stripping(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'quotes.ini'))
     assert config.section.single == 'win'
     assert config.section.double == 'win again'
     assert config['section']['single'] == 'win'
     assert config['section']['double'] == 'win again'
 def test_read_quote_stripping(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'quotes.ini'))
     assert config.section.single == 'win'
     assert config.section.double == 'win again'
     assert config['section']['single'] == 'win'
     assert config['section']['double'] == 'win again'
Exemplo n.º 4
0
class Config:
    APP_ROOT = os.path.dirname(os.path.abspath(__file__))
    config_parser = simpleconfigparser()
    env_var_name = "DATA-CREATION-CONFIG"

    def __init__(self):
        self.configs = self.read_config(self.APP_ROOT + os.sep + "config.ini")
        self.logger = self.configure_logger()

        if self.env_var_name in os.environ:
            self.override_default_config()

    def override_default_config(self):
        custom_config_path = os.environ.get(self.env_var_name)
        self.configs.update(self.read_config(custom_config_path))

    def read_config(self, config_file_path):
        self.config_parser.read(config_file_path)
        return {
            s: dict(self.config_parser.items(s, True))
            for s in self.config_parser.sections()
        }

    def configure_logger(self):
        if "log" in self.configs and "path" in self.configs.get("log"):
            logging.config.fileConfig(self.APP_ROOT + os.sep +
                                      self.configs.get("log").get("path"))
            return logging.getLogger("root")
        else:
            print("Logging configuration failed.")
Exemplo n.º 5
0
    def __init__(self):
        """
        Initialize the bot with some basic info.
        """

        if(os.path.isfile("settings.cfg") == False):
            print("Could not find settings.cfg. Exiting...")
            exit(1)

        self.config = simpleconfigparser()

        self.config.read("settings.cfg")

        self.userAgent = "xposting bot by /u/SirNeon"

        # add terminal output
        self.verbose = self.config.main.getboolean("verbose")

        # list of subreddits to crawl
        self.subredditList = set(self.config.main.subreddits.split(','))

        # enable errorLogging
        self.errorLogging = self.config.logging.getboolean("errorLogging")

        # list of threads already done
        self.alreadyDone = set()

        # post to this subreddit
        self.post_to = self.config.main.post_to

        # scan no more than this number of threads
        self.scrapeLimit = int(self.config.main.scrapeLimit)
    def test_read_items(self):
        config = simpleconfigparser()
        config.read(join(test_path, 'quotes.ini'))
        items = [
            ('single', "win"),
            ('double', "win again")
        ]

        assert config.section.items() == items
    def test_defaults(self):
        defaults = {
            'section': {
                'item': 'default'
            }
        }

        config = simpleconfigparser(defaults=defaults)
        assert config.section.item == 'default'
        assert config['section']['item'] == 'default'
    def test_defaults_read_ini(self):
        defaults = {
            'section': {
                'item': 'default'
            }
        }

        config = simpleconfigparser(defaults=defaults)
        config.read(join(test_path, 'not-default.ini'))
        assert config.section.item == 'not-default'
        assert config['section']['item'] == 'not-default'
Exemplo n.º 9
0
def init():
    APP_ROOT = os.path.dirname(os.path.abspath(__file__))
    configs = simpleconfigparser()
    configs.read(APP_ROOT + '/config.ini')
    global config_dict
    config_dict = {s: dict(configs.items(s)) for s in configs.sections()}
    env_path_name = "DATA_CONFIGS"
    if env_path_name in os.environ and os.environ[env_path_name]:
        custom_config_path = os.environ[env_path_name]
        sconfigs = simpleconfigparser()
        sconfigs.read(custom_config_path)
        local_config_dict = {
            s: dict(sconfigs.items(s))
            for s in sconfigs.sections()
        }
        for key, val in local_config_dict.iteritems():
            if key not in config_dict:
                config_dict[key] = val
            else:
                config_dict[key].update(val)
Exemplo n.º 10
0
 def __init__(self, screen_name):
     self.app_route = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
     configfile = simpleconfigparser()
     configfile.read(self.app_route+'/twitter_api/twitter/twitter.ini')
     self.screen_name = screen_name
     self.base_url = 'https://api.twitter.com/1.1/statuses/update.json?status='
     self.access_token = configfile.login.access_token
     self.access_token_secret = configfile.login.access_token_secret
     self.consumer_key = configfile.login.consumer_key
     self.consumer_secret = configfile.login.consumer_secret
     self.b64 = base64.b64encode(urllib2.quote(self.consumer_key) + b':' + urllib2.quote(self.consumer_secret))
     self.url = 'https://api.twitter.com/1.1/statuses/'
Exemplo n.º 11
0
def fix_tempest_conf(network_client, nova_client):
    DEFAULT_CONFIG_DIR = os.path.join(
        os.path.abspath(os.path.dirname(os.path.dirname(__file__))),
        "etc")

    DEFAULT_CONFIG_FILE = "/tempest.conf"
    _path = DEFAULT_CONFIG_DIR + DEFAULT_CONFIG_FILE
    if not os.path.isfile(_path):
        raise Exception("No config file in %s", _path)

    try:
        config = simpleconfigparser()
        config.read(_path)
    except Exception as e:
        print(str(e))

    # get neutron suported extensions
    extensions_dict = network_client.list_extensions()
    extensions_unfiltered = [x['alias'] for x in extensions_dict['extensions']]
    # setup network extensions
    extensions = [x for x in extensions_unfiltered
                  if x not in ['lbaas', 'fwaas']]
    to_string = ""
    for ex in extensions[:-1]:
        if ex != "lbaas" or ex != "fwaas":
            to_string = str.format("{0},{1}", ex, to_string)
    to_string = str.format("{0}{1}", to_string, extensions[-1])

    if CONF.network_feature_enabled.api_extensions != to_string:
        # modify tempest.conf file
        config.set('network-feature-enabled',
                   'api_extensions', to_string)

    # set up image_ref
    if image_ref:
        config.set('compute', 'image_ref', image_ref)

    # set up flavor_ref
    nova_flavors = nova_client.flavors.list()
    nova_flavors.sort(key=lambda x: x.ram)
    smallest_flavor = nova_flavors[0]
    if smallest_flavor.ram > 64:
        print "WARNING: smallest flavor available is greater than 64 mb"
    config.set('compute', 'flavor_ref', smallest_flavor.id)

    # set up allow_tenant_isolation
    if not config.has_section('auth'):
        config.add_section('auth')
    config.set('auth', 'allow_tenant_isolation', 'True')
    
    with open(_path, 'w') as tempest_conf:
        config.write(tempest_conf)
 def test_read_types(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'types.ini'))
     assert int(config.types.int) == 6
     assert int(config.types.int2) == 7
     assert float(config.types.float) == 6.5
     assert float(config.types.float2) == 8.5
     assert config.types.getboolean('boolean_yes_1') is True
     assert config.types.getboolean('boolean_yes_2') is True
     assert config.types.getboolean('boolean_yes_3') is True
     assert config.types.getboolean('boolean_no_1') is False
     assert config.types.getboolean('boolean_no_2') is False
     assert config.types.getboolean('boolean_no_3') is False
 def test_read_types_dict_format(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'types.ini'))
     assert int(config['types']['int']) == 6
     assert int(config['types']['int2']) == 7
     assert float(config['types']['float']) == 6.5
     assert float(config['types']['float2']) == 8.5
     assert config['types'].getboolean('boolean_yes_1') is True
     assert config['types'].getboolean('boolean_yes_2') is True
     assert config['types'].getboolean('boolean_yes_3') is True
     assert config['types'].getboolean('boolean_no_1') is False
     assert config['types'].getboolean('boolean_no_2') is False
     assert config['types'].getboolean('boolean_no_3') is False
Exemplo n.º 14
0
 def test_read_types(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'types.ini'))
     assert int(config.types.int) == 6
     assert int(config.types.int2) == 7
     assert float(config.types.float) == 6.5
     assert float(config.types.float2) == 8.5
     assert config.types.getboolean('boolean_yes_1') is True
     assert config.types.getboolean('boolean_yes_2') is True
     assert config.types.getboolean('boolean_yes_3') is True
     assert config.types.getboolean('boolean_no_1') is False
     assert config.types.getboolean('boolean_no_2') is False
     assert config.types.getboolean('boolean_no_3') is False
Exemplo n.º 15
0
 def __init__(self):
     self.app_route = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
     configfile = simpleconfigparser()
     configfile.read(self.app_route+'/twitter_api/twitter/twitter.ini')
     self.access_token = configfile.login.access_token
     self.access_token_secret = configfile.login.access_token_secret
     self.consumer_key = configfile.login.consumer_key
     self.consumer_secret = configfile.login.consumer_secret
     auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret)
     auth.set_access_token(self.access_token, self.access_token_secret)
     self.api = tweepy.API(auth)
     self.es = Elasticsearch()
     self.today = datetime.datetime.now().date().strftime('%Y-%m-%d')
Exemplo n.º 16
0
 def test_read_types_dict_format(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'types.ini'))
     assert int(config['types']['int']) == 6
     assert int(config['types']['int2']) == 7
     assert float(config['types']['float']) == 6.5
     assert float(config['types']['float2']) == 8.5
     assert config['types'].getboolean('boolean_yes_1') is True
     assert config['types'].getboolean('boolean_yes_2') is True
     assert config['types'].getboolean('boolean_yes_3') is True
     assert config['types'].getboolean('boolean_no_1') is False
     assert config['types'].getboolean('boolean_no_2') is False
     assert config['types'].getboolean('boolean_no_3') is False
    def test_write(self, tmpdir):
        path = join(str(tmpdir), 'new.ini')
        text = b"""[add]
this = woo!

"""

        config = simpleconfigparser()
        config.add.this = 'woo!'
        with open(path, 'w') as handle:
            config.write(handle)

        assert exists(path) is True
        with open(path, 'rb') as handle:
            content = handle.read()
            assert text == content
        os.remove(path)
Exemplo n.º 18
0
    def test_write(self, tmpdir):
        path = join(str(tmpdir), 'new.ini')
        text = b"""[add]
this = woo!

"""

        config = simpleconfigparser()
        config.add.this = 'woo!'
        with open(path, 'w') as handle:
            config.write(handle)

        assert exists(path) is True
        with open(path, 'rb') as handle:
            content = handle.read()
            assert text == content
        os.remove(path)
Exemplo n.º 19
0
def read_tempest_conf():
    default_path = "etc/tempest.conf"
    mido_path = "midokura/utils/tempest.conf.midokura"

    if not os.path.isfile(mido_path):
        raise IOError("No tempest.conf file in %s", mido_path)

    config = simpleconfigparser()
    config.read(default_path)

    for section, keys in sections.items():
        for key in keys:
            if not config.has_option(section, key):
                raise ValueError(
                    "Section " + section + " key " + key + " is missing.\n" +
                    "A minimal tempest.conf MUST specify:\n" +
                    str(sections))

    return config
Exemplo n.º 20
0
def fix_tempest_conf(manager, config):
    default_path = "etc/tempest.conf"
    mido_path = "midokura/utils/tempest.conf.midokura"

    if not os.path.isfile(mido_path):
        raise IOError("No mido tempest.conf file in %s", mido_path)

    midoconfig = simpleconfigparser()
    midoconfig.read(mido_path)

    # get config params from deployment and set into midoconfig
    # TODO: no need for public_net_id, query it ourselves
    for section, keys in sections.items():
        for key in keys:
            value = config.get(section, key)
            midoconfig.set(section, key, value)

    # get neutron suported extensions
    extensions_dict = manager.network_client.list_extensions()
    extensions_unfiltered = [x['alias'] for x in extensions_dict['extensions']]
    # setup network extensions
    extensions = [x for x in extensions_unfiltered
                  if x not in ['lbaas', 'fwaas', 'lbaas_agent_scheduler']]
    to_string = ""
    for ex in extensions[:-1]:
        if ex != "lbaas" or ex != "fwaas" or ex != "lbaas_agent_scheduler":
            to_string = str.format("{0},{1}", ex, to_string)
    to_string = str.format("{0}{1}", to_string, extensions[-1])

    if CONF.network_feature_enabled.api_extensions != to_string:
        # modify tempest.conf file
        midoconfig.set('network-feature-enabled',
                       'api_extensions', to_string)

    # set up public_network_id
    try:
        networks = manager.network_client.list_networks(
            **{'router:external': True})
    except:
        networks = manager.networks_client.list_networks(
            **{'router:external': True})

    if len(networks['networks']) == 0:
        raise ValueError('No public networks available.')

    public_network_id = networks['networks'][0]['id']
    midoconfig.set('network', 'public_network_id', public_network_id)

    # set up image_ref
    if image_ref:
        midoconfig.set('compute', 'image_ref', image_ref)
        midoconfig.set('compute', 'image_ref_alt', image_ref)
    # set up flavor_ref
    # FIXME: workaround to make it work with tempest upstream
    try:
        flavors = manager.flavors_client.list_flavors_with_detail()
        flavors.sort(key=lambda x: x['ram'])
        min_flavor = flavors[0]
        min_ram = min_flavor['ram']
    except:
        flavors = manager.flavors_client.list_flavors()['flavors']
        min_ram = 1024000000
        min_flavor = None
        for flavor in flavors:
            current_ram = manager.flavors_client.show_flavor(
                flavor['id'])['flavor']['ram']
            if current_ram < min_ram:
                min_ram = current_ram
                min_flavor = flavor

    if min_ram > 64:
        print "WARNING: smallest flavor available is greater than 64 mb"
    midoconfig.set('compute', 'flavor_ref', min_flavor['id'])

    # Disable resize feature to disable those tests
    midoconfig.set('compute-feature-enabled', 'resize', 'false')

    with open(default_path, 'w') as tempest_conf:
        midoconfig.write(tempest_conf)
 def test_read_without_quotes(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'without-quotes.ini'))
     assert config.section.item == 'not-default'
     assert config['section']['item'] == 'not-default'
Exemplo n.º 22
0
    },
    'titlovi': {
        'username': '',
        'password': ''
    },
    'subsync': {
        'use_subsync': 'False',
        'use_subsync_threshold': 'False',
        'subsync_threshold': '90',
        'use_subsync_movie_threshold': 'False',
        'subsync_movie_threshold': '70',
        'debug': 'False'
    }
}

settings = simpleconfigparser(defaults=defaults, interpolation=None)
settings.read(os.path.join(args.config_dir, 'config', 'config.ini'))

settings.general.base_url = settings.general.base_url if settings.general.base_url else '/'
base_url = settings.general.base_url


def save_settings(settings_items):
    from database import database

    configure_debug = False
    configure_captcha = False
    update_schedule = False
    update_path_map = False
    configure_proxy = False
    exclusion_updated = False
Exemplo n.º 23
0
        shuffle(words)

        def get_sentence():
            return ' '.join(words[:randint(50, 150)])

assert get_sentence

parser = argparse.ArgumentParser()
parser.add_argument(
    '-c',
    '--config',
    help="config file to use instead of the default shreddit.cfg"
)
args = parser.parse_args()

config = simpleconfigparser()
if args.config:
    config.read(args.config)
else:
    config.read('shreddit.cfg')

hours = config.getint('main', 'hours')
whitelist = config.get('main', 'whitelist')
whitelist_ids = config.get('main', 'whitelist_ids')
sort = config.get('main', 'sort')
verbose = config.getboolean('main', 'verbose')
clear_vote = config.getboolean('main', 'clear_vote')
trial_run = config.getboolean('main', 'trial_run')
edit_only = config.getboolean('main', 'edit_only')
item = config.get('main', 'item')
whitelist_distinguished = config.getboolean('main', 'whitelist_distinguished')
Exemplo n.º 24
0
from __future__ import print_function
from simpleconfigparser import simpleconfigparser

defaults = {'app': {'name': 'default'}}

config = simpleconfigparser(defaults=defaults)
print(config.app.name)

config.read('read.ini')

print(config.app.debug)
print(config.app.getboolean('debug'))
print(config.app.verbose)
print(config.app.getboolean('verbose'))
print(config.app.name)
print(config.app.nope)
Exemplo n.º 25
0
 def test_read_without_quotes(self):
     config = simpleconfigparser()
     config.read(join(test_path, 'without-quotes.ini'))
     assert config.section.item == 'not-default'
     assert config['section']['item'] == 'not-default'
Exemplo n.º 26
0
 def test_read_section_missing(self):
     config = simpleconfigparser()
     assert config.fake.it is None
     assert config['fake']['it'] is None
Exemplo n.º 27
0
def readConfig():
    global WaitTime
    config = simpleconfigparser()
    config.read("config.ini")
    WaitTime = float(config.setting.WaitTime)
 def test_read_item_missing(self):
     config = simpleconfigparser()
     config.fake.me = 'boo'
     assert config.fake.it is None
     assert config['fake']['it'] is None
Exemplo n.º 29
0
 def test_read_item_missing(self):
     config = simpleconfigparser()
     config.fake.me = 'boo'
     assert config.fake.it is None
     assert config['fake']['it'] is None
Exemplo n.º 30
0
    def test_read_items(self):
        config = simpleconfigparser()
        config.read(join(test_path, 'quotes.ini'))
        items = [('single', "win"), ('double', "win again")]

        assert config.section.items() == items
Exemplo n.º 31
0
    # portable for *NIX/Windows
    if os.name == "nt":
        path = os.getcwd() + "\\queries\\"
    elif os.name == "posix":
        path = os.getcwd() + "/queries/"

    for query_file in os.listdir(path):
        if(query_file.endswith("rq")):
            print("Running " + query_file)
            f = open(path + query_file, 'r')
            results.append(graph.query(f.read()))
    return results

if __name__ == "__main__":
    cp = simpleconfigparser.simpleconfigparser()
    cp.read("config/exgest_config.ini")

    store = sparqlstore.SPARQLUpdateStore()
    store.open((cp.settings.endpoint, cp.settings.endpoint))

    g = rdflib.Graph(store)

    results = query_iterator(g)

    result_hash = {}

    field_names = None

    #collect all the data into one data structure
    for result in results:
Exemplo n.º 32
0
    def test_defaults(self):
        defaults = {'section': {'item': 'default'}}

        config = simpleconfigparser(defaults=defaults)
        assert config.section.item == 'default'
        assert config['section']['item'] == 'default'
Exemplo n.º 33
0
    def __init__(self):
        """
        Initialize the class with some basic attributes.
        """

        # check for a banlist.txt file
        if(os.path.isfile("banlist.txt") == False):
            print("Could not find banlist.txt.")

        # check for settings.cfg file
        if(os.path.isfile("settings.cfg") == False):
            raise SettingsError("Could not find settings.cfg.")

        # needed to read the settings.cfg file
        self.config = simpleconfigparser()

        self.config.read("settings.cfg")

        # add terminal output
        self.verbose = self.config.main.getboolean("verbose")

        # maximum threads to crawl. Reddit doesn't
        # like it when you go over 1000
        self.scrapeLimit = int(self.config.main.scrapeLimit)

        # maximum amount of comments/submissions to crawl through in
        # a user's overview
        self.overviewLimit = int(self.config.main.overviewLimit)

        # don't include comments/submissions beneath this score
        self.minScore = int(self.config.main.minScore)

        # give drilldowns flair or not
        self.setflair = self.config.main.getboolean("setflair")

        # calculate similarity or not
        self.similarity = self.config.main.getboolean("similarity")

        # determines how many subreddits the bot calculates similarity for
        self.similarityLimit = int(self.config.main.similarityLimit)

        # sets the cap for sample size
        self.userLimit = int(self.config.main.userLimit)

        # post drilldown to this subreddit
        self.post_to = self.config.main.post_to

        self.useragent = "Reddit Analysis Bot by /u/SirNeon"

        # optional logging
        self.infoLogging = self.config.logging.getboolean("infoLogging")
        self.postLogging = self.config.logging.getboolean("postLogging")
        self.errorLogging = self.config.logging.getboolean("errorLogging")

        # banned defaults and former defaults since
        # reddit autosubscribes users to them
        self.banList = []

        # list of users found in the target subreddit
        self.userList = []

        # list of overlapping subreddits
        self.subredditList = []

        if(self.config.main.getboolean("banList")):
            with open("banlist.txt", 'r') as f:
                for subreddit in f.readlines():
                    subreddit = subreddit.strip('\n')
                    self.banList.append(subreddit)
from __future__ import print_function
from simpleconfigparser import simpleconfigparser

defaults = {
    'app': {
        'name': 'default'
    }
}

config = simpleconfigparser(defaults=defaults)
print(config.app.name)

config.read('read.ini')

print(config.app.debug)
print(config.app.getboolean('debug'))
print(config.app.verbose)
print(config.app.getboolean('verbose'))
print(config.app.name)
print(config.app.nope)
Exemplo n.º 35
0
        'password': '',
        'random_agents': 'True'
    },
    'legendastv': {
        'username': '',
        'password': ''
    },
    'xsubs': {
        'username': '',
        'password': ''
    },
    'assrt': {
        'token': ''
    }}

settings = simpleconfigparser(defaults=defaults)
settings.read(os.path.join(args.config_dir, 'config', 'config.ini'))

base_url = settings.general.base_url

# sonarr url
if settings.sonarr.getboolean('ssl'):
    protocol_sonarr = "https"
else:
    protocol_sonarr = "http"

if settings.sonarr.base_url == '':
    settings.sonarr.base_url = "/"
if not settings.sonarr.base_url.startswith("/"):
    settings.sonarr.base_url = "/" + settings.sonarr.base_url
if settings.sonarr.base_url.endswith("/"):
 def test_read_section_missing(self):
     config = simpleconfigparser()
     assert config.fake.it is None
     assert config['fake']['it'] is None