def setfacl_posix(path, op, val, connector, config, LOG): unset_posix() setfacl_cmd = config.get('tsi.setfacl', '/bin/false') if "RECURSIVE" in op: recursive = "-R " else: recursive = "" if "RM_ALL" in op: command = "%s -b %s'%s'" % (setfacl_cmd, recursive, path) else: base_arg = "" remove = False if val.startswith("D"): base_arg = "-d " if "MODIFY" in op: base_arg += "-m" elif "RM" in op: base_arg += "-x" remove = True else: connector.failed("WRONG SETFACL SYNTAX") return arg = prepare_posix_arg(val, remove) command = "%s %s %s %s '%s'" % ( setfacl_cmd, recursive, base_arg, arg, path) LOG.debug(command) (success, result) = run_command(command) if not success: connector.failed(result) else: connector.ok()
def getfacl_posix(path, connector, config, LOG): unset_posix() getfacl_cmd = config.get('tsi.getfacl', '/bin/false') command = "%s %s" % (getfacl_cmd, path) LOG.debug(command) (success, result) = run_command(command) if not success: connector.failed(result) else: patterns = ["user", "group", "default:user", "default:group"] connector.ok() for line in result.splitlines(): if True in [line.startswith(p) for p in patterns]: connector.write_message(line)
def df(message, connector, config, LOG): """ determines the free space on a given partition and reports results on stdout in the format that the XNJS expects. The format of the output is as follows: Output starts with the line: START_DF and ends with the line: END_DF The following values are reported (in bytes): - TOTAL: The total space on the partition - FREE: The free space on the partition - USER: The user quota (optional) Every line is terminated by \n """ path = extract_parameter(message, "FILE") path = expand_variables(path) # TODO might want to add a cache or do not check # free space for certain paths command = "df -P -B 1 %s" % path (success, result) = run_command(command) total = free = user = '******' if success: try: for line in result.splitlines(): m = re.match(r"(\S+)\s+(\d+)\s+(\d+)\s+(\d+).+", line) if m is not None: total = m.group(2) free = m.group(4) except: connector.failed("Wrong or unexpected output from 'df' " "command: %s" % result) return connector.write_message("START_DF") connector.write_message("TOTAL %s" % total) connector.write_message("FREE %s" % free) connector.write_message("USER %s" % user) connector.write_message("END_DF") else: connector.failed(result)