def getUid(userName): lines = Utils.readFile(Globals.CIFS_USER_FILE, lines=True) for line in lines: tokens = line.strip().split(":") if tokens[1] == userName: return int(tokens[0]) return None
def removeUser(userName): lines = Utils.readFile(Globals.CIFS_USER_FILE, lines=True) try: fp = open(Globals.CIFS_USER_FILE, "w") for line in lines: if not line.strip(): continue ## junli.li remove the line of userName from CIFS_USER_FILE if line.strip().split(":")[1] == userName: continue fp.write("%s" % line) fp.close() except IOError, e: Utils.log("failed to write file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) return False
def getCifsUsers(): try: lines = Utils.readFile(Globals.CIFS_USER_FILE, lines=True) cifsUserDom = XmlHandler.ResponseXml() cifsUserTag = cifsUserDom.appendTagRoute("cifsUsers") for line in lines: if not line.strip(): continue tokens = line.strip().split(":") cifsUserTag.appendChild(cifsUserDom.createTag("cifsUser", tokens[1])) return cifsUserTag.toxml() except Exception,e: code, reval = "25000", "Error when getting cifsusers: " + str(e) result = Utils.errorCode(code, reval, []) raise web.HTTPError(status = "400 Bad Request", data = result)
def getLastUid(): lines = Utils.readFile(Globals.CIFS_USER_FILE, lines=True) if not lines: return Globals.DEFAULT_UID return int([line.strip().split(':')[0] for line in lines if line.strip()][-1])