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
15 changes: 10 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ Json Preprocessor's Package Description
Getting Started
---------------

The JsonPreprocessor is a python3 package which allows programmers to handle
additional features in json files such as comments, imports, overrides, etc.
The json files containing comments, imports,... will be handled by the JsonPreprocessor
package which returs as result an dictionary object of the deserialized data.
The JsonPreprocessor is a Python3 package which allows programmers to handle
additional features in json files such as

* add comments
* import other json files
* overwrite already existing parameters with new values

These json files will be handled by the JsonPreprocessor which returns as result
a dictionary object of the deserialized data.

How to install
--------------
Expand All @@ -42,7 +47,7 @@ package documentation is located in 'doc/_build/'.
Package Documentation
---------------------

A detailed documentation of the Json Preprocessor's Package can be found here: `Json-Preprocessor.pdf <https://github.com/test-fullautomation/python-jsonpreprocessor/blob/develop/doc/_build/latex/Json-Preprocessor.pdf>`_
A detailed documentation of the Json Preprocessor's package can be found here: `Json-Preprocessor.pdf <https://github.com/test-fullautomation/python-jsonpreprocessor/blob/develop/doc/_build/latex/Json-Preprocessor.pdf>`_

Feedback
--------
Expand Down
88 changes: 28 additions & 60 deletions config/CConfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +16,7 @@
#
# CConfig.py
#
# CM-CI1/ECA3-Queckenstedt
# XC-CT/ECA3-Queckenstedt
#
# Purpose:
# - Compute and store all repository specific information, like the repository name,
Expand All @@ -31,13 +29,16 @@
# (when documentation project files like make.bat are generated by Sphinx; for better understanding
# no new names here).
#
# - Output in PDF format requires LaTeX compiler and self.__bGenPDFSupported set to True (True is default)
# - Output in PDF format requires LaTeX compiler and depends on %ROBOTLATEXPATH%/miktex/bin/x64/pdflatex.exe
#
# - Don't be confused: We have 'doc/_build' containing the documentation builder output
# and we have 'build' containing the build of the setup tools. These are different things.
#
# --------------------------------------------------------------------------------------------------------------
#
# 18.02.2022 / XC-CT/ECA3-Queckenstedt
# Usage of %RobotPythonPath% exchanged by sys.executable
#
# 11.10.2021 / XC-CI1/ECA3-Queckenstedt
# Fixed path within site-packages (Linux)
#
Expand Down Expand Up @@ -81,8 +82,6 @@ def __init__(self, sReferencePath="."):
self.__sReferencePath = os.path.normpath(os.path.abspath(sReferencePath))
self.__dictConfig['sReferencePath'] = self.__sReferencePath # only to have the possibility to print out all values only with help of 'self.__dictConfig'

self.__bGenPDFSupported = False

# 1. basic setup stuff
self.__dictConfig['sPackageName'] = "JsonPreprocessor"
self.__dictConfig['sVersion'] = "0.0.10"
Expand Down Expand Up @@ -117,84 +116,53 @@ def __InitConfig(self):

sOSName = os.name
sPlatformSystem = platform.system()
sPythonPath = os.path.dirname(sys.executable)
sPython = sys.executable
sPythonVersion = sys.version

SPHINXBUILD = None
sPython = None
sLaTeXInterpreter = None
sInstalledPackageFolder = None
sInstalledPackageDocFolder = None

try:
self.__dictConfig['sPythonVersion'] = sys.version
self.__dictConfig['sPandoc'] = pypandoc.get_pandoc_path()
self.__dictConfig['sPandoc'] = pypandoc.get_pandoc_path()
except Exception as ex:
bSuccess = False
sResult = str(ex)
return bSuccess, sResult

if sPlatformSystem == "Windows":
# -- environment check
sRobotPythonPath_EnvVar = "%RobotPythonPath%"
sRobotPythonPath = os.path.expandvars(sRobotPythonPath_EnvVar)
if sRobotPythonPath_EnvVar == sRobotPythonPath:
# environment variable not resolved => not existing
bSuccess = False
sResult = f"""Missing Windows environment variable %RobotPythonPath%!
This application requires a Windows environment variable %RobotPythonPath%, pointing to a Python installation (version required: {self.__dictConfig['sPythonRequires']}) that shall be updated.
Please create and try again"""
return bSuccess, sResult

