Compare commits

...

10 Commits

4 changed files with 41 additions and 9 deletions

View File

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

View File

@ -8,7 +8,7 @@ Created by Marcus Stoegbauer on 2013-01-10.
""" """
import platform import platform
from operator import itemgetter
class Checks(object): class Checks(object):
def __init__(self): def __init__(self):
@ -23,7 +23,7 @@ class Checks(object):
# def getShortHostname # def getShortHostname
def __classes_for_host__(self): def __classes_for_host__(self, reverse=False):
"""docstring for __classesForHost""" """docstring for __classesForHost"""
classes = [] classes = []
for c in dir(self): for c in dir(self):
@ -32,7 +32,7 @@ class Checks(object):
ret = getattr(self, c)() ret = getattr(self, c)()
if type(ret) == tuple and len(ret) == 3: if type(ret) == tuple and len(ret) == 3:
classes.append(ret) 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): def header(self):
"""docstring for header""" """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 re
import getopt import getopt
import time import time
import subprocess
# #
import Userconfig.cfgfile as cfgfile import Userconfig.cfgfile as cfgfile
@ -46,7 +47,6 @@ def workconf(directory, depth=2):
for d in dirs: for d in dirs:
name = directory+"/"+d name = directory+"/"+d
if os.path.isdir(name): if os.path.isdir(name):
# fixme: create name if it does not exist
workconf(name, depth+1) workconf(name, depth+1)
if name.endswith(".swp"): if name.endswith(".swp"):
continue continue
@ -81,9 +81,18 @@ def workdir(directory):
# key is the destination filename, values are all classes filenames that are used to # key is the destination filename, values are all classes filenames that are used to
# build the file # build the file
destfiles = {} 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 # 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 # build classes directory
if h[0] != "": if h[0] != "":
classdir = directory+"/"+h[0]+"_"+h[1] classdir = directory+"/"+h[0]+"_"+h[1]
@ -157,6 +166,12 @@ def process_all_files(destfiles, dir_config):
debug.debug(" ================ process_all_files ===============", 1) debug.debug(" ================ process_all_files ===============", 1)
for df in destfiles.keys(): for df in destfiles.keys():
debug.debug(" ??? Processing source files for %s." % df, 2) 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 # assemble file to tmp
commentstring = "" commentstring = ""
if dir_config.check("Main", "commentstring"): if dir_config.check("Main", "commentstring"):
@ -185,8 +200,13 @@ def process_all_files(destfiles, dir_config):
debug.debug(" ================ process_all_files ===============", 1) debug.debug(" ================ process_all_files ===============", 1)
def main(): 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:
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hdc:v", ["help", "debug", "config="]) opts, args = getopt.getopt(sys.argv[1:], "hdc:v", ["help", "debug", "config="])