コード例 #1
0
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)
コード例 #2
0
ファイル: tests.py プロジェクト: mcsdevv/GN-Core
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))
コード例 #3
0
ファイル: terminategn.py プロジェクト: ymoskovits/GN-Core
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()
コード例 #4
0
ファイル: grade_notifier.py プロジェクト: ymoskovits/GN-Core
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
コード例 #5
0
ファイル: grade_notifier.py プロジェクト: ymoskovits/GN-Core
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)