import getopt
from plc_config import PLCConfiguration
+from plc_config import ConfigurationException
####################
-release_id = "$Id: plc-config-tty,v 1.10 2006/12/12 10:14:44 thierry Exp $"
-release_rev = "$Revision: 1.10 $"
+release_id = "$Id$"
+release_rev = "$Revision$"
def init_flavour (flavour):
global service
global mainloop_usage
mainloop_usage= """Available commands:
Uppercase versions give variables comments, when available
--u/U\t\t\tEdit usual variables
--w\t\t\tWrite & consolidate
--r\t\t\tRestart %s service
--q\t\t\tQuit (without saving)
--h/?\t\t\tThis help
+ u/U\t\t\tEdit usual variables
+ w\t\t\tWrite & consolidate
+ r\t\t\tRestart %s service
+ q\t\t\tQuit (without saving)
+ h/?\t\t\tThis help
---
-l/L [<cat>|<var>]\tShow Locally modified variables/values
--s/S [<cat>|<var>]\tShow variables/values (all, in category, single)
--e/E [<cat>|<var>]\tEdit variables (all, in category, single)
+ l/L [<cat>|<var>]\tShow Locally modified variables/values
+ s/S [<cat>|<var>]\tShow variables/values (all, in category, single)
+ e/E [<cat>|<var>]\tEdit variables (all, in category, single)
---
--c\t\t\tList categories
--v/V [<cat>|<var>]List Variables (all, in category, single)
+ c\t\t\tList categories
+ v/V [<cat>|<var>]List Variables (all, in category, single)
---
Typical usage involves: u, [l,] w, r, q
""" % service
return
print ("Merged\n\t%s\nand\t%s\ninto\t%s"%(default_config,site_config,
consolidated_config))
+ os.system("set -x ; service plc reload")
####################
def restart_plc ():
return
elif (command in "wW"):
try:
+ # Confirm that various constraints are met before saving file.
+ cwrite.verify(cdef, cread)
cwrite.save(site_config)
+ except ConfigurationException, e:
+ print "Save failed due to a configuration exception: %s" % e
+ break;
except:
+ import traceback; print traceback.print_exc()
print ("Could not save -- fix write access on %s" % site_config)
break
print ("Wrote %s" % site_config)
print ("Unknown command >%s< -- use h for help" % answer)
####################
+# creates directory for file if not yet existing
def check_dir (config_file):
dirname = os.path.dirname (config_file)
if (not os.path.exists (dirname)):
- print "Config file %s located under a non-existing directory" % config_file
- answer=raw_input("Want to create %s [y]/n ? " % dirname)
- answer = answer.lower()
- if (answer == 'n'):
- print "Cannot proceed - good bye"
+ os.makedirs(dirname,0755)
+ if (not os.path.exists (dirname)):
+ print "Cannot create dir %s - exiting" % dirname
sys.exit(1)
else:
- os.makedirs(dirname,0755)
- if (not os.path.exists (dirname)):
- print "Cannot create dir %s - exiting" % dirname
- sys.exit(1)
- else:
- print "Created directory %s" % dirname
-
+ print "Created directory %s" % dirname
####################
def main ():