Compare commits
6 Commits
875e6a4831
...
main
Author | SHA1 | Date | |
---|---|---|---|
bfb82a7f9c | |||
d304e67089 | |||
3ee87bbb12 | |||
206398ab8d | |||
1f12b78ef3 | |||
f28e231185 |
13
install.sh
13
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
|
||||||
git clone git@git.lys.is:lysis/userconfig.git ~/.userconfig
|
if [ ! -e ~/.userconfig ]; then
|
||||||
mkdir ~/.config
|
git clone git@git.lys.is:lysis/userconfig.git ~/.userconfig
|
||||||
PYTHONPATH=~/.local/lib ~/.local/bin/userconfig.py
|
fi
|
||||||
|
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.0"
|
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"
|
||||||
|
@@ -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