def save_plugin(self, name, **settings): ''' Saves any changes to the config file. ''' stanza = 'Plugin: %s' % name.lower() conf = ConfigParser() conf.read(config.get_config_file()) settings['name'] = name if not conf.has_section(stanza): conf.add_section(stanza) for item in settings: conf.set(stanza, item, settings[item]) with open(config.get_config_file(), 'w') as cfile: conf.write(cfile)
def __init__(self, name): self.name = name self._config_file = config.get_config_file() try: self.get_config() except: self.set_config()
def open(): """Open config from saved file (if exists).""" config = cfg.get_config_file(_Config.SERIAL_FILE, _Config.CONFIG_DIR, cls=_Config) if config is None: config = _Config() return config
def plugin_listing(self): ''' Returns a list of dictionaries with the installed plugins that baskit is aware of. ''' conf = ConfigParser() conf.read(config.get_config_file()) plugins = [] for section in conf.sections(): if 'Plugin:' in section: plugins.append(self.get_plugin(conf.get(section, 'name'))) return plugins
def delete_plugin(self, name): ''' Removes the plugin from the server. ''' plug = self.get_plugin(name) # We are setting these here as I'm lazy and we will be using these a # lot in this function. pjoin = os.path.join exists = os.path.exists if exists(pjoin(self.plugin_path, plug['jar'])): os.remove(pjoin(self.plugin_path, plug['jar'])) if exists(pjoin(self.plugin_path, plug['jar'][:-4])): shutil.rmtree(pjoin(self.plugin_path, plug['jar'][:-4])) if exists(pjoin('%s_diabled' % self.plugin_path, plug['jar'])): os.remote(pjoin('%s_diabled' % self.plugin_path, plug['jar'])) conf = ConfigParser() conf.read(config.get_config_file()) conf.remove_section('Plugin: %s' % name.lower()) with open(config.get_config_file(), 'w') as cfile: conf.write(cfile) print 'Plugin %s removed and (hopefully) all associated data.' % plug['name']
def open(workspace, project_name): """Retrieve project from settings by its name and workspace.""" directory = os.path.join(workspace, project_name) project = config.get_config_file('', directory=directory, extension=PROJECT_MAIN_FILE_EXT, cls=Project) if project is None: raise InvalidProject("Current project is invalid.") project.project_dir = directory project.filename = os.path.join(directory, PROJECT_MAIN_FILE) project.workspace = workspace project.name = project_name return project
def get_plugin(self, name): ''' Returns a dictionary with the plugin information. ''' stanza = 'Plugin: %s' % name.lower() conf = ConfigParser() conf.read(config.get_config_file()) if conf.has_section(stanza): return { 'name': conf.get(stanza, 'name'), 'jar': conf.get(stanza, 'jar'), 'bukget': conf.get(stanza, 'bukget'), 'md5': conf.get(stanza, 'md5'), 'version': conf.get(stanza, 'version'), 'enabled': conf.getboolean(stanza, 'enabled'), } else: return None
def __init__(self): '''Baskit server initialization ''' self._config_file = config.get_config_file() self.get_config()
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Script for setting CodeCook bash program configurations """ import ConfigParser import os import sys from config import get_config_file path = 'codecook-bash' config_file = get_config_file() print "Please supply the information needed to get the codecook-bash program up and running." # check no accidental config overwrite if os.path.isfile(config_file): print "Configuration file exists, overwrite it?" prompt = raw_input("[y/N] ") if prompt != "y": sys.exit("Not overwriting config file.") # get config info cc_user = raw_input("What is your username?: ") cc_key = raw_input("What is your API key?: ") # actually write config
#!/usr/bin/env python # -*- coding: utf-8 -*- import ConfigParser import sys import urwid from API import CodecookApi from config import get_config_file from menu import * # # Load settings # # print "opening config file..." config = ConfigParser.ConfigParser() config_file = get_config_file() with open(config_file, 'r') as configfile: config.read(config_file) cc_user = config.get('DEFAULT', 'cc_user') cc_key = config.get('DEFAULT', 'cc_key') if cc_user == None or cc_key == None: print "user data configuration not set. Please run config program." api = CodecookApi() api.configure(cc_user, cc_key) # print "configuration loaded." #
import argparse from runner import Runner from config import ConfigStorage, get_config_file from gui import Gui if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--no-tray", dest='no_tray', action='store_true', default=False) args, _ = parser.parse_known_args() config_storage = ConfigStorage(get_config_file()) if args.no_tray: config = config_storage.load() aw_runner = Runner(config) aw_runner.run_all() else: stats_runner = Runner(config_storage.load()) gui = Gui(config_storage, stats_runner) gui.run_headless()
#!/usr/bin/env python import os import sys from shutil import copyfile import paths, download_utils, extract_utils import config as config_utils for config_directory, config, metadata in config_utils.iterate_datasets(): url = config_utils.render_url(config, metadata) download_directory = paths.build_download_directory(metadata) os.makedirs(download_directory, exist_ok=True) if "compression" in config: download_path = os.path.join(download_directory, "dataset.%s" % config["compression"]) download_utils.download_with_progress(download_path, url) if config["compression"] != "zip": print("Unsupported compression: %s!" % config["compression"]) sys.exit(1) extract_utils.unzip(download_path, download_directory) else: download_path = os.path.join(download_directory, "dataset.%s" % config["format"]) download_utils.download_with_progress(download_path, url) src_config_file = config_utils.get_config_file(config_directory) dest_config_file = config_utils.get_config_file(download_directory) print("Copying config file from %s to %s" % (src_config_file, dest_config_file)) copyfile(src_config_file, dest_config_file)
elif arg == "--log-file": if f.next_arg_exist(i, args): log_file = get_log_file(args[i + 1]) elif arg == "--filters": if not "--conf-file" in args: if f.next_arg_exist(i, args): filters_list = f.config_filter(args[i + 1], log_file) if len(filters_list) == 0: print("Enter an existing filter") else: f.application_filter(entry_folder, output_folder, filters_list, log_file) dump_log(log_file) else: entry_folder = get_config_file(conf_file)[0]["input_dir"] output_folder = get_config_file(conf_file)[1]["output_dir"] log_file = get_config_file(conf_file)[2]["log_file"] filters_list = get_config_file(conf_file)[3]["content"] if f.next_arg_exist(i, args): filters_list = f.config_filter(args[i + 1], log_file) if len(filters_list) == 0: print("Enter an existing filter") else: f.application_filter(entry_folder, output_folder, filters_list, log_file) dump_log(log_file) if arg == "--config-file": if not "--filters" in args: if f.next_arg_exist(i, args):
def __init__(self): ''' Main Onionr class. This is for the CLI program, and does not handle much of the logic. In general, external programs and plugins should not use this class. ''' try: os.chdir(sys.path[0]) except FileNotFoundError: pass # Load global configuration data exists = os.path.exists(config.get_config_file()) config.set_config( { 'devmode': True, 'log': { 'file': { 'output': True, 'path': 'data/output.log' }, 'console': { 'output': True, 'color': True } } } ) # this is the default config, it will be overwritten if a config file already exists. Else, it saves it config.reload() # this will read the configuration file into memory settings = 0b000 if config.get('log', {'console': {'color': True}})['console']['color']: settings = settings | logger.USE_ANSI if config.get('log', {'console': { 'output': True }})['console']['output']: settings = settings | logger.OUTPUT_TO_CONSOLE if config.get('log', {'file': {'output': True}})['file']['output']: settings = settings | logger.OUTPUT_TO_FILE logger.set_file( config.get('log', {'file': { 'path': 'data/output.log' }})['file']['path']) logger.set_settings(settings) if config.get('devmode', True): self._developmentMode = True logger.set_level(logger.LEVEL_DEBUG) else: self._developmentMode = False logger.set_level(logger.LEVEL_INFO) self.onionrCore = core.Core() self.onionrUtils = OnionrUtils(self.onionrCore) # Handle commands self.debug = False # Whole application debugging if os.path.exists('data-encrypted.dat'): while True: print('Enter password to decrypt:') password = getpass.getpass() result = self.onionrCore.dataDirDecrypt(password) if os.path.exists('data/'): break else: logger.error('Failed to decrypt: ' + result[1]) else: if not os.path.exists('data/'): os.mkdir('data/') os.mkdir('data/blocks/') if not os.path.exists(self.onionrCore.peerDB): self.onionrCore.createPeerDB() pass if not os.path.exists(self.onionrCore.addressDB): self.onionrCore.createAddressDB() # Get configuration if not exists: # Generate default config # Hostname should only be set if different from 127.x.x.x. Important for DNS rebinding attack prevention. if self.debug: randomPort = 8080 else: while True: randomPort = random.randint(1024, 65535) if self.onionrUtils.checkPort(randomPort): break config.set( 'client', { 'participate': 'true', 'client_hmac': base64.b64encode( os.urandom(32)).decode('utf-8'), 'port': randomPort, 'api_version': API_VERSION }, True) self.cmds = { '': self.showHelpSuggestion, 'help': self.showHelp, 'version': self.version, 'config': self.configure, 'start': self.start, 'stop': self.killDaemon, 'stats': self.showStats, 'enable-plugin': self.enablePlugin, 'enplugin': self.enablePlugin, 'enableplugin': self.enablePlugin, 'enmod': self.enablePlugin, 'disable-plugin': self.disablePlugin, 'displugin': self.disablePlugin, 'disableplugin': self.disablePlugin, 'dismod': self.disablePlugin, 'reload-plugin': self.reloadPlugin, 'reloadplugin': self.reloadPlugin, 'reload-plugins': self.reloadPlugin, 'reloadplugins': self.reloadPlugin, 'listpeers': self.listPeers, 'list-peers': self.listPeers, 'addmsg': self.addMessage, 'addmessage': self.addMessage, 'add-msg': self.addMessage, 'add-message': self.addMessage, 'pm': self.sendEncrypt, 'gui': self.openGUI, 'addpeer': self.addPeer, 'add-peer': self.addPeer, 'add-address': self.addAddress, 'addaddress': self.addAddress, 'connect': self.addAddress } self.cmdhelp = { 'help': 'Displays this Onionr help menu', 'version': 'Displays the Onionr version', 'config': 'Configures something and adds it to the file', 'start': 'Starts the Onionr daemon', 'stop': 'Stops the Onionr daemon', 'stats': 'Displays node statistics', 'enable-plugin': 'Enables and starts a plugin', 'disable-plugin': 'Disables and stops a plugin', 'reload-plugin': 'Reloads a plugin', 'list-peers': 'Displays a list of peers', 'add-peer': 'Adds a peer (?)', 'add-msg': 'Broadcasts a message to the Onionr network', 'pm': 'Adds a private message to block', 'gui': 'Opens a graphical interface for Onionr' } command = '' try: command = sys.argv[1].lower() except IndexError: command = '' finally: self.execute(command) if not self._developmentMode: encryptionPassword = self.onionrUtils.getPassword( 'Enter password to encrypt directory: ') self.onionrCore.dataDirEncrypt(encryptionPassword) shutil.rmtree('data/') return
return new_fasta if __name__ == "__main__": import config parser = argparse.ArgumentParser(description="Runs a blast.") parser.add_argument("--query", dest="query", required=True) parser.add_argument("--subject", dest="subject", required=True) parser.add_argument("--strategy", dest="strategy", default="blastn") parser.add_argument("--config", dest="config_file") args = parser.parse_args() config_values = config.get_config_file(args.config_file) # Use all available CPUs pool = Pool(cpu_count()) if args.strategy == "blastn": format_db(args.subject, "nucl", config_values) # Lower the nice value os.nice(5) # Unset the file_source config_values.set("paths", "input_path", "") for file_handler in split_query(args.query): blastout = blastn( file_handler.name, args.subject, config_values) # Delete the intermediary Tempfile os.unlink(file_handler.name)