def test_parent(self): "Fetches values from parent." parent = Settings() child = Settings(parent) parent.a = 1 parent.b = 2 child.b = "overriden" self.assertEqual(child.a, 1) self.assertEqual(child.b, "overriden")
def setUp(self): self.settings = Settings({'foo': 1, 'bar': 'barval'}, {'foo': [1], 'bar': ['barval']}) self.empty_settings = Settings({}, {}) self.same = Settings({'bar': 'barval', 'foo': 1}, {'foo': [1], 'bar': ['barval']}) self.slightly_diff = Settings({'bar': 'barval', 'fooo': 1}, {'fooo': [1], 'bar': ['barval']}) dammit.keep_fkn_trying(self.create_foo_settings_json)
def test_ctor_with_settings_file(self): s = Settings('foo_settings.json', {'foo':[0, 1], 'bar':['barval', 'barval2']}) with self.assertRaises(InvalidSettingError): Settings('foo_settings.json', {'foo':[0, 2], 'bar':['barval', 'barval2']}) with self.assertRaises(InvalidSettingError): Settings('foo_settings.json', {'foo':[0, 1], 'bar':['barval2', 'barval3']})
def test_callable_overwrite_with_callable(self): "Allows overwriting a callable with a callable." x = Settings() x.a = lambda s: s.init + " original" x.a = lambda s: s.a + " and derived" x.init = "init" self.assertEqual(x.a, "init original and derived")
def test_set_get(self): "Sets and gets values." x = Settings() x.a = 1 x.b = 2 self.assertEqual(x.a, 1) self.assertEqual(x.b, 2)
def onBatch1(self): dfilename = askdirectory() if dfilename: pickles = [] for filename in glob.glob(os.path.join(dfilename, '*.py')): module = import_file(filename) if module: basename = os.path.basename(filename) root, ext = os.path.splitext(basename) logging.debug(root) BRANCH = Settings(root) pickles.append(BRANCH.get_filename()) for i in dir(module): if i[0] != '_': value = getattr(module, i) if isinstance(value, all_types): BRANCH.set(i, value) message = "Processed pickles:\n" + plain(pickles) + "\n\n" +\ "Note: Empty pickles was not created!" showinfo("Info", message) self.setText() self.setStatus()
def __init__(self, parent, args): QtCore.QThread.__init__(self, parent) self._running = False self.args = args self.settings = Settings() self.net = Networking(self) BufferUtils.set_app(self) self.scene = Scene(self) self.plugins = PluginLoader() self.mixer = Mixer(self) self.playlist = Playlist(self) self.qt_app = parent self.scene.warmup() self.aubio_connector = None if not self.args.noaudio: self.aubio_thread = QtCore.QThread() self.aubio_thread.start() self.aubio_connector = AubioConnector() self.aubio_connector.onset_detected.connect( self.mixer.onset_detected) self.aubio_connector.fft_data.connect( self.mixer.audio.update_fft_data) self.aubio_connector.pitch_data.connect( self.mixer.audio.update_pitch_data) self.aubio_connector.moveToThread(self.aubio_thread) self.mixer.set_playlist(self.playlist) if self.args.preset: log.info("Setting constant preset %s" % args.preset) self.mixer.set_constant_preset(args.preset)
def test_no_callable_overwrite_non_callable(self): "Disallows overwriting a callable with non-callable." x = Settings() x.a = lambda s: 1 with self.assertRaisesRegex( AttributeError, "^trying to override attribute 'a' " "from a callable value to a non-callable " "one"): x.a = 1
def test_cannot_set_parent_or_attrs(self): "Cannot set the attributes 'parent' or 'attrs'." x = Settings() with self.assertRaisesRegex(AttributeError, "'parent' is a reserved name"): x.parent = 1 with self.assertRaisesRegex(AttributeError, "'attrs' is a reserved name"): x.attrs = 1
def onLoadFile(self): initialdir = os.path.expanduser("~") filename = askopenfilename(initialdir=initialdir, filetypes=[ ('Config files', '*.pickle'), ('All files', '*.*'), ]) if filename: self.s = Settings(filename=filename) self.showInfo()
def test_as_dict(self): "The ``as_dict`` method returns a dictionary of values." x = Settings() x.a = lambda s: s.init + " original" x.a = lambda s: s.a + " and derived" x.init = "init" self.assertEqual(x.as_dict(), { "a": "init original and derived", "init": "init", })
def test_default_injection(self): self.assertEqual( Settings._inject_defaults({}, None), {}) self.assertEqual( Settings._inject_defaults({}, {'foo': 'foov'}), {'foo': 'foov'}) self.assertEqual( Settings._inject_defaults({'foo': 'bar'}, {'foo': 'foov'}), {'foo': 'bar'}) self.assertEqual( Settings._inject_defaults({'foo': None}, {'foo': 'foov'}), {'foo': 'foov'}) self.assertEqual( Settings._inject_defaults( {'foo':'foov','bar':None}, {'foo':'foo_default','bar':'bar_default','baz':'baz_default'}), {'foo':'foov','bar':'bar_default','baz':'baz_default'} ) self.assertEqual( Settings._inject_defaults({'foo':{}}, {'foo':{'bar':'baz'}}), {'foo':{'bar':'baz'}} ) self.assertEqual( Settings._inject_defaults({'foo':{'bar':'barv'}}, {'foo':{'bar':'barv','baz':'bazv'}}), {'foo':{'bar':'barv','baz':'bazv'}} ) s = Settings({}, {'foo': [1, 0], 'bar': ['barval', 'barval2']}, {'foo': 0, 'bar': 'barval'}) self.assertEqual(s['bar'], 'barval') self.assertEqual(s['foo'], 0) with self.assertRaises(InvalidSettingError): Settings({}, {'foo': [1, 0], 'bar': ['barval', 'barval2']}, {'bar': 'barval'}) s = Settings({'bar': 'barval', 'foo': 1}, {'foo': [1, 0], 'bar': ['barval', 'barval2']}, {'bar': 2})
def __init__(self, args, parent=None): self._running = False self.args = args self.settings = Settings() self.net = Networking(self) BufferUtils.set_app(self) self.scene = Scene(self) self.plugins = PluginLoader() self.mixer = Mixer(self) # Create the default layer. default_playlist = Playlist(self, self.args.playlist, 'last_playlist') default_layer = Layer(self, 'default') default_layer.set_playlist(default_playlist) self.mixer.add_layer(default_layer) if self.args.speech_layer: speech_playlist = Playlist(self, self.args.speech_playlist, 'last_speech_playlist') speech_layer = Layer(self, 'speech') speech_layer.set_playlist(speech_playlist) self.mixer.add_layer(speech_layer) self.scene.warmup() self.aubio_connector = None if not self.args.noaudio: self.aubio_connector = AubioConnector() self.aubio_connector.onset_detected.connect( self.mixer.onset_detected) self.osc_server = None if not self.args.noosc: self.osc_server = OscServer(self.args.osc_port, self.args.mixxx_osc_port, self.mixer) self.osc_server.start() if self.args.preset: log.info("Setting constant preset %s" % args.preset) self.mixer.set_constant_preset(args.preset) QtCore.QThread.__init__(self, parent)
def __init__(self, parent, args): QtCore.QThread.__init__(self, parent) self._running = False self.args = args self.settings = Settings() self.net = Networking(self) BufferUtils.set_app(self) self.scene = Scene(self) self.plugins = PluginLoader() self.mixer = Mixer(self) self.playlist = Playlist(self) self.qt_app = parent self.gui = None self.scene.warmup() self.mixer.set_playlist(self.playlist) if self.args.preset: log.info("Setting constant preset %s" % args.preset) self.mixer.set_constant_preset(args.preset)
def __init__(self, args, parent=None): self._running = False self.args = args self.settings = Settings() self.net = Networking(self) self.scene = Scene(SceneLoader(self)) self.plugins = PluginLoader() self.mixer = Mixer(self) self.playlist = Playlist(self) self.aubio_connector = None if self.args.audio: self.aubio_connector = AubioConnector() self.aubio_connector.onset_detected.connect(self.mixer.onset_detected) self.mixer.set_playlist(self.playlist) if self.args.preset: log.info("Setting constant preset %s" % args.preset) self.mixer.set_constant_preset(args.preset) QtCore.QThread.__init__(self, parent)
def test_ctor(self): Settings({'foo': 0}, {'foo': [0, 1]}) Settings({'foo': 1}, {'foo': [0, 1]}) Settings({'foo': 0, 'bar': 'barval'}, {'foo': [0, 1], 'bar': ['barval', 'barval2']}) Settings({'foo': 0, 'bar': 'barval2'}, {'foo': [0, 1], 'bar': ['barval', 'barval2']}) with self.assertRaises(InvalidSettingError): Settings({'foo': 1}, {'foo': [0, 2]}) with self.assertRaises(InvalidSettingError): Settings({'foo': 0, 'bar': 'barval'}, {'foo': [0, 1], 'bar': ['barval1', 'barval2']}) with self.assertRaises(InvalidSettingError): Settings({'foo': 0, 'bar': 'barr'}, {'foo': [1, 0], 'bar': []}) Settings({'foo':['a','b']}, {'foo':['a','b','c','d']}) Settings({'foo':[['a','b']]}, {'foo':[['c','d'],['b','a']]}) Settings({'foo':[['a']]}, {'foo':[['c','d'],['a','b']]}) Settings({'foo':[['b']]}, {'foo':[['c','d'],['a','b']]}) Settings({'foo':[['b'], ['a']]}, {'foo':[['c','d'],['a','b']]}) Settings({'foo':[['b'], ['d']]}, {'foo':[['c','d'],['a','b']]}) Settings({'foo':[['b'], []]}, {'foo':[['c','d'],['a','b']]}) Settings({'foo':{'bar':'a'}}, {'foo':{'bar':['b','a']}}) Settings({'foo':{'bar':'a'}}, {'foo':[{'baz':['c','d']},{'bar':['b','a']}]}) with self.assertRaises(InvalidSettingError): Settings({'foo':{'bar':'a'}}, {'foo':[{'baz':['c','d']},{'bar':['b','a'],'mu':['e','f']}]}) Settings({'foo':{'bar':'a','mu':'e'}}, {'foo':[{'baz':['c','d']},{'bar':['b','a'],'mu':['e','f']}]}) Settings({'foo':{'baz':'d'}}, {'foo':[{'baz':['c','d']},{'bar':['b','a'],'mu':['e','f']}]}) with self.assertRaises(InvalidSettingError): Settings({'foo':[['b','d']]}, {'foo':[['c','d'],['b','a']]}) Settings( {'foo': [{'bar': 3}, {'baz': 4}]}, {'foo': [ {'bar': [4, 3]}, {'baz': [4, 5]}, {'mu': [6, 7]} ]}) Settings( {'foo': {'bar': 'baz'}}, {'foo': [{'bar': ['mu', 'baz']}]})
import lib from lib.settings import Settings from lib.constants import WIDTH, HEIGHT import argparser import neatinterface if __name__ == "__main__": args = argparser.get_args() # pygame initialization pygame.init() screen = pygame.display.set_mode((WIDTH * args.z, HEIGHT * args.z)) clock = pygame.time.Clock() settings = Settings(args) if args.ai == "neat": core = neatinterface.NeatCore() else: core = lib.Core() core.new_game() # main loop while True: # set tick rate to 60 per second clock.tick(settings.tickrate) # update game state core.update() if core.game_over():
def __init__(self, settings_file, batcave='batcave'): """create a Sched handle object with configuration based on the JSON |settings_file| which is the path to the settings file. |batcave| is where all the batch scripts generated by this Sched object are stored. This is 'batcave' by default, but can be any path. Refer to the valid dictionary in the code below to know what the required JSON structure should be for a valid settings file. Refer to the defaults dictionary in the code below to know what the optional settings are. valid={ 'name': '*:str', 'run_cmd': '*:str', 'working_dir': '*:str', 'start_min': '*:bool', 'start_time': [r'\d{2}:\d{2}:re', ''], 'schedule': ['once', 'minute', 'hourly', 'daily', 'quarterly', 'weekly', 'monthly', 'onstart', 'onlogon', 'onidle'], 'days': ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'], 'months': ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'], 'modifier': ['*:int', 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY', ''], 'start_date': [r'\d{2}\\\d{2}\\\d{4}:re', ''], 'end_date': [r'\d{2}\\\d{2}\\\d{4}:re', ''] } defaults={ 'working_dir': '.', 'start_min': True, 'start_time': '', 'days': [], 'months': [], 'modifier': '', 'start_date': '', 'end_date': '' } """ self._settings = Settings( Sched._inject_translation_settings(settings_file), valid={ 'name': '*:str', 'run_cmd': '*:str', 'working_dir': '*:str', 'start_min': '*:bool', 'start_time': [r'\d{2}:\d{2}:re', ''], 'schedule': [ 'once', 'minute', 'hourly', 'daily', 'quarterly', 'weekly', 'monthly', 'onstart', 'onlogon', 'onidle' ], 'days': ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'], 'months': [ 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' ], 'modifier': [ '*:int', 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY', '' ], 'start_date': [r'\d{2}\\\d{2}\\\d{4}:re', ''], 'end_date': [r'\d{2}\\\d{2}\\\d{4}:re', ''] }, defaults={ 'working_dir': '.', 'start_min': True, 'start_time': '', 'days': [], 'months': [], 'modifier': '', 'start_date': '', 'end_date': '' }) if not os.path.isdir(batcave): dammit.keep_fkn_trying(self._create_batcave, [batcave]) self._batcave = batcave
from lib.talker import Talker from lib.listener import Listener from lib.settings import Settings from lib.utils import * app = Flask(__name__) #app._static_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static") app.config['SECRET_KEY'] = 'M-LkyLF&sid=379941accd8541ef9f9c7e8efb323c82' socketio = SocketIO(app, async_mode='threading') pusher = Pusher(socketio) talkers = [] listeners = [] settings = Settings(app) logging.basicConfig(level=logging.INFO, filename=os.path.join(app.root_path, "log", "nmea_muxer.log"), filemode='w', format='%(message)s') logging.getLogger('werkzeug').setLevel(logging.WARN) colors = { "Red": "#f44336", "Pink": "#e91e63", "Purple": "#9c27b0", "Deep purple": "#673ab7", "Indigo": "#3f51b5", "Blue": "#2196f3",
def onLoadDefault(self): self.s = Settings() self.showInfo()
print('WooferBot ' + wooferbotVersion + ' Copyright (C) 2019 Tomaae') print('This program comes with ABSOLUTELY NO WARRANTY.') print('This is free software, and you are welcome to redistribute it') print('under certain conditions.') print( 'By using this program, you accept the terms of the software license agreement.' ) print('') signal(SIGINT, exit_gracefully) signal(SIGTERM, exit_gracefully) signal(SIGBREAK, exit_gracefully) # Initialize settings path_root = path.dirname(path.realpath(__file__)) settings = Settings(path_root=path_root) # Initialize nanoleaf nanoleaf = Nanoleaf(settings=settings) # Initialize Philips HUE hue = Hue(settings=settings) # Initialize Philips HUE yeelight = Yeelight(settings=settings) settings.save() # Initialize twitch chatbot chatbot = Twitch(settings=settings, woofer=None, bot=True) if settings.UseChatbot and len(
import random import pygame from lib.settings import Settings from lib.constants import WIDTH, HEIGHT from lib.constants import START_POSITION, GRAVITY, MOVE_SPEED from lib.constants import HOLE_SIZE from lib.constants import WALL_SPEED, CLOUD_SPEED pygame.init() settings = Settings() def load_image(file): image = pygame.image.load(file) return image class Ball: # default image for size reference __image = load_image("./rsc/img/blue_ball_falling.png") # lazy implementation of colored balls __images = { "blue_jumping": load_image("./rsc/img/blue_ball_jumping.png"), "blue_falling": load_image("./rsc/img/blue_ball_falling.png"), "green_jumping": load_image("./rsc/img/green_ball_jumping.png"), "green_falling": load_image("./rsc/img/green_ball_falling.png"), "yellow_jumping": load_image("./rsc/img/yellow_ball_jumping.png"), "yellow_falling": load_image("./rsc/img/yellow_ball_falling.png"), "red_jumping": load_image("./rsc/img/red_ball_jumping.png"), "red_falling": load_image("./rsc/img/red_ball_falling.png"),
import sys from lib.models import * from lib.database import db from lib.settings import Settings SETTINGS = Settings('settings.yml') methods = ['threads'] def threads(): for thread in db.query(Thread).all(): for msg in thread.messages: if msg.sender == SETTINGS.okcupid['username']: print '[OkBot]: %s' % msg.body.encode('utf-8').strip() else: print '[Suitor]: %s' % msg.body.encode('utf-8').strip() print def print_usage(): print >> sys.stderr, 'Usage: %s [%s]' % (sys.argv[0], ', '.join(methods)) if __name__ == '__main__': try: if sys.argv[1] in methods: globals()[sys.argv[1]]() else: print_usage() except IndexError: print_usage()
print("under certain conditions.") print( "By using this program, you accept the terms of the software license agreement." ) print("") signal(SIGINT, exit_gracefully) signal(SIGTERM, exit_gracefully) signal(SIGBREAK, exit_gracefully) # Initialize GUI gui = Gui() # Initialize settings path_root = getcwd() settings = Settings(gui=gui, path_root=path_root) gui.attach_settings(settings=settings) # Initialize nanoleaf nanoleaf = Nanoleaf(settings=settings) # Initialize Philips HUE hue = Hue(settings=settings) # Initialize Philips HUE yeelight = Yeelight(settings=settings) settings.save() # Initialize twitch chatbot chatbot = Twitch(settings=settings, woofer=None, gui=gui, bot=True)
############################################################ # main def main(settings, simulator_settings): pipelines_to_run = instantiate_pipelines(settings, simulator_settings) return run_pipelines(pipelines_to_run, simulator_settings) ############################################################ if __name__ == '__main__': """ """ parser = argparse.ArgumentParser() parser.add_argument('-r', '--run_settings', action='store', required=True) parser.add_argument('-s', '--run_serial', action='store_true', help='Default run parallel') parser.add_argument('-d', '--debug_mode', action='store_true', help='Debug') args = parser.parse_args() if args.debug_mode: args.run_serial = True simulator_settings = {'debug_mode': args.debug_mode, 'run_serial': args.run_serial} logger.info("\nINPUT SETTINGS\n") datasets_settings = Settings(args.run_settings) datasets_settings.print_settings() main(datasets_settings, simulator_settings)