SPHINXBUILD = os.path.normpath(os.path.expandvars("%RobotPythonPath%/Scripts/sphinx-build.exe"))
sPython = os.path.normpath(os.path.expandvars("%RobotPythonPath%/python.exe"))
if self.__bGenPDFSupported is True:
sLaTeXInterpreter = os.path.normpath(os.path.expandvars("%ROBOTLATEXPATH%/miktex/bin/x64/pdflatex.exe"))
sInstalledPackageFolder = os.path.normpath(os.path.expandvars("%RobotPythonPath%/Lib/site-packages/" + self.__dictConfig['sPackageName']))
sInstalledPackageDocFolder = os.path.normpath(os.path.expandvars("%RobotPythonPath%/Lib/site-packages/" + self.__dictConfig['sPackageName'] + "_doc"))
SPHINXBUILD = f"{sPythonPath}/Scripts/sphinx-build.exe"
sInstalledPackageFolder = f"{sPythonPath}/Lib/site-packages/" + self.__dictConfig['sPackageName']
sInstalledPackageDocFolder = f"{sPythonPath}/Lib/site-packages/" + self.__dictConfig['sPackageName'] + "_doc"
sLaTeXInterpreter = os.path.normpath(os.path.expandvars("%ROBOTLATEXPATH%/miktex/bin/x64/pdflatex.exe"))

elif sPlatformSystem == "Linux":
# -- environment check
sRobotPythonPath_EnvVar = "${RobotPythonPath}"
sRobotPythonPath = os.path.expandvars(sRobotPythonPath_EnvVar)
if sRobotPythonPath_EnvVar == sRobotPythonPath:
# environment variable not resolved => not existing
bSuccess = False
sResult = f"""Missing Linux environment variable ${RobotPythonPath}!
This application requires a Linux environment variable ${RobotPythonPath}, pointing to a Python installation (version required: {self.__dictConfig['sPythonRequires']}) that shall be updated.
Please create and try again"""
return bSuccess, sResult
SPHINXBUILD = os.path.normpath(os.path.expandvars("${RobotPythonPath}/sphinx-build"))
sPython = os.path.normpath(os.path.expandvars("${RobotPythonPath}/python3.9"))
# if self.__bGenPDFSupported is True: # not yet!!
# sLaTeXInterpreter = os.path.normpath(os.path.expandvars("${ROBOTLATEXPATH}/miktex/bin/x64/pdflatex"))
sInstalledPackageFolder = os.path.normpath(os.path.expandvars("${RobotPythonPath}/../lib/python3.9/site-packages/" + self.__dictConfig['sPackageName']))
sInstalledPackageDocFolder = os.path.normpath(os.path.expandvars("${RobotPythonPath}/../lib/python3.9/site-packages/" + self.__dictConfig['sPackageName'] + "_doc"))
SPHINXBUILD = f"{sPythonPath}/sphinx-build"
sInstalledPackageFolder = f"{sPythonPath}/../lib/python3.9/site-packages/" + self.__dictConfig['sPackageName']
sInstalledPackageDocFolder = f"{sPythonPath}/../lib/python3.9/site-packages/" + self.__dictConfig['sPackageName'] + "_doc"
sLaTeXInterpreter = os.path.normpath(os.path.expandvars("${ROBOTLATEXPATH}/miktex/bin/x64/pdflatex"))

else:
bSuccess = False
sResult = "Operating system " + str(sPlatformSystem) + " (" + str(sOSName) + ") not supported"
sResult = f"Operating system {sPlatformSystem} ({sOSName}) not supported"
return bSuccess, sResult

self.__dictConfig['SPHINXBUILD'] = SPHINXBUILD
self.__dictConfig['sPython'] = sPython
self.__dictConfig['sLaTeXInterpreter'] = sLaTeXInterpreter
self.__dictConfig['sInstalledPackageFolder'] = sInstalledPackageFolder
self.__dictConfig['sInstalledPackageDocFolder'] = sInstalledPackageDocFolder
if os.path.isfile(sLaTeXInterpreter) is False:
sLaTeXInterpreter = None # not an error; PDF generation is an option

