def test_config_load_save(self): """test modifying, saving, and reloading the config""" with open_config(TEST_CONFIG) as conf1: conf1.directories.append( Directory("/path/to/foo", "zip", 1.23, True)) with open_config(TEST_CONFIG) as conf2: self.assertEqual(conf1, conf2)
def process(target="config.txt", *, command_line=False, should_submit=None): if not command_line: print_ = lambda *args, **kwargs: None else: print_ = print # Open config file print_(f"Opening config file: {target}") try: file = open(target) except FileNotFoundError: if not command_line: raise print_(f"File doesn't exist: {target}") sys.exit(1) # Read and process the file with file: print_("Reading config entries...") config = open_config(file) print_(f"Form URL: {config.url}") messages = parse_entries(config.entries, on_prompt=prompt_entry) data = format_entries(config.entries, messages) print_(f"Form data: {data}") if should_submit is not None and not should_submit: # False return data # Used to send the form response try: import requests except ImportError: if not command_line: raise print_("Form cannot be submitted (missing requests library)") sys.exit(3) if command_line and should_submit is None: if input("Submit the form data? (Y/N) ").strip().lower() != "y": print_("Form will not be submitted") return data # Send POST request to the URL print_("Submitting form...") response = requests.post(config.url, data=data) print_(f"Response received: {response.status_code} {response.reason}") return response
def run_commandline(interactive=True): """Run in command-line mode, either asking whether to back up each directory, or determining it based on last modification time. """ with config.open_config() as conf: conf.check() if interactive: for d in conf.directories: incl = input(f"Include {d.path}? [y/N] ") d.include = incl.lower().startswith("y") else: conf.update_includes() for msg in backup_core.perform_backup_iter(conf): print(msg)
Ltgroups made with this process will be usually different from that with incremental processing. """.strip().format(sys.argv[0]) import optparse op = optparse.OptionParser(usage) op.add_option("-c", "--config", action="store", dest="conf", type="string", default=config.DEFAULT_CONFIG_NAME, help="configuration file path") op.add_option("-r", action="store_true", dest="recur", default=False, help="search log file recursively") op.add_option("--debug", action="store_true", dest="debug", default=False, help="set logging level to DEBUG") options, args = op.parse_args() conf = config.open_config(options.conf) lv = logging.DEBUG if options.debug else logging.INFO config.set_common_logging(conf, _logger, ["lt_common", "lt_shiso", "lt_va", "lt_import"], lv = lv) if len(args) == 0: sys.exit(usage) mode = args.pop(0) if mode == "make": targets = _get_targets(conf, args, options.recur) timer = common.Timer("log_db make", output = _logger) timer.start() process_files(conf, targets, True) timer.stop() elif mode == "make-init": targets = _get_targets(conf, args, options.recur)
docorr = str(sys.argv[8]) #examples: #project = 'MegaRest.TMS' or 'despolarity' #atlas = 'aal' or 'power' #config_suff = 'power_DATE' # anything to make it clear which specific analysis running #subblocks = #of subblocks to split each block into (must be even divisor) #dosmooth = 'smooth' or 'nosmooth' or 'alreadysmooth' #dofilter = 'filter' or 'nofilter' or 'alreadyfilter' #doscrub = 'scrub' or 'noscrub' or 'both' #docorr = 'corr' or 'nocorr' # Load project-specific parameters from project_config file configdir = os.path.join('config_files','') configfile = '%s%s_%s_config' %(configdir,project,config_suff) configinfo=config.open_config(configfile) configout=config.config_to_dict(configinfo) # Print info included in config file about specific analysis print "\n***%s***\n\n" %(configout['notes']) ######## The below should all be defined in project_config file!!! See project_config_example for an example of variables to define ######## # Parameters #fwhm=6 #filt=[0.0009,0.08] #GSR=False # False is the default #maskedroi_prop=.25 # Minimum proportion of voxels in masked ROI as compared to unmasked ROI #mindist=20 # Minimum distance for connection in dosenbach_all atlas (load a mask that zeros out all connections shorter than mindist) #
def show_self_corr(conf): sc = CalculateSelfCorr(conf, False) if sc.loaded(): print sc.show_result() if __name__ == "__main__": import optparse usage = "usage: {0} [options] mode".format(sys.argv[0]) op = optparse.OptionParser(usage) op.add_option("-c", "--config", action="store", dest="conf", type="string", default=config.DEFAULT_CONFIG_NAME, help="configuration file path") op.add_option("-f", action="store_true", dest="fflag", default=False, help="format indata and recalculate") op.add_option("-t", "--threshold", action="store", dest="threshold", type="float", default=None, help="Threshold") (options, args) = op.parse_args() if len(args) == 0: sys.exit(usage) conf = config.open_config(options.conf) config.set_common_logging(conf, _logger) if args[0] == "self-corr": mkfilter_self_corr(conf, options.fflag, options.threshold) elif args[0] == "show-self-corr": show_self_corr(conf)
return None, None, None, None l_word, l_symbol = self.split_message(message) return dt, host, l_word, l_symbol def test_parse(conf): LP = LogParser(conf) ret = [] if conf.getboolean("general", "src_recur"): l_fp = common.recur_dir(conf.getlist("general", "src_path")) else: l_fp = common.rep_dir(conf.getlist("general", "src_path")) for fp in l_fp: with open(fp, 'r') as f: for line in f: ret.append(LP.process_line(line.rstrip("\n"))) return ret if __name__ == "__main__": if len(sys.argv) < 3: sys.exit("usage: {0} config targets".format(sys.argv[0])) conf = config.open_config(sys.argv[1]) LP = LogParser(conf) for fp in common.rep_dir(sys.argv[2:]): with open(fp) as f: for line in f: print LP.process_line(line.rstrip("\n"))
l_word, l_symbol = self.split_message(message) return dt, host, l_word, l_symbol def test_parse(conf): LP = LogParser(conf) ret = [] if conf.getboolean("general", "src_recur"): l_fp = common.recur_dir(conf.getlist("general", "src_path")) else: l_fp = common.rep_dir(conf.getlist("general", "src_path")) for fp in l_fp: with open(fp, 'r') as f: for line in f: ret.append(LP.process_line(line.rstrip("\n"))) return ret if __name__ == "__main__": if len(sys.argv) < 3: sys.exit("usage: {0} config targets".format(sys.argv[0])) conf = config.open_config(sys.argv[1]) LP = LogParser(conf) for fp in common.rep_dir(sys.argv[2:]): with open(fp) as f: for line in f: #print LP.process_line(line.rstrip("\n")) print " ".join(LP.process_line(line.rstrip("\n"))[2])
s2 = d_set2[k] d_diff[k] = (s1 - s2) return d_diff if __name__ == "__main__": usage = "usage: {0} [options] mode".format(sys.argv[0]) import optparse op = optparse.OptionParser(usage) op.add_option("-c", "--config", action="store", dest="conf", type="string", default=config.DEFAULT_CONFIG_NAME, help="configuration file path") (options, args) = op.parse_args() conf = config.open_config(options.conf) if len(args) == 0: sys.exit(usage) mode = args.pop(0) if mode == "diff-event": if len(args) == 0: sys.exit(usage) conf2 = config.open_config(args[0]) show_diff_event(conf, conf2) elif mode == "diff-filter": if len(args) < 3: sys.exit(("give me 3 config files: 1 for original events, " "2 for filtered ones to compare")) conf_org = config.open_config(args[0]) conf1 = config.open_config(args[1])
def test_config_create(self): """test creation of empty default config if none exists""" self.assertFalse(os.path.isfile(TEST_CONFIG)) with open_config(TEST_CONFIG) as conf: pass self.assertTrue(os.path.isfile(TEST_CONFIG))
def run_graphical(): """Run with the graphical GTK UI (default). """ with config.open_config() as conf: backup_gtk.BackupFrame(conf) backup_gtk.Gtk.main()
#Restore previous color values for i in range(2): config.Bridge(woohue_config.ip).set_light(woohue_config.goal_lights[i], 'xy', existingState[i]) class configuration: def __init__(self, config_obj): self.config = config_obj self.ip = self.config['Bridge']['ip'] self.goal_lights = self.config['Goal_Lights']['Lights'] self.teams = self.config['Teams']['Team'] try: woohue_config = configuration(config.open_config()) except Exception as e: print(e) else: activate_goal_light(woohue_config, woohue_config.teams[0]) class game: def __init__(self, team): self.team = team self.initial_score = 0 self.get_game() self.watch_game() @run_once def start_game(self):
usage = """ usage: {0} [options] args... """.format(sys.argv[0]).strip() import optparse op = optparse.OptionParser(usage) op.add_option("-c", "--config", action="store", dest="conf", type="string", default=config.DEFAULT_CONFIG_NAME, help="configuration file path") (options, args) = op.parse_args() conf = config.open_config(options.conf) if len(args) == 0: sys.exit(usage) mode = args.pop(0) if mode == "diff-event-type": diff_event_type(conf) elif mode == "related-filtered": related_filtered_all(conf) elif mode == "list-all-gid": list_all_gid(conf) elif mode == "search-gid": if len(args) == 0: sys.exit("give me gid") gid = args[0] search_gid(conf, gid)