- if action == '-e':
- # 1. create temporary config file copy
- temp_file = create_temp_file(conffile)
- mod_time = os.path.getmtime(temp_file)
-
- # 2. run system editor on this file
- run_system_editor(temp_file)
-
- # 3. check if this file is changed
- if os.path.getmtime(temp_file) <= mod_time:
- print 'File was not changed.'
- sys.exit(2)
-
- # TODO: 4. check this file's syntax
- try:
- check_syntax(temp_file)
- except CrontabParserError, e:
- print e.message
- print 'File has syntax errors, aborting.'
- sys.exit(3)
-
- # 5. replace system wide config file with new one
- shutil.move(temp_file, conffile)
-
- # 6. send sighup to dbuscron daemon
- pid = get_dbuscron_pid()
- os.kill(pid, signal.SIGHUP)
- print "Everything's OK, SIGHUP to dbuscron is sent."
-
- elif action == '-l':
- f = open(conffile, 'r')
- for l in f:
- print l.strip()
- f.close()
+ try:
+ if action == '-e':
+
+ # 1. create temporary config file copy
+ temp_file = create_temp_file(conffile)
+ mod_time = os.path.getmtime(temp_file)
+
+ try:
+ # 2. run system editor on this file
+ run_system_editor(temp_file)
+
+ # 3. check if this file is changed
+ if os.path.getmtime(temp_file) <= mod_time:
+ print 'File was not changed.'
+ sys.exit(2)
+
+ # 4. check this file's syntax
+ check_syntax(temp_file)