def dump_report(self, bqm, target, report, metric, tags=[]): bqm_id = self.id_bqm(bqm) target_id = self.id_target(target) reports_path = [self.reports_path,bqm_id,target_id]+tags report_filename = metric report_path = self.get_path(reports_path, report_filename) with open(report_path,'w+') as fp: _dump(report,fp,cls=EmberaEncoder) return report_filename
def generate_config(config_fp, **kwargs): """ Creates a config file. :param config_fp: Filepath to the config :param \*\*kwargs: Source for the config data """ _local = {} for k, v in kwargs.items(): _local[k] = v with open(config_fp, 'w') as c: _dump(_local, c, indent=2)
def save_jsonfile(filepath, _dict, **kwargs): """ :param filepath: :param _dict: :param kwargs: :return: """ """ Saves a json file. :param config_fp: Filepath to the config :param \*\*kwargs: Source for the config data """ with open(filepath, 'w') as file: _dump(_dict, file, **kwargs)
def set_mount( storage, config_name=None, storage_parameters=None, unsecure=None, extra_root=None ): """ Set a mount configuration. Most arguments are identical to "airfs.mount". .. versionadded:: 1.5.0 Args: storage (str): Storage name. config_name (str): If specified, save the configuration as a specific storage configuration. This allow to save multiple configurations for a same "storage". storage_parameters (dict): Storage configuration parameters. Generally, client configuration and credentials. unsecure (bool): If True, disables TLS/SSL to improves transfer performance. But makes connection unsecure. Default to False. extra_root (str): Extra root that can be used in replacement of root in path. This can be used to provides support for shorter URLS. Example: with root "https://www.my_storage.com/user" and extra_root "mystorage://" it is possible to access object using "mystorage://container/object" instead of "https://www.my_storage.com/user/container/object". """ if config_name: storage = f"{storage}.{config_name}" config = _read_config() or dict() config[storage] = { key: value for key, value in dict( unsecure=unsecure, extra_root=extra_root, storage_parameters=storage_parameters, ).items() if value } with open(_CONFIG_FILE, "wt") as config_file: _dump(config, config_file) chmod(_CONFIG_FILE, 0o600)
def dumpf(data, file, **kwargs): with open(file, "w") as fs: _dump(data, fs, **kwargs)
def run(): """ Function to be executed whenever sech3r is supposed to be executed. Does command-line argument parsing, etc.. """ from docopt import docopt args = docopt(__doc__, version='SéCh3r v{}'.format(__version__)) color = True verbose = search4cves = noRedirects = insecure = quiet = output_filename = input_filename = False if args['--noColor']: color = False if args['--verbose']: verbose = True if args['--searchForVuln']: search4cves = True if args['--noRedirects']: noRedirects = True if args['--insecure']: insecure = True if args['--quiet']: quiet = True if args['--input']: input_filename = args['--input'] if args['--output']: output_filename = args['--output'] if not quiet: banner(__version__, color) if verbose: if not quiet: print(info('Verbosity -> Enabled', color)) if color: print(info('Colorized Output -> Yeah')) else: print(info('Much fanciness -> Nope', False)) if search4cves: print(info('Google for CVEs -> Yup!', color)) else: print(info('Interested in CVEs -> Nah', color)) if noRedirects: print(info('Follow Redirects -> No', color)) else: print(info('Do Follow redirects -> Sure', color)) if insecure: print(info('Bypass TLS/SSL verification -> Yea', color)) else: print(info('Ignore TLS/SSL warnings -> Noo!', color)) else: banner(__version__, color) print( bad('Wait a minute! -> How can I be both quiet, and verbose?', color)) coolExit(1, color) if args['<urls>']: output = main(args['<urls>'], verbose, search4cves, noRedirects, insecure, color, quiet) elif input_filename: if not quiet: print(info(f'Input file -> {input_filename}')) urls = read_url_from_file(input_filename) if urls: output = main(urls, verbose, search4cves, noRedirects, insecure, color, quiet) else: print(bad(f'Wait! -> File not found or the file is empty')) coolExit(1, color) else: output = main([], verbose, search4cves, noRedirects, insecure, color, quiet) if output_filename: if not quiet: print(info(f'Output File -> {output_filename}')) with open(output_filename, 'w') as output_file: from json import dump as _dump _dump(output, output_file, indent=2) if not quiet: coolExit(0, color) exit(0)
def to_file(self, path, indent=2, sort_keys=True): with _LazyPath(str(path)).write() as tmp_file: _dump(self, tmp_file, indent=indent, sort_keys=sort_keys)
def saveConfig(): """Write config and PSE to json-file""" with open(_expanduser('~/.vipster.json'), 'w') as f: _dump(_ODict([('PSE', pse), ('General', config), ('Parameters', _paramdict)]), f, indent=2)
def update_aliases(self): with open(self.aliases_path,'w+') as fp: _dump(self.aliases,fp)
def make_cached_file(fn: str, data: dict, cd=cached_dir): _path = _join(cd, fn) file = f"{_path}.data.json" mkdir(cd) with open(file, "w") as f: _dump(data, f)