From 0996f26be8d1f23676804c14d6ce374432489e24 Mon Sep 17 00:00:00 2001 From: Ctibor Date: Fri, 17 Mar 2017 19:35:31 +0100 Subject: Add action.py and further improve check.py --- tools/.sync-rpi.conf.kate-swp | Bin 517 -> 0 bytes tools/action.py | 30 ++++++++++++++ tools/check.py | 91 ++++++++++++++++++++++++++++++++++++++++++ tools/config.py | 2 + tools/config.pyc | Bin 210 -> 0 bytes tools/sync-rpi-config.py | 76 ----------------------------------- tools/sync-rpi.conf | 7 +++- 7 files changed, 128 insertions(+), 78 deletions(-) delete mode 100644 tools/.sync-rpi.conf.kate-swp create mode 100644 tools/action.py create mode 100644 tools/check.py delete mode 100644 tools/config.pyc delete mode 100644 tools/sync-rpi-config.py (limited to 'tools') diff --git a/tools/.sync-rpi.conf.kate-swp b/tools/.sync-rpi.conf.kate-swp deleted file mode 100644 index 373ddea..0000000 Binary files a/tools/.sync-rpi.conf.kate-swp and /dev/null differ diff --git a/tools/action.py b/tools/action.py new file mode 100644 index 0000000..a2d0ba0 --- /dev/null +++ b/tools/action.py @@ -0,0 +1,30 @@ +# The basic workflow is like this: +# git rsync +# [remote git] <-> [local git] <-> [local storage] +# +# If action PULL is specified: +# 1. git pull from remote repo +# 2. rsync local repo to local storage +# +# If action PUSH is specified: +# 1. rsync from local storage to local repo +# 2. git push to remote repo + +# Pull config files from git repo + +import git + +def repo_pull(): + pass + +# Push config files to git repo +def repo_push(): + pass + +# Pull config files from local storage to be pushed to repo +def local_pull(): + pass + +# Push config pulled from repo to local storage +def local_push(): + pass diff --git a/tools/check.py b/tools/check.py new file mode 100644 index 0000000..efa2449 --- /dev/null +++ b/tools/check.py @@ -0,0 +1,91 @@ +import ConfigParser, os, getopt, sys, config + +ini = ConfigParser.ConfigParser() + +# Parse parameters +def get_opts(argv): + try: + opts, args = getopt.getopt(argv,"ha:c:d:l",["conf=","action=","device=","list-devices"]) + except getopt.GetoptError: + usage() + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + return usage() + sys.exit() + elif opt in ("-l", "--list-devices"): + print "You have configured these devices: " + list_devices() + sys.exit() + elif opt in ("-a", "--action"): + config.action = arg + elif opt in ("-c", "--conf"): + config.configfile = arg + elif opt in ("-d", "--device"): + config.device = arg + +# Check parameters for errors +def check_opts(): + get_opts(sys.argv[1:]) + if not config.action: + print "Error: No action has been specified. Use -a." + return usage() + sys.exit(2) + if not config.action == "pull" or config.action == "push": + print "Error: Action \"" + config.action + "\" is invalid." + return usage() + sys.exit(2) + if not config.device: + print "Error: No device has been specified. Use -d." + return usage() + sys.exit(2) + if config.device: + load_config(config.configfile) + if not ini.has_section(config.device): + print "Error: Device \"" + config.device + "\" not configured. Add it to\"" + config.configfile + "." + sys.exit(2) + +# Load provided config file or use default +def load_config(configfile): + if not configfile: + config.configfile = "/etc/sync-rpi.conf" + try: + ini.read([config.configfile]) + except: + sys.exit(2) + +# Check if configuration file is sane +def check_config(configfile): + get_opts(sys.argv[1:]) + load_config(config.configfile) + error = 0 + #print config.configfile + #print ini.items('config') + #print ini.items('alcor-01') + #print config.options_config + #print config.options_device + for option in config.options_config: + if not ini.has_option('config', option): + print "Error: Option \"" + option + "\" not set in [config]." + error = 1 + for section in ini.sections(): + for option in config.options_device: + if section != 'config' and not ini.has_option(section, option): + print "Error: Option " + option + " not set in [" + section + "]." + error = 1 + + if error == 1: + sys.exit(2) + +# List all devices defined in config.configfile +def list_devices(): + load_config(config.configfile) + return " ".join(ini.sections()[1:]) + +# Prin usage +def usage(): + print """Usage: sync-rpi-config -a ACTION -d DEVICE [ -c [FILE] ] [ -l ] + Options + -a, --action ACTION can be either pull or push. You are pushing config from you workstation to device or pulling it back. + -d, --device DEVICE is set in configuration file. It is the machine you wish to push config to or pull from. + -c, --conf Path to configuration file. + -l, --list-devices List all devices defined in current configuration file.""" diff --git a/tools/config.py b/tools/config.py index 61dacd8..c8e6ec3 100644 --- a/tools/config.py +++ b/tools/config.py @@ -1,3 +1,5 @@ configfile = '' device = '' action = '' +options_config = [ 'repo', 'repo_path', 'rpi1', 'rpi2', 'rpi3', 'rpi1_path', 'rpi2_path', 'rpi3_path' ] +options_device = [ 'type', ] diff --git a/tools/config.pyc b/tools/config.pyc deleted file mode 100644 index 270f526..0000000 Binary files a/tools/config.pyc and /dev/null differ diff --git a/tools/sync-rpi-config.py b/tools/sync-rpi-config.py deleted file mode 100644 index 9496c70..0000000 --- a/tools/sync-rpi-config.py +++ /dev/null @@ -1,76 +0,0 @@ -import ConfigParser, os, getopt, sys, config - -ini = ConfigParser.ConfigParser() - -# Parse parameters -def get_opts(argv): - try: - opts, args = getopt.getopt(argv,"ha:c:d:l",["conf=","action=","device=","list-devices"]) - except getopt.GetoptError: - print 'sync-rpi-config: -a -c -d ' - sys.exit(2) - for opt, arg in opts: - if opt == '-h': - return usage() - sys.exit() - elif opt in ("-l", "--list-devices"): - print "You have configured these devices: " + list_devices() - sys.exit() - elif opt in ("-a", "--action"): - config.action = arg - elif opt in ("-c", "--conf"): - config.configfile = arg - elif opt in ("-d", "--device"): - config.device = arg - -# Check parameters for errors -def check_opts(): - if not config.action: - print "Error: No action has been specified." - return usage() - sys.exit(2) - if not config.action == "pull" or config.action == "push": - print "Error: Action \"" + config.action + "\" is invalid." - return usage() - sys.exit(2) - if not config.device: - print "Error: No device has been specified." - return usage() - sys.exit(2) - if config.device: - load_config(config.configfile) - if not ini.has_section(config.device): - print "Error: Device \"" + config.device + "\" not configured. Add it to\"" + config.configfile + "." - sys.exit(2) - -# Load provided config file or use default -def load_config(configfile): - if not configfile: - config.configfile = "/etc/sync-rpi.conf" - try: - ini.read([config.configfile]) - except: - sys.exit(2) - -# Check if configuration file is sane -def check_config(configfile): - options_config = ['repo', 'repo_path', 'rpi1', 'rpi2', 'rpi3' ] - options_device = ['type'] - load_config(config.configfile) - for option in options_config: - if not ini.has_option('config', option): - print "Option " + option + " not set in config" - break - -# List all devices defined in config.configfile -def list_devices(): - load_config(config.configfile) - return " ".join(ini.sections()[1:]) - -def usage(): - print """Usage: sync-rpi-config -a ACTION -d DEVICE [ -c [FILE] ] [ -l ] - Options - -a, --action ACTION can be either pull or push. You are pushing config from you workstation to device or pulling it back. - -d, --device DEVICE is set in configuration file. It is the machine you wish to push config to or pull from. - -c, --conf Path to configuration file. - -l, --list-devices List all devices defined in current configuration file.""" diff --git a/tools/sync-rpi.conf b/tools/sync-rpi.conf index b9651c1..b2ac111 100644 --- a/tools/sync-rpi.conf +++ b/tools/sync-rpi.conf @@ -1,8 +1,11 @@ [config] ## Define directories, where you store crosscompiled environment +rpi1=true +rpi2=true +#rpi3=true rpi1_path=/usr/armv6j-hardlofat-linux-gnueabi rpi2_path=/usr/armv7a-hardfloat-linux-gnueabi -rpi3_path=/usr/aarch64-uknown-linux-gnu +#rpi3_path=/usr/aarch64-uknown-linux-gnu ## Full URI to the git repository holding configuration files repo=ssh://git@git.brancik.cz/rpi-config.git @@ -14,6 +17,6 @@ repo_path=conf ## Name the section after the device [alcor-01] ## Define the type of RPi being used -type = rpi1 +type=rpi1 [alcor-02] [mizar] -- cgit v1.2.3