Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class CSyntaxType():

class CPythonJSONDecoder(json.JSONDecoder):
"""
**Class: PythonJSONDecoder**

Add python data types and syntax to json. ``True``, ``False`` and ``None`` will be a accepted as json syntax elements.

**Args:**
Expand Down Expand Up @@ -127,8 +125,6 @@ def custom_scan_once(self, string : str, idx : int) -> any:

class CJsonPreprocessor():
"""
**Class: CJsonPreprocessor**

CJsonPreprocessor extends the syntax of json.

Features are
Expand Down Expand Up @@ -165,8 +161,6 @@ class CJsonPreprocessor():

def __init__(self, syntax: CSyntaxType = CSyntaxType.json , currentCfg : dict = {}) -> None:
"""
**Method: __init__**

Constructor

**Args:**
Expand All @@ -191,8 +185,6 @@ def __init__(self, syntax: CSyntaxType = CSyntaxType.json , currentCfg : dict =

def __sNormalizePath(self, sPath : str) -> str:
"""
**Method: __sNormalizePath**

Python struggles with

- UNC paths
Expand Down Expand Up @@ -255,8 +247,6 @@ def __mkslash(sPath : str) -> str:

def __processImportFiles(self, input_data : dict) -> dict:
'''
**Method: __processImportFiles**

This is a custom decorder of ``json.loads object_pairs_hook`` function.

This method helps to import json files which are provided in ``"[import]"`` keyword into the current json file.
Expand Down Expand Up @@ -297,8 +287,6 @@ def __processImportFiles(self, input_data : dict) -> dict:

def __load_and_removeComments(self, jsonFile : str) -> str:
"""
**Method: __load_and_removeComments**

Loads a given json file and filters all C/C++ style comments.

**Args:**
Expand All @@ -324,7 +312,7 @@ def replacer(match):
else:
return s

file=open(jsonFile,mode='r')
file=open(jsonFile, mode='r', encoding='utf-8')
sContent=file.read()
file.close()

Expand All @@ -336,8 +324,6 @@ def replacer(match):

def __nestedParamHandler(self, sInputStr : str) -> str:
'''
**Method: __nestedParamHandler**

This method handles nested variables in parameter names or values. Variable syntax is ${Variable_Name}.

**Args:**
Expand Down Expand Up @@ -385,7 +371,7 @@ def __nestedParamHandler(self, sInputStr : str) -> str:
exec(sExec, globals(), ldict)
tmpValue = ldict['value']
except:
raise Exception("fThe variable '{fullVariable}' is not available!")
raise Exception(f"The variable '{fullVariable}' is not available!")
pattern = re.sub('\[', '\\[', fullVariable)
pattern = re.sub('\]', '\\]', pattern)
sInputStr = re.sub('\\' + pattern, '\'' + tmpValue + '\'', sInputStr) if isinstance(tmpValue, str) else \
Expand All @@ -411,8 +397,6 @@ def __nestedParamHandler(self, sInputStr : str) -> str:

def __updateAndReplaceNestedParam(self, oJson : dict, recursive : bool = False):
'''
**Method: __updateAndReplaceNestedParam**

This method replaces all nested parameters in key and value of a json object .

**Args:**
Expand All @@ -432,7 +416,7 @@ def __updateAndReplaceNestedParam(self, oJson : dict, recursive : bool = False):
def __tmpJsonUpdated(k, v, tmpJson, bNested):
if bNested:
if '[' in k:
sExec = k + " = \'" + v + "\'" if isinstance(v, str) else k + " = " + str(v)
sExec = k + " = \"" + v + "\"" if isinstance(v, str) else k + " = " + str(v)
try:
exec(sExec, globals())
except:
Expand Down Expand Up @@ -531,7 +515,6 @@ def __tmpJsonUpdated(k, v, tmpJson, bNested):

def __checkAndUpdateKeyValue(self, sInputStr: str) -> str:
'''
**Method: jsonLoad**
This function checks and makes up all nested parameters in json configuration files.

**Args:**
Expand Down Expand Up @@ -562,8 +545,6 @@ def __checkAndUpdateKeyValue(self, sInputStr: str) -> str:

def jsonLoad(self, jFile : str, masterFile : bool = True):
'''
**Method: jsonLoad**

This function is the entry point of JsonPreprocessor.

It loads the json file, preprocesses it and returns the preprocessed result as data structure.
Expand Down
Binary file modified JsonPreprocessor/JsonPreprocessor.pdf
Binary file not shown.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
> Licensed under the Apache License, Version 2.0 (the \"License\"); you
> may not use this file except in compliance with the License. You may
> obtain a copy of the License at
>
> <http://www.apache.org/licenses/LICENSE-2.0>
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an \"AS IS\" BASIS,
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied. See the License for the specific language governing
> permissions and limitations under the License.

# Json Preprocessor\'s Package Description

## Getting Started
Expand All @@ -26,19 +14,33 @@ as result a dictionary object of the deserialized data.

## How to install

Firstly, clone **python-jsonpreprocessor** repository to your machine.
**JsonPreprocessor** can be installed in two different ways.

1. Installation via PyPi (recommended for users)

```
pip install JsonPreprocessor
```

[JsonPreprocessor in
PyPi](https://pypi.org/project/JsonPreprocessor/)

2. Installation via GitHub (recommended for developers)

Clone the **JsonPreprocessor** repository to your machine.

```
git clone https://github.com/test-fullautomation/python-jsonpreprocessor.git
```

Then go to python-jsonpreprocessor, using the 2 common commands below to
build or install this package:
[JsonPreprocessor in
GitHub](https://github.com/test-fullautomation/python-jsonpreprocessor)

```
setup.py build will build the package underneath 'build/'
setup.py install will install the package
```
Use the following command to install **JsonPreprocessor**:

After the build processes is completed, the package is located in
\'build/\', and the generated package documentation is located in
\'doc/\_build/\'.
```
setup.py install
```

## Package Documentation

Expand Down
33 changes: 23 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.. Copyright 2020-2022 Robert Bosch GmbH

Licensed under the Apache License, Version 2.0 (the "License");
.. Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
.. http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
.. Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
Expand All @@ -31,18 +31,31 @@ a dictionary object of the deserialized data.
How to install
--------------

Firstly, clone **python-jsonpreprocessor** repository to your machine.
**JsonPreprocessor** can be installed in two different ways.

Then go to python-jsonpreprocessor, using the 2 common commands below to build or install this package:
1. Installation via PyPi (recommended for users)

.. code-block::
.. code::

setup.py build will build the package underneath 'build/'
setup.py install will install the package
pip install JsonPreprocessor

After the build processes is completed, the package is located in 'build/', and the generated
package documentation is located in 'doc/_build/'.
`JsonPreprocessor in PyPi <https://pypi.org/project/JsonPreprocessor/>`_

2. Installation via GitHub (recommended for developers)

Clone the **JsonPreprocessor** repository to your machine.

.. code::

git clone https://github.com/test-fullautomation/python-jsonpreprocessor.git

`JsonPreprocessor in GitHub <https://github.com/test-fullautomation/python-jsonpreprocessor>`_

Use the following command to install **JsonPreprocessor**:

.. code::

setup.py install

Package Documentation
---------------------
Expand Down
Loading