def load_config(self): config.load() adsrconf = config.get('adsr') if adsrconf: for k, v in adsrconf.iteritems(): setattr(self.adsrList, k, v) self.adsrw.adsr = self.adsrList sounds = config.get('sounds') if sounds: for snd in sounds['files']: self.add_sound(str(snd)) globs = config.get('globals') if globs: self.invert_control = globs['invert_control'] self.trigger_shadow = globs['trigger_shadow'] if self.invert_control: self.invert.setCheckState(QtCore.Qt.Checked) if self.trigger_shadow: self.invert_slope.setCheckState(QtCore.Qt.Checked) self.sldVolumen.setValue(globs['default_volume']) for x in xrange(globs['sensor_count']): self.add_sensor()
def _request(self, method, path, data=None, body=None, headers=None, params=None, stream=False): """Creates a request against the Remarkable Cloud API This function automatically fills in the blanks of base url & authentication. Credit: https://github.com/subutux/rmapy/blob/master/rmapy/api.py Args: method: The request method. path: complete url or path to request. data: raw data to put/post/... body: the body to request with. This will be converted to json. headers: a dict of additional headers to add to the request. params: Query params to append to the request. stream: Should the response be a stream? Returns: A Response instance containing most likely the response from the server. """ config = cfg.load() if headers is None: headers = {} if not path.startswith("http"): if not path.startswith('/'): path = '/' + path url = "%s%s" % (BASE_URL, path) else: url = path _headers = { "user-agent": USER_AGENT, } user_token = cfg.get("authentication.user_token") if user_token != None: _headers["Authorization"] = "Bearer %s" % user_token for k in headers.keys(): _headers[k] = headers[k] r = requests.request(method, url, json=body, data=data, headers=_headers, params=params, stream=stream, timeout=60 * 2) return r
def load_model(model_path): model_config_path = os.path.join(os.path.dirname(model_path), "config.yml") model_name = load(model_config_path, "model_name") if hasattr(MODELS[model_name], "custom_objects"): return keras_load_model( model_path, custom_objects=MODELS[model_name].custom_objects, compile=False) else: return keras_load_model(model_path, compile=False)
def main(): parser = argparse.ArgumentParser( description='A light tunnel proxy that helps you bypass firewalls') parser.add_argument('--version', action='store_true', default=False, help='show version information') proxy_options = parser.add_argument_group('Proxy options') proxy_options.add_argument('--save', metavar='CONFIG', help='path to dump config') proxy_options.add_argument('-c', metavar='CONFIG', help='path to config file') proxy_options.add_argument('-s', metavar='SERVER_ADDR', help='server address, default: 0.0.0.0') proxy_options.add_argument('-p', metavar='SERVER_PORT', type=int, help='server port, default: 443') proxy_options.add_argument('-k', metavar='PASSWORD', help='password') proxy_options.add_argument('--random', action='store_true', default=False, help='generate a random password to use') args = parser.parse_args() if args.version: print('lightsocks - modified by @nanqinlang') sys.exit(0) config = lsConfig.Config(None, None, None, None, None) if args.c: try: with open(args.c, encoding='utf-8') as f: file_config = lsConfig.load(f) except lsConfig.InvalidFileError: parser.print_usage() print(f'invalid config file {args.c!r}') sys.exit(1) except FileNotFoundError: parser.print_usage() print(f'config file {args.c!r} not found') sys.exit(1) config = config._replace(**file_config._asdict()) if args.s: serverAddr = args.s # TODO: 验证 serverAddr 有效性 config = config._replace(serverAddr=serverAddr) if args.p: serverPort = args.p # TODO: 验证 serverPort 有效性 config = config._replace(serverPort=serverPort) if args.k: try: password = loadsPassword(args.k) config = config._replace(password=password) except InvalidPasswordError: parser.print_usage() print('invalid password') sys.exit(1) if config.serverAddr is None: config = config._replace(serverAddr='0.0.0.0') if config.serverPort is None: config = config._replace(serverPort=443) if config.password is None and not args.random: parser.print_usage() print('need PASSWORD, please use [-k PASSWORD] or ' 'use [--random] to generate a random password') sys.exit(1) if args.random: print('generate random password') config = config._replace(password=randomPassword()) if args.save: print(f'dump config file into {args.save!r}') with open(args.save, 'w', encoding='utf-8') as f: lsConfig.dump(f, config) run_server(config)
import discord import core from discord.ext import commands from utils import config # Configs token = config.load('bot').get('token') bot = commands.Bot(command_prefix='!') # Cogs startup_extensions = ["core.fun", "core.xkcd"] for extension in startup_extensions: try: bot.load_extension(extension) except Exception as e: exc = '{}: {}'.format(type(e).__name__, e) print('Failed to load extension {}\n{}'.format(extension, exc)) # Run bot.run(token)
log_prob=log_prob, log_prob_sum=log_prob_sum, log_prob_ratio=log_prob_ratio, **other_data) tractogram = Tractogram(streamlines=tractogram.streamlines, data_per_point=data_per_point, affine_to_rasmm=np.eye(4)) out_dir = os.path.join(os.path.dirname(config["dwi_path"]), "marked_fibers", timestamp()) os.makedirs(out_dir, exist_ok=True) marked_path = os.path.join(out_dir, "marked.trk") TrkFile(tractogram, trk_file.header).save(marked_path) config["out_dir"] = out_dir configs.save(config) if __name__ == '__main__': parser = argparse.ArgumentParser(description="Mark fiber statistics.") parser.add_argument("config_path", type=str) args = parser.parse_args() config = load(args.config_path) mark(config)
def main(): parser = argparse.ArgumentParser( description='A light tunnel proxy that helps you bypass firewalls') parser.add_argument('--version', action='store_true', default=False, help='show version information') proxy_options = parser.add_argument_group('Proxy options') proxy_options.add_argument('--save', metavar='CONFIG', help='path to dump config') proxy_options.add_argument('-c', metavar='CONFIG', help='path to config file') proxy_options.add_argument( '-u', metavar='URL', help='url contains server address, port and password') proxy_options.add_argument('-s', metavar='SERVER_ADDR', help='server address') proxy_options.add_argument('-p', metavar='SERVER_PORT', type=int, help='server port, default: 443') proxy_options.add_argument( '-b', metavar='LOCAL_ADDR', help='local binding address, default: 127.0.0.1') proxy_options.add_argument('-l', metavar='LOCAL_PORT', type=int, help='local port, default: 1082') proxy_options.add_argument('-k', metavar='PASSWORD', help='password') args = parser.parse_args() if args.version: print('lightsocks - modified by @nanqinlang') sys.exit(0) config = lsConfig.Config(None, None, None, None, None) if args.c: try: with open(args.c, encoding='utf-8') as f: file_config = lsConfig.load(f) except lsConfig.InvalidFileError: parser.print_usage() print(f'invalid config file {args.c!r}') sys.exit(1) except FileNotFoundError: parser.print_usage() print(f'config file {args.c!r} not found') sys.exit(1) config = config._replace(**file_config._asdict()) if args.u: try: url_config = lsConfig.loadURL(args.u) except lsConfig.InvalidURLError: parser.print_usage() print(f'invalid config URL {args.u!r}') sys.exit(1) config = config._replace(**url_config._asdict()) if args.s: serverAddr = args.s # TODO: 验证 serverAddr 有效性 config = config._replace(serverAddr=serverAddr) if args.p: serverPort = args.p # TODO: 验证 serverPort 有效性 config = config._replace(serverPort=serverPort) if args.b: localAddr = args.b # TODO: 验证 localPort 有效性 config = config._replace(localAddr=localAddr) if args.l: localPort = args.l # TODO: 验证 localPort 有效性 config = config._replace(localPort=localPort) if args.k: try: password = loadsPassword(args.k) config = config._replace(password=password) except InvalidPasswordError: parser.print_usage() print('invalid password') sys.exit(1) if config.localAddr is None: config = config._replace(localAddr='127.0.0.1') if config.localPort is None: config = config._replace(localPort=1082) if config.serverPort is None: config = config._replace(serverPort=443) if config.password is None: parser.print_usage() print('need PASSWORD, please use [-k PASSWORD]') sys.exit(1) if config.serverAddr is None: parser.print_usage() print('need SERVER_ADDR, please use [-s SERVER_ADDR]') if args.save: print(f'dump config file into {args.save!r}') with open(args.save, 'w', encoding='utf-8') as f: lsConfig.dump(f, config) run_server(config)
more_args.append(path) return more_args if __name__ == '__main__': parser = argparse.ArgumentParser(description="Dispatch several runs.") parser.add_argument("base_config_path", type=str) parser.add_argument("--action", type=str, choices=ACTIONS, default="training") args, more_args = parser.parse_known_args() config = load(args.base_config_path) assert config["action"] == args.action procs = [] if args.action in ["training", "inference"]: if (args.action == "inference" and "*" in config["model_path"] and "--model_path" not in more_args): more_args += glob_to_more_args(config["model_path"], "model_path") configurations = make_configs_from(config, more_args) target = train if args.action == "training" else run_inference
class Config: config = config.YAMLConfiguration("config.yml") config.load()
await asyncio.sleep(2) leader = await self.check_leader(leader) if not leader: continue changed, song_id, playing = await self.check_new( leader, song_id, playing) if changed: followers = await self.check_followers(followers) await self.sync(leader, followers, song_id, playing) async def main(): store = await get_store() spotify = Spotify() worker = Worker(store, spotify) await worker.run() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-c", "--config", default=None, help="Supplemental config file to load") args = parser.parse_args() if args.config: config.load(args.config) logging.basicConfig(level=config.LOG_LEVEL) logging.debug("Debug logs enabled") asyncio.run(main())
''' AHUCV server dynamic DNS updater ''' from re import MULTILINE, findall from datetime import datetime import requests from utils import config, DrCOM, DnsPod APP_VERSION = '1.0.0' CONFIG_PATH = 'config.ini' username, password = config.load(CONFIG_PATH, 'AUTH') dnspod_id, dnspod_token, author_email = config.load(CONFIG_PATH, 'DNSPOD') sub_domain, domain = config.load(CONFIG_PATH, 'DOMAIN') mac_address, *_ = config.load(CONFIG_PATH, 'CLIENT') need_update = False update_result = '' new_ip = DrCOM.get_ip_by_mac_address(username, password, mac_address) dnspod_client = DnsPod.DnsPodClient(dnspod_id, dnspod_token, author_email, APP_VERSION) record_id, old_ip = dnspod_client.get_record(sub_domain, domain) if new_ip and old_ip and new_ip != old_ip: need_update = True result = dnspod_client.update_ip(sub_domain, domain, record_id, new_ip) update_result = 'Success' if result else 'Failed' print(f'''
def loader(self): temp = config.load("systemconfig") for k, v in temp.iteritems(): self.__setattr__(k,v)