Compare commits
10 Commits
378ebcebf6
...
main
Author | SHA1 | Date | |
---|---|---|---|
bfb82a7f9c | |||
d304e67089 | |||
3ee87bbb12 | |||
206398ab8d | |||
1f12b78ef3 | |||
f28e231185 | |||
875e6a4831 | |||
1ea2450261 | |||
f67a8ed01f | |||
3b747f56ba |
19
.idea/inspectionProfiles/Project_Default.xml
generated
19
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,19 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
|
||||||
<option name="ignoredErrors">
|
|
||||||
<list>
|
|
||||||
<option value="E501" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PyShadowingBuiltinsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
|
||||||
<option name="ignoredNames">
|
|
||||||
<list>
|
|
||||||
<option value="format" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</inspection_tool>
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
7
.idea/misc.xml
generated
7
.idea/misc.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Black">
|
|
||||||
<option name="sdkName" value="Python 3.6 (pyuserconfig)" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (userconfig)" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
8
.idea/modules.xml
generated
8
.idea/modules.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/pyuserconfig.iml" filepath="$PROJECT_DIR$/.idea/pyuserconfig.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
13
.idea/pyuserconfig.iml
generated
13
.idea/pyuserconfig.iml
generated
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
<component name="TestRunnerService">
|
|
||||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@@ -1,40 +0,0 @@
|
|||||||
Index: .idea/pyuserconfig.iml
|
|
||||||
IDEA additional info:
|
|
||||||
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
|
|
||||||
<+><?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<module type=\"PYTHON_MODULE\" version=\"4\">\n <component name=\"NewModuleRootManager\">\n <content url=\"file://$MODULE_DIR$\" />\n <orderEntry type=\"jdk\" jdkName=\"Python 3.7 (pyuserconfig)\" jdkType=\"Python SDK\" />\n <orderEntry type=\"sourceFolder\" forTests=\"false\" />\n </component>\n <component name=\"TestRunnerService\">\n <option name=\"PROJECT_TEST_RUNNER\" value=\"Unittests\" />\n </component>\n</module>
|
|
||||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
|
||||||
<+>UTF-8
|
|
||||||
===================================================================
|
|
||||||
diff --git a/.idea/pyuserconfig.iml b/.idea/pyuserconfig.iml
|
|
||||||
--- a/.idea/pyuserconfig.iml (revision cba08629cbfd9427213cb8e1719d2ce1e601bdfc)
|
|
||||||
+++ b/.idea/pyuserconfig.iml (date 1711709021136)
|
|
||||||
@@ -1,8 +1,10 @@
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
- <content url="file://$MODULE_DIR$" />
|
|
||||||
- <orderEntry type="jdk" jdkName="Python 3.7 (pyuserconfig)" jdkType="Python SDK" />
|
|
||||||
+ <content url="file://$MODULE_DIR$">
|
|
||||||
+ <excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
+ </content>
|
|
||||||
+ <orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
<component name="TestRunnerService">
|
|
||||||
Index: .idea/misc.xml
|
|
||||||
IDEA additional info:
|
|
||||||
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
|
|
||||||
<+><?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"ProjectRootManager\" version=\"2\" project-jdk-name=\"Python 3.7 (pyuserconfig)\" project-jdk-type=\"Python SDK\" />\n</project>
|
|
||||||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
|
||||||
<+>UTF-8
|
|
||||||
===================================================================
|
|
||||||
diff --git a/.idea/misc.xml b/.idea/misc.xml
|
|
||||||
--- a/.idea/misc.xml (revision cba08629cbfd9427213cb8e1719d2ce1e601bdfc)
|
|
||||||
+++ b/.idea/misc.xml (date 1711709021140)
|
|
||||||
@@ -1,4 +1,4 @@
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
- <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (pyuserconfig)" project-jdk-type="Python SDK" />
|
|
||||||
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (pyuserconfig)" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
||||||
\ No newline at end of file
|
|
@@ -1,4 +0,0 @@
|
|||||||
<changelist name="Uncommitted_changes_before_Checkout_at_29_03_2024_21_55_[Changes]" date="1711745731399" recycled="true" deleted="true">
|
|
||||||
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Checkout_at_29_03_2024_21_55_[Changes]/shelved.patch" />
|
|
||||||
<option name="DESCRIPTION" value="Uncommitted changes before Checkout at 29/03/2024 21:55 [Changes]" />
|
|
||||||
</changelist>
|
|
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
98
.idea/workspace.xml
generated
98
.idea/workspace.xml
generated
@@ -1,98 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="AutoImportSettings">
|
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
|
||||||
</component>
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="cee80f0e-cafd-4941-b7a7-08488f062272" name="Changes" comment="">
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/pyuserconfig.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/pyuserconfig.iml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/cli/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/cli/__init__.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/userconfig/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/userconfig/__init__.py" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectColorInfo">{
|
|
||||||
"associatedIndex": 2
|
|
||||||
}</component>
|
|
||||||
<component name="ProjectId" id="2eKxRWG4LxyRkMlusUvbQX9b4Vc" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
|
||||||
"keyToString": {
|
|
||||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
|
||||||
"Python.__init__.executor": "Run",
|
|
||||||
"Python.cli.executor": "Run",
|
|
||||||
"Python.test.executor": "Run",
|
|
||||||
"Python.tools.executor": "Run",
|
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
|
||||||
"git-widget-placeholder": "reorg__checks",
|
|
||||||
"last_opened_file_path": "/Users/lysis/Documents/Repositories/lys.is/pyuserconfig",
|
|
||||||
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
|
|
||||||
}
|
|
||||||
}]]></component>
|
|
||||||
<component name="RunManager">
|
|
||||||
<configuration name="test" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
|
||||||
<module name="pyuserconfig" />
|
|
||||||
<option name="ENV_FILES" value="" />
|
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
|
||||||
<option name="PARENT_ENVS" value="true" />
|
|
||||||
<envs>
|
|
||||||
<env name="PYTHONUNBUFFERED" value="1" />
|
|
||||||
</envs>
|
|
||||||
<option name="SDK_HOME" value="" />
|
|
||||||
<option name="SDK_NAME" value="Python 3.12 (userconfig)" />
|
|
||||||
<option name="WORKING_DIRECTORY" value="$Sourcepath$" />
|
|
||||||
<option name="IS_MODULE_SDK" value="false" />
|
|
||||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
|
||||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
|
||||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test.py" />
|
|
||||||
<option name="PARAMETERS" value="" />
|
|
||||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
|
||||||
<option name="EMULATE_TERMINAL" value="false" />
|
|
||||||
<option name="MODULE_MODE" value="false" />
|
|
||||||
<option name="REDIRECT_INPUT" value="false" />
|
|
||||||
<option name="INPUT_FILE" value="" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
<component name="SharedIndexes">
|
|
||||||
<attachedChunks>
|
|
||||||
<set>
|
|
||||||
<option value="bundled-python-sdk-09665e90c3a7-d3b881c8e49f-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-233.15026.15" />
|
|
||||||
</set>
|
|
||||||
</attachedChunks>
|
|
||||||
</component>
|
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="cee80f0e-cafd-4941-b7a7-08488f062272" name="Changes" comment="" />
|
|
||||||
<created>1711667063738</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1711667063738</updated>
|
|
||||||
</task>
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
|
||||||
<option name="TAB_STATES">
|
|
||||||
<map>
|
|
||||||
<entry key="MAIN">
|
|
||||||
<value>
|
|
||||||
<State />
|
|
||||||
</value>
|
|
||||||
</entry>
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@@ -76,10 +76,8 @@ def main():
|
|||||||
dest='file', action='store')
|
dest='file', action='store')
|
||||||
cmdline = parser.parse_args()
|
cmdline = parser.parse_args()
|
||||||
debug = Debug()
|
debug = Debug()
|
||||||
# debug.set_verbose(cmdline.verbose)
|
debug.set_verbose(cmdline.verbose)
|
||||||
# cfg = Conf(filename=cmdline.file, debug=debug)
|
cfg = Conf(filename=cmdline.file, debug=debug)
|
||||||
debug.set_verbose(3)
|
|
||||||
cfg = Conf(filename='/Users/lysis/userconfig2-test.conf', debug=debug)
|
|
||||||
uc = Userconfig(cfg)
|
uc = Userconfig(cfg)
|
||||||
|
|
||||||
cfg.debug.stdout(f'Verbose level: {cfg.debug.get_verbose()}', 1)
|
cfg.debug.stdout(f'Verbose level: {cfg.debug.get_verbose()}', 1)
|
||||||
@@ -117,6 +115,7 @@ def main():
|
|||||||
continue
|
continue
|
||||||
if package.name in ['.svn', '.git']:
|
if package.name in ['.svn', '.git']:
|
||||||
cfg.debug.stdout(f'{package.path} is a svn or git data directory, skipping', 2, 'WARNING')
|
cfg.debug.stdout(f'{package.path} is a svn or git data directory, skipping', 2, 'WARNING')
|
||||||
|
continue
|
||||||
if os.path.isfile(f'{package.path}/.ignore'):
|
if os.path.isfile(f'{package.path}/.ignore'):
|
||||||
cfg.debug.stdout(f'{package.path} contains .ignore, skipping', 2, 'WARNING')
|
cfg.debug.stdout(f'{package.path} contains .ignore, skipping', 2, 'WARNING')
|
||||||
continue
|
continue
|
||||||
@@ -124,9 +123,15 @@ def main():
|
|||||||
cfg.debug.stdout(f'Start Package {cfg.debug.green(package.path)}', 1, 'NOTICE')
|
cfg.debug.stdout(f'Start Package {cfg.debug.green(package.path)}', 1, 'NOTICE')
|
||||||
# Get all category directories for package
|
# Get all category directories for package
|
||||||
(category_dirs, dir_config) = uc.process_package_dir(package.path)
|
(category_dirs, dir_config) = uc.process_package_dir(package.path)
|
||||||
|
if not category_dirs:
|
||||||
|
cfg.debug.stdout(f'Could not get category_dirs for package {package.name}, skipping package.', 0, 'ERROR')
|
||||||
|
continue
|
||||||
|
if not dir_config:
|
||||||
|
cfg.debug.stdout(f'Could not get dir_config for package {package.name}, skipping package.', 0, 'ERROR')
|
||||||
|
continue
|
||||||
cfg.debug.stdout(f'Got categories: {category_dirs}', 2)
|
cfg.debug.stdout(f'Got categories: {category_dirs}', 2)
|
||||||
host_category_dirs = uc.filter_categories(category_dirs)
|
host_category_dirs = uc.filter_categories(category_dirs)
|
||||||
cfg.debug.stdout(f'Host uses categories: {", ".join([f'{v[1]}_{v[2]}' for v in host_category_dirs])}', 2)
|
cfg.debug.stdout('Host uses categories: %s' % ", ".join([f'{v[1]}_{v[2]}' for v in host_category_dirs]), 2)
|
||||||
file_list = dict()
|
file_list = dict()
|
||||||
for c in host_category_dirs:
|
for c in host_category_dirs:
|
||||||
file_list = uc.process_category_dir(c, file_list)
|
file_list = uc.process_category_dir(c, file_list)
|
||||||
@@ -136,7 +141,7 @@ def main():
|
|||||||
subprocess.call([f'{package.path}/install.sh'])
|
subprocess.call([f'{package.path}/install.sh'])
|
||||||
for file in file_list:
|
for file in file_list:
|
||||||
dest = f'{dir_config.get(section="Main", option="dest")}/{file}'
|
dest = f'{dir_config.get(section="Main", option="dest")}/{file}'
|
||||||
cfg.debug.stdout(f'Generating {dest} from:\n {"\n ".join(file_list[file])}', 1)
|
cfg.debug.stdout('Generating %s from:\n %s' % (dest, "\n ".join(file_list[file])), 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
comment_string = dir_config.get(section="Main", option="commentstring")
|
comment_string = dir_config.get(section="Main", option="commentstring")
|
||||||
|
11
install.sh
11
install.sh
@@ -1,10 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if type pip3 >/dev/null 2>&1; then
|
if type pipx >/dev/null 2>&1; then
|
||||||
pip3 install --user git+https://git.lys.is/lysis/pyuserconfig.git
|
pipx install git+https://git.lys.is/lysis/pyuserconfig.git
|
||||||
|
if [ ! -e ~/.userconfig ]; then
|
||||||
git clone git@git.lys.is:lysis/userconfig.git ~/.userconfig
|
git clone git@git.lys.is:lysis/userconfig.git ~/.userconfig
|
||||||
mkdir ~/.config
|
fi
|
||||||
PYTHONPATH=~/.local/lib ~/.local/bin/userconfig.py
|
userconfig
|
||||||
else
|
else
|
||||||
echo "No pip3 installed, cannot proceed."
|
echo "No pipx installed, cannot proceed."
|
||||||
fi
|
fi
|
||||||
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "userconfig"
|
name = "userconfig"
|
||||||
version = "2.0b-1"
|
version = "2.1"
|
||||||
authors = [ {name = "Marcus Stoegbauer", email = "marcus@grmpf.org"} ]
|
authors = [ {name = "Marcus Stoegbauer", email = "marcus@grmpf.org"} ]
|
||||||
maintainers = [ {name = "Marcus Stoegbauer", email = "marcus@grmpf.org"} ]
|
maintainers = [ {name = "Marcus Stoegbauer", email = "marcus@grmpf.org"} ]
|
||||||
description = "Generate config files for user home"
|
description = "Generate config files for user home"
|
||||||
|
@@ -28,11 +28,11 @@ class Userconfig:
|
|||||||
if not os.path.isfile(package_config_file):
|
if not os.path.isfile(package_config_file):
|
||||||
self._cfg.debug.stdout(f'No config file {self._cfg.get("configfile")} in {package_dir}, skipping',
|
self._cfg.debug.stdout(f'No config file {self._cfg.get("configfile")} in {package_dir}, skipping',
|
||||||
0, 'ERROR')
|
0, 'ERROR')
|
||||||
return None
|
return None, None
|
||||||
dir_config = self.get_config(package_config_file)
|
dir_config = self.get_config(package_config_file)
|
||||||
if not dir_config:
|
if not dir_config:
|
||||||
self._cfg.debug.stdout(f'Cannot read config file {package_config_file}, skipping', 0, 'ERROR')
|
self._cfg.debug.stdout(f'Cannot read config file {package_config_file}, skipping', 0, 'ERROR')
|
||||||
return None
|
return None, None
|
||||||
classes = []
|
classes = []
|
||||||
for category in os.scandir(package_dir):
|
for category in os.scandir(package_dir):
|
||||||
if category.path == package_config_file:
|
if category.path == package_config_file:
|
||||||
@@ -91,6 +91,9 @@ class Userconfig:
|
|||||||
(prio, category, value, category_dir) = category_dir_tuple
|
(prio, category, value, category_dir) = category_dir_tuple
|
||||||
self._cfg.debug.stdout(f'process category {category_dir}', 3)
|
self._cfg.debug.stdout(f'process category {category_dir}', 3)
|
||||||
for file in os.scandir(category_dir):
|
for file in os.scandir(category_dir):
|
||||||
|
if file.name.endswith('.swp'):
|
||||||
|
self._cfg.debug.stdout(f'Ignoring swap file {file.name}', 3)
|
||||||
|
continue
|
||||||
if file.name not in file_list:
|
if file.name not in file_list:
|
||||||
file_list[file.name] = []
|
file_list[file.name] = []
|
||||||
file_list[file.name].append(file.path)
|
file_list[file.name].append(file.path)
|
||||||
@@ -170,6 +173,7 @@ class Userconfig:
|
|||||||
ret.set(section="Main", option="dest", value=ret.get(section="Main", option="dest")+"/")
|
ret.set(section="Main", option="dest", value=ret.get(section="Main", option="dest")+"/")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
# FIXME remove, unused now
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_skip_comment(fp, comment_string):
|
def read_skip_comment(fp, comment_string):
|
||||||
"""Read line from filehandle fp and skip all empty (whitespace) lines and lines starting with comment_string
|
"""Read line from filehandle fp and skip all empty (whitespace) lines and lines starting with comment_string
|
||||||
@@ -180,7 +184,8 @@ class Userconfig:
|
|||||||
not re.match(r"^\s+$", line)):
|
not re.match(r"^\s+$", line)):
|
||||||
yield line
|
yield line
|
||||||
|
|
||||||
def diff(self, dest_file, temp_file, comment_string):
|
# FIXME remove, unused now
|
||||||
|
def diff_old(self, dest_file, temp_file, comment_string):
|
||||||
"""diff dest_file and temp_file, returns True if files differ, False if they are the same"""
|
"""diff dest_file and temp_file, returns True if files differ, False if they are the same"""
|
||||||
self._cfg.debug.stdout(f'Diffing {dest_file} and {temp_file}, comment: {comment_string}', 3)
|
self._cfg.debug.stdout(f'Diffing {dest_file} and {temp_file}, comment: {comment_string}', 3)
|
||||||
if not os.path.isfile(dest_file):
|
if not os.path.isfile(dest_file):
|
||||||
@@ -204,6 +209,35 @@ class Userconfig:
|
|||||||
self._cfg.debug.stdout(f'{dest_file} is the same as generated config', 3)
|
self._cfg.debug.stdout(f'{dest_file} is the same as generated config', 3)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def sanitize_input(fp, comment_string):
|
||||||
|
"""Read line from filehandle fp and skip all empty (whitespace) lines and lines starting with comment_string
|
||||||
|
return result as set
|
||||||
|
"""
|
||||||
|
ret = set()
|
||||||
|
for line in fp:
|
||||||
|
line = line[:-1]
|
||||||
|
if ((comment_string != "" and not re.match("^"+re.escape(comment_string), line)) and line != "" and
|
||||||
|
not re.match(r"^\s+$", line)):
|
||||||
|
ret.add(line)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def diff(self, dest_file, temp_file, comment_string):
|
||||||
|
"""diff dest_file and temp_file, returns True if files differ, False if they are the same"""
|
||||||
|
self._cfg.debug.stdout(f'Diffing {dest_file} and {temp_file}, comment: {comment_string}', 3)
|
||||||
|
if not os.path.isfile(dest_file):
|
||||||
|
self._cfg.debug.stdout(f'dest_file {dest_file} does not exist.', 3)
|
||||||
|
return True
|
||||||
|
if not os.path.isfile(temp_file):
|
||||||
|
self._cfg.debug.stderr(f'Temporary file {temp_file} does not exist, this should not happen.', 0, 'ERROR')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# get temp_file and dest_file, remove comments and whitespaces
|
||||||
|
temp_lines = self.sanitize_input(open(temp_file), comment_string)
|
||||||
|
dest_lines = self.sanitize_input(open(dest_file), comment_string)
|
||||||
|
# differences of temp_file and dest_file in both directions, if != 0: files differ
|
||||||
|
return len(temp_lines.symmetric_difference(dest_lines)) != 0
|
||||||
|
|
||||||
def user_config_generated(self, filename):
|
def user_config_generated(self, filename):
|
||||||
"""returns True if filename has been generated by userconfig, False else"""
|
"""returns True if filename has been generated by userconfig, False else"""
|
||||||
|
|
||||||
|
@@ -2,22 +2,33 @@ import platform
|
|||||||
|
|
||||||
|
|
||||||
def get_hostname():
|
def get_hostname():
|
||||||
hostname = platform.node()
|
node_name = platform.node()
|
||||||
if hostname.count("."):
|
if node_name.count("."):
|
||||||
hostname = hostname.split(".")[0]
|
return node_name.split(".")[0]
|
||||||
return hostname
|
else:
|
||||||
|
return node_name
|
||||||
|
|
||||||
|
|
||||||
def get_arch():
|
def get_arch():
|
||||||
return platform.system()
|
return platform.system()
|
||||||
|
|
||||||
|
|
||||||
|
def get_domain():
|
||||||
|
node_name = platform.node()
|
||||||
|
if node_name.count("."):
|
||||||
|
return '.'.join(node_name.split('.')[1:])
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def check_class(class_tuple):
|
def check_class(class_tuple):
|
||||||
(prio, category, value, path) = class_tuple
|
(prio, category, value, path) = class_tuple
|
||||||
if category == 'Arch':
|
if category == 'Arch':
|
||||||
return get_arch() == value
|
return get_arch() == value
|
||||||
elif category == 'Host':
|
elif category == 'Host':
|
||||||
return get_hostname() == value
|
return get_hostname() == value
|
||||||
|
elif category == 'Domain':
|
||||||
|
return get_domain() == value
|
||||||
elif value == '': # if value is empty, we cannot filter anything, so it matches always
|
elif value == '': # if value is empty, we cannot filter anything, so it matches always
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user