def config_on_update(arr, configfile, lineno): if len(arr) < 3: stderr("%s:%d: 'on_update' requires at least 2 arguments: filename and shell command to run" % (configfile, lineno)) return 1 file = synctool_lib.prepare_path(arr[1]) cmd = string.join(arr[2:]) cmd = synctool_lib.prepare_path(cmd) # # check if the script exists # if cmd[0] != '/': # if relative path, use scriptdir # but what to do if scriptdir hasn't been set yet? Use default ... if not synctool_param.SCRIPT_DIR: synctool_param.SCRIPT_DIR = os.path.join(synctool_param.MASTERDIR, 'scripts') # do not use os.path.join() on dir+cmd+arguments cmd = synctool_param.SCRIPT_DIR + '/' + cmd # get the command file arr = string.split(cmd) cmdfile = arr[0] if not os.path.isfile(cmdfile): stderr("%s:%d: no such command '%s'" % (configfile, lineno, cmdfile)) return 1 synctool_param.ON_UPDATE[file] = cmd return 0
def config_logfile(arr, configfile, lineno): if len(arr) < 2: stderr("%s:%d: 'logfile' requires an argument: the full path to the file to write log messages to" % (configfile, lineno)) return 1 synctool_param.LOGFILE = synctool_lib.prepare_path(string.join(arr[1:])) return 0
def config_always_run(arr, configfile, lineno): if len(arr) < 2: stderr("%s:%d: 'always_run' requires an argument: the shell command to run" % (configfile, lineno)) return 1 cmd = string.join(arr[1:]) cmd = synctool_lib.prepare_path(cmd) if cmd in synctool_param.ALWAYS_RUN: stderr("%s:%d: same command defined again: %s" % (configfile, lineno, cmd)) return 1 # # check if the script exists # if cmd[0] != '/': # if relative path, use scriptdir # but what to do if scriptdir hasn't been set yet? Use default ... if not synctool_param.SCRIPT_DIR: synctool_param.SCRIPT_DIR = os.path.join(synctool_param.MASTERDIR, 'scripts') # do not use os.path.join() on dir+cmd+arguments cmd = synctool_param.SCRIPT_DIR + '/' + cmd # get the command file arr = string.split(cmd) cmdfile = arr[0] if not os.path.isfile(cmdfile): stderr("%s:%d: no such command '%s'" % (configfile, lineno, cmdfile)) return 1 synctool_param.ALWAYS_RUN.append(cmd) return 0
def _config_command(param, arr, short_cmd, configfile, lineno): '''helper for configuring rsync_cmd, ssh_cmd, synctool_cmd, etc.''' if len(arr) < 2: stderr("%s:%d: '%s' requires an argument: the full path to the '%s' command" % (configfile, lineno, param, short_cmd)) return (1, None) cmd = synctool_lib.prepare_path(arr[1]) if not os.path.isfile(cmd): if cmd[0] != '/': stderr("%s:%d: '%s' requires the full path to the '%s' command" % (configfile, lineno, param, short_cmd)) else: stderr("%s:%d: no such command '%s'" % (configfile, lineno, cmd)) return (1, None) return (0, synctool_lib.prepare_path(string.join(arr[1:])))
def _config_dir(param, value, current, configfile, lineno): if current != None: stderr('%s:%d: redefinition of %s' % (configfile, lineno, param)) return (1, current) the_dir = synctool_lib.prepare_path(value) if not os.path.isdir(the_dir): stderr('%s:%d: no such directory for %s' % (configfile, lineno, param)) return (1, the_dir) return (0, the_dir)
def _config_multipath(param, value, multipaths, configfile, lineno): if value in multipaths: stderr('%s:%d: already in %s' % (configfile, lineno, param)) return 1 the_dir = synctool_lib.prepare_path(value) if not os.path.isdir(the_dir): stderr('%s:%d: no such directory for %s' % (configfile, lineno, param)) return 1 multipaths.append(the_dir) return 0
def config_include(arr, configfile, lineno): # recursively read the given config file return read_config_file(synctool_lib.prepare_path(arr[1]))