Coverage for /home/pradyumna/Languages/python/packages/pyprojstencil/pyprojstencil/common.py: 0%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python3
2# -*- coding:utf-8; mode:python; -*-
3#
4# Copyright 2021 Pradyumna Paranjape
5# This file is part of pyprojstencil.
6#
7# pyprojstencil is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Lesser General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# pyprojstencil is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with pyprojstencil. If not, see <https://www.gnu.org/licenses/>.
19#
20"""
21commonly used functions
22"""
24from pathlib import Path
26from pyprojstencil.configure import PyConfig
29def edit_modify(text: str, config: PyConfig) -> str:
30 """
31 Insert modifications in the text based on configuration
33 Args:
34 text: text to modify
35 config: configuration to use
37 Returns:
38 modified text
39 """
40 for key, value in config.__dict__.items():
41 if value is not None:
42 if isinstance(value, Path):
43 text = text.replace(f'<{key.upper()}>', value.name)
44 else:
45 text = text.replace(f'<{key.upper()}>', value)
46 return text