示例#1
0
    def test_raises_file_not_found(self):
        """
        Test that it raises if file is not found
        """
        with self.assertRaises(PyYAMLConfigError) as err:
            load_config('tests/myconfig.yaml')

        self.assertEqual(
            str(err.exception),
            'Could not open config file: tests/myconfig.yaml',
        )
示例#2
0
    def test_raises_parse_error(self):
        """
        Test that it raises if file can't be parsed
        """
        with self.assertRaises(PyYAMLConfigError) as err:
            load_config('tests/faulty_config.yaml')

        self.assertEqual(
            str(err.exception),
            'Could not parse config file: tests/faulty_config.yaml',
        )
示例#3
0
 def test_loads_config(self):
     """
     Tests that config can be loaded
     """
     config = load_config('tests/config.yaml')
     self.assertEqual(
         config,
         {'mykey': 'myvalue'},
     )
示例#4
0
文件: tests.py 项目: marhag87/budget
 def run_query(query):
     config = load_config('tests/test_config.yaml')
     with psycopg2.connect(
             dbname=config.get('database'),
             user=config.get('username'),
             password=config.get('password'),
             host=config.get('hostname'),
     ) as con:
         with con.cursor() as cur:
             cur.execute(query)
             return cur.fetchone()
示例#5
0
 def __init__(self, configfile=None):
     if configfile is None:
         if os.name == 'nt':
             configfile = f'{Path.home()}\workday.yaml'
         else:
             configfile = f'{Path.home()}/.config/workday.yaml'
     self.configfile = configfile
     self.config = load_config(configfile)
     self.days_file = self.config.get('days_file')
     self.until_today = timedelta()
     self.until_today_days = 0
     self.total_time = timedelta()
     self.total_days = 0
     self.week_days = []
     self.all_days = []
示例#6
0
 def __init__(self, url):
     try:
         self.config = load_config(
             expanduser('~/.config/jenkins_control.yaml'))
         self.config_loaded = True
     except PyYAMLConfigError:
         self.config_loaded = False
     if url is None:
         if self.config_loaded is True:
             self.url = self.config.get('url')
         else:
             raise Exception(
                 'No url provided on commandline or in config file')
     else:
         self.url = url
     self.session = requests.session()
示例#7
0
import psutil
from pyyamlconfig import load_config
import socket
import time
import graphyte
import sys

hostname = socket.gethostname()
config = load_config('config.yaml')
if config is None:
    sys.exit('Config is empty, please supply a whitelist')

whitelist = config.get('whitelist')
if whitelist is None or whitelist == []:
    sys.exit('Whitelist is empty, exiting')

carbon = config.get('carbon', {})
graphyte.init(
    carbon.get('hostname', 'localhost'),
    prefix=f'gm.{hostname}',
)


def get_memory():
    """Get a per process summary of all memory used by all processes in the whitelist"""
    procs = {}
    for program, rss in [(x.name(), x.memory_info().rss)
                         for x in psutil.process_iter()
                         if x.name() in whitelist]:
        if program in procs:
            procs[program] += rss
示例#8
0
from pathlib import Path
import googlemaps
from datetime import datetime
from pyyamlconfig import load_config

config = load_config(f'{Path.home()}/.config/fredagslunch.yaml')
data = config.get('data')
destination = config.get('destination')

people_with_cars = []
for person in data:
    if person.get('car'):
        people_with_cars.append(person)

gmaps = googlemaps.Client(key=config.get('key'))

shortest_distance = None
shortest_order = []

for person_with_car in people_with_cars:
    waypoints = set([x.get('location') for x in data])
    directions_result = gmaps.directions(
        person_with_car.get('location'),
        destination,
        mode="driving",
        departure_time=datetime.now(),
        waypoints=waypoints,
        optimize_waypoints=True,
    )

    distance = 0
示例#9
0
@app.route('/configure')
def configure():
    clients = []
    for client in app.config.get('clients'):
        clients.append(client)
    return render_template(
        'configure.html',
        clients=clients,
    )


@app.route('/sidebar')
def sidebar():
    clients = []
    for client in app.config.get('clients'):
        clients.append(client)
    return render_template(
        'sidebar.html',
        clients=clients,
    )


if __name__ == '__main__':
    try:
        _CONFIG = load_config('config.yaml')
    except PyYAMLConfigError:
        _CONFIG = {}
    app.config['clients'] = _CONFIG.get('clients', [])
    app.run(debug=_CONFIG.get('debug', False))
示例#10
0
文件: budget.py 项目: marhag87/budget
 def __init__(self, config=None):
     if config is None:
         config = f'{Path.home()}/.config/budget.yaml'
     self.config = load_config(config)
示例#11
0
 def config(self):
     """Fetch config from ~/.config/c20.yaml"""
     if self._config is None:
         self._config = load_config(f'{Path.home()}/.config/c20.yaml')
     return self._config
示例#12
0
#!/bin/env python
# -*- coding: utf-8 -*-
"""A bot for discord that links videos and prints topic changes"""
from datetime import datetime
from random import choice
from html.parser import HTMLParser
import requests
import yaml
from pyyamlconfig import load_config
import discord
from imgurpython import ImgurClient

CLIENT = discord.Client()
CFG = load_config('config.yaml')


def get_random_caturday_image():
    """Return url to random caturday image from album"""
    client = ImgurClient(
        CFG.get('imgur').get('clientid'),
        CFG.get('imgur').get('clientsecret')
    )
    album = client.get_album(CFG.get('imgur').get('caturdayalbum'))
    return choice([image.get('link') for image in album.images])


def get_days_left(user):
    """Return days left that user has to toil"""
    end_date = CFG.get('daysleft').get(str(user))
    if end_date is None:
        return "http://i.imgur.com/kkrihuR.png"
示例#13
0
文件: bot.py 项目: marhag87/gitbot
    PyYAMLConfigError,
)


class BotError(Exception):
    """
    Generic Bot Error
    """
    pass


_CONFIGFILE = 'config.yaml'
_CLIENT = discord.Client()
_SLEEPTIME = 5
try:
    _CONFIG = load_config(_CONFIGFILE)
except PyYAMLConfigError:
    _CONFIG = {}


@_CLIENT.event
async def on_ready():
    """
    Print user information once logged in
    """
    print('Logged in as')
    print(_CLIENT.user.name)
    print(_CLIENT.user.id)
    print('------')
    perms = discord.Permissions.none()
    perms.read_messages = True