def check_user_exists(username, state): stored_username = custom_hash(username) file_path = instance_path(state) open(file_path, 'a').close() with open(file_path, 'r+') as file: return re.search( '^{0}'.format(re.escape(stored_username)), file.read(), flags=re.M)
def run_test(): scriptpath = script_path() instancepath = instance_path() if os.path.isfile(instancepath): os.system('rm {0}'.format(instancepath)) os.system('touch {0}'.format(instancepath)) unittest.main() os.system('rm {0}'.format(instancepath))
def getpid(username): file_path = instance_path(state) if not os.path.isfile(file_path): return stored_username = custom_hash(username) with open(file_path) as oldfile: for line in oldfile: if stored_username in line: return line.split(':')[1].strip()
def add_new_user_instance(username): file_path = instance_path(state) if not check_user_exists(username): stored_username = custom_hash(username) with open(file_path, "a+") as instance_file: redacted_list = [username] instance_file = RedactedFile(instance_file, redacted_list) instance_file.write("{0} : {1}\n".format(stored_username, os.getpid())) return True return False
def remove_user_instance(username): file_path = instance_path(state) file = "" if not os.path.isfile(file_path): return stored_username = custom_hash(username) with open(file_path) as oldfile: for line in oldfile: if stored_username not in line: file += line with open(file_path, 'w+') as newfile: redacted_list = [username] newfile = RedactedFile(newfile, redacted_list) newfile.writelines(file)