equal
deleted
inserted
replaced
85 help="Run target with given given interval(s)") |
85 help="Run target with given given interval(s)") |
86 |
86 |
87 |
87 |
88 # defaults |
88 # defaults |
89 parser.set_defaults( |
89 parser.set_defaults( |
90 loglevel = logging.WARNING, |
90 loglevel = logging.INFO, |
91 |
91 |
92 target_intervals = [], |
92 target_intervals = [], |
93 ) |
93 ) |
94 parser.set_defaults(**defaults) |
94 parser.set_defaults(**defaults) |
95 |
95 |
112 if options.exclude_from : |
112 if options.exclude_from : |
113 options.rsync_options['exclude-from'] = options.exclude_from |
113 options.rsync_options['exclude-from'] = options.exclude_from |
114 |
114 |
115 return options, args |
115 return options, args |
116 |
116 |
|
117 ## Configuration |
|
118 class ConfigError (Exception) : |
|
119 pass |
|
120 |
117 def process_config_name (name) : |
121 def process_config_name (name) : |
118 """ |
122 """ |
119 Process config file name into python version |
123 Process config file name into python version |
120 """ |
124 """ |
121 |
125 |
165 |
169 |
166 log.debug("config: %s", config) |
170 log.debug("config: %s", config) |
167 |
171 |
168 return config |
172 return config |
169 |
173 |
170 def config_bool (name, value) : |
174 def config_bool (name, value, strict=True) : |
171 if value.lower() in ('yes', 'true', '1', 'on') : |
175 if value.lower() in ('yes', 'true', '1', 'on') : |
172 return True |
176 return True |
173 |
177 |
174 elif value.lower() in ('no', 'false', '0', 'off') : |
178 elif value.lower() in ('no', 'false', '0', 'off') : |
175 return False |
179 return False |
176 |
180 |
|
181 elif strict : |
|
182 raise ConfigError("Unrecognized boolean value: {name} = {value}".format(name=name, value=value)) |
|
183 |
177 else : |
184 else : |
178 raise ConfigError("Unrecognized boolean value: {name} = {value}".format(name=name, value=value)) |
185 # allow non-boolean values |
|
186 return value |
179 |
187 |
180 def config_int (name, value) : |
188 def config_int (name, value) : |
181 try : |
189 try : |
182 return int(value) |
190 return int(value) |
183 |
191 |
293 # global defaults |
301 # global defaults |
294 _rsync_options = dict(options.rsync_options) |
302 _rsync_options = dict(options.rsync_options) |
295 |
303 |
296 if rsync_options : |
304 if rsync_options : |
297 # override |
305 # override |
298 _rsync_options.update(rsync_options) |
306 _rsync_options.update([ |
|
307 # parse |
|
308 (option, config_bool(option, value, strict=False)) for option, value in rsync_options.iteritems() |
|
309 ]) |
299 |
310 |
300 # lookup intervals |
311 # lookup intervals |
301 _intervals = [ |
312 _intervals = [ |
302 ( |
313 ( |
303 # lookup base from options.intervals |
314 # lookup base from options.intervals |
643 interval_config = config['intervals'][name] |
654 interval_config = config['intervals'][name] |
644 |
655 |
645 # parse |
656 # parse |
646 interval = Interval.from_config(options, name, **interval_config) |
657 interval = Interval.from_config(options, name, **interval_config) |
647 |
658 |
648 log.info("Interval: %s", name) |
659 log.debug("config interval: %s", name) |
649 |
660 |
650 # store |
661 # store |
651 options.intervals[name] = interval |
662 options.intervals[name] = interval |
652 |
663 |
653 for option in config['rsync_options'] : |
664 for option in config['rsync_options'] : |
654 value = config['rsync_options'][option] |
665 value = config['rsync_options'][option] |
655 |
666 |
656 # parse |
667 # parse, allowing non-boolean values as well... |
657 value = config_bool(option, value) |
668 value = config_bool(option, value, strict=False) |
658 |
669 |
659 log.debug("rsync option: %s=%s", option, value) |
670 log.debug("rsync option: %s=%s", option, value) |
660 |
671 |
661 # store |
672 # store |
662 options.rsync_options[option] = value |
673 options.rsync_options[option] = value |
670 target_config = config['targets'][name] |
681 target_config = config['targets'][name] |
671 |
682 |
672 # parse |
683 # parse |
673 target = Target.from_config(options, name, **target_config) |
684 target = Target.from_config(options, name, **target_config) |
674 |
685 |
675 log.info("Target: %s", name) |
686 log.info("Config target: %s", name) |
676 |
687 |
677 # run |
688 # run |
678 target.run(options) |
689 target.run(options) |
679 |
690 |
680 def config_defaults () : |
691 def config_defaults () : |