if os.path.isfile(SPHINXBUILD) is False:
bSuccess = False
sResult = "Missing Sphinx '" + str(SPHINXBUILD) + "'"
sResult = f"Missing Sphinx '{SPHINXBUILD}'"
return bSuccess, sResult

if os.path.isfile(sPython) is False:
bSuccess = False
sResult = "Missing Python '" + str(sPython) + "'"
return bSuccess, sResult
self.__dictConfig['SPHINXBUILD'] = SPHINXBUILD
self.__dictConfig['sPython'] = sPython
self.__dictConfig['sLaTeXInterpreter'] = sLaTeXInterpreter
self.__dictConfig['sInstalledPackageFolder'] = sInstalledPackageFolder
self.__dictConfig['sInstalledPackageDocFolder'] = sInstalledPackageDocFolder

if self.__bGenPDFSupported is True:
if os.path.isfile(sLaTeXInterpreter) is False:
bSuccess = False
sResult = "Missing LaTeX '" + str(sLaTeXInterpreter) + "'"
return bSuccess, sResult

# ---- paths relative to repository root folder (where the srcipts are located that use this module)

Expand Down Expand Up @@ -233,7 +201,7 @@ def __InitConfig(self):
self.__dictConfig['sEggInfoFolder'] = os.path.normpath(self.__sReferencePath + "/" + self.__dictConfig['sPackageName'] + ".egg-info")

print()
print("Running under " + str(sPlatformSystem) + " (" + str(sOSName) + ")")
print(f"Running under {sPlatformSystem} ({sOSName})")
self.PrintConfig()

