Compare commits

..

10 Commits

4 changed files with 41 additions and 9 deletions

View File

@ -11,7 +11,6 @@ import configparser
import os
import re
class Conf(object):
confobj = configparser.RawConfigParser()
cfgfile = ''
@ -57,7 +56,10 @@ class Conf(object):
"""
if not self.cfgfile:
raise Exception('No config file set')
return self.confobj.get(section, option)
try:
return self.confobj.get(section, option)
except configparser.NoOptionError:
raise ValueError('Option does not exist')
def set(self, section, option, value):
"""docstring for update"""

View File

@ -8,7 +8,7 @@ Created by Marcus Stoegbauer on 2013-01-10.
"""
import platform
from operator import itemgetter
class Checks(object):
def __init__(self):
@ -23,7 +23,7 @@ class Checks(object):
# def getShortHostname
def __classes_for_host__(self):
def __classes_for_host__(self, reverse=False):
"""docstring for __classesForHost"""
classes = []
for c in dir(self):
@ -32,7 +32,7 @@ class Checks(object):
ret = getattr(self, c)()
if type(ret) == tuple and len(ret) == 3:
classes.append(ret)
return map(lambda k: (k[1], k[2]), sorted(classes, key=lambda k: k[0]))
return map(lambda k: (k[1], k[2]), sorted(classes, key=itemgetter(0), reverse=reverse))
def header(self):
"""docstring for header"""

10
install.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
if type pip3 >/dev/null 2>&1; then
pip3 install --user git+https://git.lys.is/lysis/pyuserconfig.git
git clone git@git.lys.is:lysis/userconfig.git ~/.userconfig
mkdir ~/.config
PYTHONPATH=~/.local/lib ~/.local/bin/userconfig.py
else
echo "No pip3 installed, cannot proceed."
fi

View File

@ -14,6 +14,7 @@ import tempfile
import re
import getopt
import time
import subprocess
#
import Userconfig.cfgfile as cfgfile
@ -46,7 +47,6 @@ def workconf(directory, depth=2):
for d in dirs:
name = directory+"/"+d
if os.path.isdir(name):
# fixme: create name if it does not exist
workconf(name, depth+1)
if name.endswith(".swp"):
continue
@ -81,9 +81,18 @@ def workdir(directory):
# key is the destination filename, values are all classes filenames that are used to
# build the file
destfiles = {}
# FIXME: reverse_order should really be a bool in .cfg, implement variable types in cfg file
reverse_sort = False
try:
reverse_sort = (dir_config.get("Main", "reverse") == 'True')
except ValueError:
reverse_sort = False
if os.access(directory + "/install.sh", os.X_OK):
subprocess.call([directory + "/install.sh"])
# walk through all know classes in directory and find filenames
for h in classchecks.__classes_for_host__():
for h in classchecks.__classes_for_host__(reverse_sort):
# build classes directory
if h[0] != "":
classdir = directory+"/"+h[0]+"_"+h[1]
@ -157,6 +166,12 @@ def process_all_files(destfiles, dir_config):
debug.debug(" ================ process_all_files ===============", 1)
for df in destfiles.keys():
debug.debug(" ??? Processing source files for %s." % df, 2)
if not os.path.exists(os.path.dirname(df)):
debug.debug(" +++ Directory %s does not exist, creating" % os.path.dirname(df), 1)
os.mkdir(os.path.dirname(df))
if not os.path.isdir(os.path.dirname(df)):
debug.debug(" --- Destination directory %s does not exist, skipping." % os.path.dirname(df), 1)
return False
# assemble file to tmp
commentstring = ""
if dir_config.check("Main", "commentstring"):
@ -185,8 +200,13 @@ def process_all_files(destfiles, dir_config):
debug.debug(" ================ process_all_files ===============", 1)
def main():
configfile = os.environ['HOME']+"/etc/userconfig.cfg"
configfile_destinations = [os.environ['HOME'] + "/etc/",
os.environ['HOME'] + "/.local/etc"]
configfile = ''
for directory in configfile_destinations:
if os.path.isfile(directory + "/userconfig.cfg"):
configfile = directory + "/userconfig.cfg"
break
try:
try:
opts, args = getopt.getopt(sys.argv[1:], "hdc:v", ["help", "debug", "config="])