diff --git a/README b/README index 5bb9391163e211b49d43aa315fb1cd2d75e4715e..144069a9d3cf882a63566d1ae2a8bc18aafc0275 100644 --- a/README +++ b/README @@ -1,32 +1,35 @@ -====== -Config -====== -cc-cli support FreeDesktop BaseDirectory specifications (http://standards.freedesktop.org/basedir-spec/0.6/) -Your main config is stored in ~/.config/cc-cli/cli (ini file format with section cli) -You can configure all parameter in this file -You will find an example in examples subdirectory in git. - -You can set default behaviour with environment variables. The following are recognised: -CC_SERVER, CC_PORT, CC_LOGIN, CC_PASS, CC_DEBUG, CC_PROFILE - -To quickly connect to mulptiple servers, you can define profiles. -A profile is an ini config file in ~/.config/cc-cli/ directory with suffix .profile and section profile. -Profiles file are loaded exactly like the main config file. -You can load toto profile by calling cc-cli -P toto -You have to play with the following loading order to do worderful things. - -You configuration is loaded in this order: -1 load default config file settings -2 load default config file profile -2 load environment profile -3 load environment settings -4 load argline profile -5 load argline settings +======= +Profile +======= +A profile in a set of configuration options. +cc-cli support FreeDesktop BaseDirectory specifications, see +http://standards.freedesktop.org/basedir-spec/0.6/ to store his config files. +Profiles are stored in ~/.config/cc-cli/profile. This file format is ini where +every profile is a section. +cc-cli load at every start the cli profile. You can specify +a default profile in cli profile with option "profile". +You will find examples in examples subdirectory in git repository. + +To quickly connect to mulptiple servers, you can define a profile by server. + +Profile is loaded in this order: +1 load [cli] profile in ~/.config/cc-cli/profile +2 load profile specified by option profile in [cli] profile +3 load profile specified by environment +4 load profile specified on argument line + +=========== +Environment +=========== +You can set some options by environment variables. +The following variables are recognised: CC_SERVER, CC_PORT, CC_LOGIN, CC_PASS, +CC_DEBUG, CC_PROFILE. ===== Alias ===== CLI support aliasing. This is a very useful command substitution +Alias is stored in ~/.config/cc-cli/alias You can use the alias command to set alias. Setting an alias w, which list online client @@ -35,6 +38,11 @@ alias w "list a&con!=offline&role=client" Setting an alias vm, which list running vm (and show cpu) alias vm "list vm&status=running$cpu" +======= +History +======= +History is stored in ~/.local/share/cc-cli/history + === TQL === diff --git a/bin/cc-cli b/bin/cc-cli index 199ce32077ad9c0ee0f17076555c7ee5b8a3d0dc..9d35541387c583d3c8a9cdda1b45d55ef92b5ca1 100755 --- a/bin/cc-cli +++ b/bin/cc-cli @@ -23,36 +23,28 @@ settings = { "port": "1984", "timeout": "30", "hsize": "100", - "config": "%s/cli"%BaseDirectory.save_config_path(cccli.canonical_name), "alias": "%s/alias"%BaseDirectory.save_config_path(cccli.canonical_name), "history": "%s/history"%BaseDirectory.save_data_path(cccli.canonical_name), } -def load_config_file(config, filename, section): - '''Update a dict with param from an ini file ''' - if os.access(filename, os.R_OK): - fparser = ConfigParser.RawConfigParser() - fparser.read(filename) - if fparser.has_section(section): - config.update(fparser.items(section)) - else: - printer.warn("Unable to load file %s"%filename) - -def get_profile_path(profile): - '''Force a profile path from a profile name''' - return "%s/%s/%s.profile"%(BaseDirectory.xdg_config_home, cccli.canonical_name, profile) - try: # load a printer printer = Printer(False) - # parse config file - if os.access(settings["config"], os.R_OK): - load_config_file(settings, settings["config"], "cli") + # parse profile file and load default profile + try: + propath = "%s/profile"%BaseDirectory.save_config_path(cccli.canonical_name) + fparser = ConfigParser.RawConfigParser() + fparser.read(propath) + if fparser.has_section("cli"): + settings.update(fparser.items("cli")) + except Exception: + fparser = None - # parse config file profile + # load "default profile" profile if "profile" in settings: - load_config_file(settings, get_profile_path(settings["profile"]), "profile") + if fparser is not None and fparser.has_section(settings["profile"]): + settings.update(fparser.items(settings["profile"])) del settings["profile"] # parse env @@ -67,9 +59,10 @@ try: if "CC_DEBUG" in os.environ: settings["debug"] = "True" - # parse env profile + # load env profile if "CC_PROFILE" in os.environ: - load_config_file(settings, get_profile_path(os.environ["CC_PROFILE"]), "profile") + if fparser is not None and fparser.has_section(os.environ["CC_PROFILE"]): + settings.update(fparser.items(os.environ["CC_PROFILE"])) # Parse line argument oparser = optparse.OptionParser(usage="usage: %prog [options] [commands]", @@ -99,9 +92,10 @@ try: if o: settings[i] = o - # parse argline file profile + # load argline profile if "profile" in settings: - load_config_file(settings, get_profile_path(settings["profile"]), "profile") + if fparser is not None and fparser.has_section(settings["profile"]): + settings.update(fparser.items(settings["profile"])) del settings["profile"] # debug stuff diff --git a/examples/cli b/examples/cli deleted file mode 100644 index f1979bd345963649db332139057fd3d51cdd9e6b..0000000000000000000000000000000000000000 --- a/examples/cli +++ /dev/null @@ -1,4 +0,0 @@ -[cli] -hsize = 1000 -profile = lab - diff --git a/examples/lab.profile b/examples/lab.profile deleted file mode 100644 index b6259028eabc0b24c263e4392b6d72db972086ab..0000000000000000000000000000000000000000 --- a/examples/lab.profile +++ /dev/null @@ -1,5 +0,0 @@ -[profile] -login = sluttrin -pass = toto42sh -server = 192.168.0.162 - diff --git a/examples/millet.profile b/examples/millet.profile deleted file mode 100644 index ccd42c509d83228665b2e25838a05a851b8db6f3..0000000000000000000000000000000000000000 --- a/examples/millet.profile +++ /dev/null @@ -1,6 +0,0 @@ -[profile] -login = seblu -pass = iloveseblu -server = 192.168.0.41 -debug = true - diff --git a/examples/prod.profile b/examples/prod.profile deleted file mode 100644 index 865359fb81164886c06065bd5636f2b81e77435c..0000000000000000000000000000000000000000 --- a/examples/prod.profile +++ /dev/null @@ -1,3 +0,0 @@ -[profile] -login = sluttrin -server = 10.15.255.42 diff --git a/examples/profile b/examples/profile new file mode 100644 index 0000000000000000000000000000000000000000..3603cfabb70eb37c221c4818535e6463307cf431 --- /dev/null +++ b/examples/profile @@ -0,0 +1,19 @@ +# this is the default profile +[cli] +hsize = 1000 +profile = lab + +[lab] +login = sluttrin +pass = toto +server = 192.168.0.162 + +[preprod] +login = seblu +pass = sex +server = 192.168.0.41 +debug = true + +[prod] +login = sluttrin +server = 10.15.255.42