bSuccess = True
Expand All @@ -256,7 +224,7 @@ def PrintConfig(self):
def Get(self, sName=None):
if ( (sName is None) or (sName not in self.__dictConfig) ):
print()
printerror("Error: Configuration parameter '" + str(sName) + "' not existing!")
printerror(f"Error: Configuration parameter '{sName}' not existing!")
# from here it's standard output:
print("Use instead one of:")
self.PrintConfig()
Expand Down
24 changes: 11 additions & 13 deletions config/CExtendedSetup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -73,8 +71,8 @@ def gen_doc(self):
sPython = self.__oRepositoryConfig.Get('sPython')
sDocumentationBuilder = self.__oRepositoryConfig.Get('sDocumentationBuilder')
listCmdLineParts = []
listCmdLineParts.append("\"" + str(sPython) + "\"")
listCmdLineParts.append("\"" + str(sDocumentationBuilder) + "\"")
listCmdLineParts.append(f"\"{sPython}\"")
listCmdLineParts.append(f"\"{sDocumentationBuilder}\"")
sCmdLine = " ".join(listCmdLineParts)
del listCmdLineParts
listCmdLineParts = shlex.split(sCmdLine)
Expand Down Expand Up @@ -104,7 +102,7 @@ def delete_previous_build(self):
sSetupDistFolder = self.__oRepositoryConfig.Get('sSetupDistFolder')
sEggInfoFolder = self.__oRepositoryConfig.Get('sEggInfoFolder')
if os.path.isdir(sSetupBuildFolder) is True:
print("* Deleting '" + sSetupBuildFolder + "'")
print(f"* Deleting '{sSetupBuildFolder}'")
try:
shutil.rmtree(sSetupBuildFolder)
except Exception as ex:
Expand All @@ -113,7 +111,7 @@ def delete_previous_build(self):
print()
return ERROR
if os.path.isdir(sSetupDistFolder) is True:
print("* Deleting '" + sSetupDistFolder + "'")
print(f"* Deleting '{sSetupDistFolder}'")
try:
shutil.rmtree(sSetupDistFolder)
except Exception as ex:
Expand All @@ -122,7 +120,7 @@ def delete_previous_build(self):
print()
return ERROR
if os.path.isdir(sEggInfoFolder) is True:
print("* Deleting '" + sEggInfoFolder + "'")
print(f"* Deleting '{sEggInfoFolder}'")
try:
shutil.rmtree(sEggInfoFolder)
except Exception as ex:
Expand All @@ -140,7 +138,7 @@ def delete_previous_installation(self):
"""
sInstalledPackageFolder = self.__oRepositoryConfig.Get('sInstalledPackageFolder')
if os.path.isdir(sInstalledPackageFolder) is True:
print("* Deleting '" + sInstalledPackageFolder + "'")
print(f"* Deleting '{sInstalledPackageFolder}'")
try:
shutil.rmtree(sInstalledPackageFolder)
except Exception as ex:
Expand All @@ -150,7 +148,7 @@ def delete_previous_installation(self):
return ERROR
sInstalledPackageDocFolder = self.__oRepositoryConfig.Get('sInstalledPackageDocFolder')
if os.path.isdir(sInstalledPackageDocFolder) is True:
print("* Deleting '" + sInstalledPackageDocFolder + "'")
print(f"* Deleting '{sInstalledPackageDocFolder}'")
try:
shutil.rmtree(sInstalledPackageDocFolder)
except Exception as ex:
Expand All @@ -172,18 +170,18 @@ def add_htmldoc_to_installation(self):
sInstalledPackageDocFolder = self.__oRepositoryConfig.Get('sInstalledPackageDocFolder')
if os.path.isdir(sHTMLOutputFolder) is False:
print()
printerror("Error: Missing html output folder '" + sHTMLOutputFolder + "'")
printerror(f"Error: Missing html output folder '{sHTMLOutputFolder}'")
print()
return ERROR
shutil.copytree(sHTMLOutputFolder, sInstalledPackageDocFolder)
if os.path.isdir(sInstalledPackageDocFolder) is False:
print()
printerror("Error: html documentation not copied to package installation folder '" + sInstalledPackageDocFolder + "'")
printerror(f"Error: html documentation not copied to package installation folder '{sInstalledPackageDocFolder}'")
print()
return ERROR
print(COLBY + "Folder '" + sHTMLOutputFolder + "'")
print(COLBY + f"Folder '{sHTMLOutputFolder}'")
print(COLBY + "copied to")
print(COLBY + "'" + sInstalledPackageDocFolder + "'")
print(COLBY + f"'{sInstalledPackageDocFolder}'")
print()
return SUCCESS
# eof def add_htmldoc_to_installation():
Expand Down
Binary file modified doc/_build/latex/Json-Preprocessor.pdf
Binary file not shown.
40 changes: 20 additions & 20 deletions doc/additional_doc/feature_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ Introduction:

.. image:: /images/python3-jsonpreprocessor.png

The JsonPreprocessor is the python3 package which allows programmer to handle some
additional features in json file such as comment, import, override, etc for
configuring purpose. The json file containing comment, import,... will be handled
by JsonPreprocessor package then returned the final dictionary object for python
program.
The JsonPreprocessor is a Python3 package which allows programmers to handle
additional features in json files such as

* add comments
* import other json files
* overwrite already existing parameters with new values

These json files will be handled by the JsonPreprocessor package which returns as result
a dictionary object of the deserialized data.

New features
~~~~~~~~~~~~
Expand All @@ -42,17 +46,14 @@ Features in details

Adding comments to Json file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The JsonPreprocessor allows adding comments into json file, a comment could be
added follow **"//"**.

This is required becuase some big projects require a large json configuration file
which contains a huge number of configuration parameters for the different features.
Therefore, having the need of adding comments into json file to clarify the different
configuration parameters.
Every line starting with **"//"**, is commented out. Therefore a comment is valid for singles lines only.

Comment out a block of several lines with only one start and one end comment string, is currently not supported.

**Note:** This package is not allow commented a block of json code, each comment
must be added with **"//"**.
Adding comments to json files is useful in case of more and more content is added, e.g. because of a json file
has to hold a huge number of configuration parameters for different features. Comments can be used here
to clarify the meaning of these parameters or the differences between them.

**Example:**

Expand Down Expand Up @@ -102,13 +103,12 @@ must be added with **"//"**.
Import the contents from other json files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This import feature allows user merges the content of other json files into the
json file, it also allows the nested importing means we can use import feature in
the imported files.
This import feature enables developers to take over the content of other json files into the
current json file. A json file that is imported into another json file, can contain imports also
(allows nested imports).

The import feature helps user distinguish the configuration parameters of each
functions, purposes, variants, and so forth into the separate json files. Therefore,
we can easy to understand and manage the configuration parameters of big project.
A possible usecase for nested imports is to handle similar configuration parameters of different variants of a feature
or a component within a bunch of several smaller files, instead of putting all parameter into only one large json file.

**Example:**

Expand Down
Loading