コード例 #1
0
ファイル: config.py プロジェクト: rlaphoenix/pynfogen
def config(ctx: click.Context, key: Optional[str], value: Optional[str],
           unset: bool, list_: bool) -> None:
    """Manage configuration."""
    if not key and not value and not list_:
        return click.echo(config.get_help(ctx))

    log = logging.getLogger("config")

    if list_:
        print(pytomlpp.dumps(data).rstrip())
        return

    tree = key.split(".")
    temp = data
    for t in tree[:-1]:
        if temp.get(t) is None:
            temp[t] = {}
        temp = temp[t]

    if unset:
        if tree[-1] in temp:
            del temp[tree[-1]]
        log.info(f"Unset {key}")
    else:
        if value is None:
            if tree[-1] not in temp:
                raise click.ClickException(
                    f"Key {key} does not exist in the config.")
            print(f"{key}: {temp[tree[-1]]}")
        else:
            temp[tree[-1]] = value
            log.info(f"Set {key} to {repr(value)}")
            Files.config.parent.mkdir(parents=True, exist_ok=True)
            pytomlpp.dump(data, Files.config)
コード例 #2
0
    def _save(self, out_dict: Dict, info_dict: Optional[Dict],
              path: str) -> str:
        """Write function for TOML type

        Args:
            out_dict: payload to write
            info_dict: info payload to write
            path: path to write out

        Returns:
        """
        # First write the commented info
        self.write_extra_info(path=path, info_dict=info_dict)
        with open(path, "a") as toml_fid:
            pytomlpp.dump(out_dict, toml_fid)
        return path
コード例 #3
0
ファイル: bar2vtk.py プロジェクト: PHASTA/vtkpytools
def tomlReceipt(args: dict, tomlMetadata: dict):
    """Creates a receipt of the created file

    Parameters
    ----------
    args : dict
        Arguments passed to bar2vtk_function
    tomlMetadata : dict
        Extra metadata given by bar2vtk_function
    """

    convertArray = [(PurePath, lambda x: x.as_posix()),
                    (type(None), lambda x: '')]

    _convertArray2TomlTypes(args, convertArray)

    vtmPath = tomlMetadata['vtmPath']
    _convertArray2TomlTypes(tomlMetadata, convertArray)

    tomldict = {'arguments': args}

    meta = {}
    meta['bar2vtk_vars'] = tomlMetadata
    meta['created'] = datetime.datetime.now()
    meta['vtkpytools_version'] = __version__
    meta['pyvista_version'] = pv.__version__
    meta['vtk_version'] = vtk.VTK_VERSION
    meta['python_version'] = platform.python_version()
    meta['uname'] = platform.uname()._asdict()

    meta['directory'] = os.getcwd()

    tomldict['metadata'] = meta

    vtmDir = Path(os.path.splitext(vtmPath)[0])
    if not vtmDir.is_dir():
        warnings.warn(
            'Directory {} does not exist. '
            'Cannot create toml receipt.'.format(vtmDir.as_posix()),
            RuntimeWarning)
    else:
        tomlPath = vtmDir / Path('receipt.toml')
        with tomlPath.open(mode='w') as file:
            pytomlpp.dump(tomldict, file)
コード例 #4
0
ファイル: bar2vtk.py プロジェクト: PHASTA/vtkpytools
def blankToml(tomlfilepath: Path, returndict=False):
    """Write blank toml file to tomlfilepath"""
    tomldict = {
        'arguments': {
            'blankvtmfile': 'path/to/blankVTMFile (required)',
            'barfiledir': 'path/to/directory/of/*barfiles (required)',
            'timestep': 'timestep (range) of data (required)',
            'ts0': -1,
            'new_file_prefix': '',
            'outpath': 'path/to/different/output/directory',
            'velonly': False,
            'debug': False,
            'asciidata': False,
            'velbar': [],
            'stsbar': [],
            'consrvstress': False,
        }
    }

    with tomlfilepath.open('w') as file:
        pytomlpp.dump(tomldict, file)
    if returndict: return tomldict
コード例 #5
0
 def dump(self, obj, fp):  # pragma: no cover
     ready_obj = TomlSerializer.restructure_primitives(refactor_object(obj))
     with open(fp, 'w') as outfile:
         toml.dump(ready_obj, outfile)
コード例 #6
0
ファイル: parser.py プロジェクト: Dezorgon/ISP_lab2
 def dump(self, obj, fp):
     pytomlpp.dump(serialize(obj), fp)
コード例 #7
0
ファイル: util.py プロジェクト: django-daiquiri/dq-dev
def write_toml(data, filename):
    with open(filename, 'w') as toml_file:
        toml.dump(data, toml_file)
コード例 #8
0
def test_decode_encode_binary(toml_file, tmp_path):
    data = pytomlpp.load(toml_file)
    pytomlpp.dump(data, str(tmp_path / "tmp.toml"), mode="wb")
    assert pytomlpp.load(str(tmp_path / "tmp.toml"), mode="rb") == data
コード例 #9
0
 def dump(obj, file="testtoml.toml"):
     packed = convert(obj)
     with open(file, 'w+') as fw:
         pytomlpp.dump(packed, fw)