示例#1
0
def remove(username):

    from ixtlilton_tools.admin.directory.user.home.local.lib import exists as lib_exists
    from ixtlilton_tools.admin.directory.user.home.local.lib import is_empty as lib_is_empty

    path = pathlib.Path('/home/'+username+'/local/lib')

    if not lib_exists(username):
        raise DirectoryConflict('The lib directory of user {username} does not exists')
    else:
        if not lib_is_empty(username):
            raise DirectoryConflict('The lib directory of user {username} is not empty')
        else:
            shutil.rmtree(path)

    pass
示例#2
0
def exists(username):

    path = pathlib.Path('/home/'+username+'/local/opt/apps')

    if path.exists() and not path.is_dir():
        raise DirectoryConflict(f'The apps directory of user {username} exists but is not a directory')

    return path.exists()
示例#3
0
def remove(username):

    from ixtlilton_tools.admin.directory.user.scratch import exists as scratch_exists
    from ixtlilton_tools.admin.directory.user.scratch import is_empty as scratch_is_empty

    path = '/scratch/' + username

    if not scratch_exists(username):
        raise DirectoryConflict(
            'The scratch directory of user {username} does not exists')
    else:
        if not scratch_is_empty(username):
            raise DirectoryConflict(
                'The scratch directory of user {username} is not empty')
        else:
            shutil.rmtree(path)

    pass
示例#4
0
def remove(username):

    from ixtlilton_tools.admin.directory.user.work import exists as work_exists
    from ixtlilton_tools.admin.directory.user.work import is_empty as work_is_empty

    path = '/work/' + username

    if not work_exists(username):
        raise DirectoryConflict(
            'The work directory of user {username} does not exists')
    else:
        if not work_is_empty(username):
            raise DirectoryConflict(
                'The work directory of user {username} is not empty')
        else:
            shutil.rmtree(path)

    pass
示例#5
0
def exists(username):

    path = pathlib.Path('/home/'+username+'/local')
    path_source = pathlib.Path('/home/'+username+'/.local')

    if path_source.exists() and not path.is_symlink():
        raise DirectoryConflict(f'The local directory of user {username} exists but is not a directory')

    return path.exists()
示例#6
0
def exists(username):

    path = pathlib.Path('/work/' + username)

    if path.exists() and not path.is_dir():
        raise DirectoryConflict(
            f'The work directory of user {username} exists but is not a directory'
        )

    return path.exists()
示例#7
0
def remove(username):

    from ixtlilton_tools.admin.directory.user.home.local import exists as local_exists
    from ixtlilton_tools.admin.directory.user.home.local import is_empty as local_is_empty

    path = pathlib.Path('/home/' + username + '/local')
    aux_path = pathlib.Path('/home/' + username + '/.local')

    if not local_exists(username):
        raise DirectoryConflict(
            'The local directory of user {username} does not exists')
    else:
        if not local_is_empty(username):
            raise DirectoryConflict(
                'The local directory of user {username} is not empty')
        else:
            os.unlink(path)
            shutil.rmtree(aux_path)

    pass
示例#8
0
def is_empty(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.home.local.src import exists as src_exists
    from ixtlilton_tools.admin.directory.user.home.local.src import is_empty as src_is_empty

    output = False

    if not src_exists(username):
        raise DirectoryConflict('The src directory of user {username} does not exists')
    else:
        path = pathlib.Path('/home/'+username+'/local/src')
        if set(initial_content)==set(os.listdir(path)):
            output = True

    return output
示例#9
0
def is_empty(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.scratch import exists as scratch_exists
    from ixtlilton_tools.admin.directory.user.scratch import is_empty as scratch_is_empty

    output = False

    if not scratch_exists(username):
        raise DirectoryConflict('The scratch directory of user {username} does not exists')
    else:
        path = pathlib.Path('/scratch/'+username)
        if set(initial_content)==set(os.listdir(path)):
            output = True

    return output
示例#10
0
def fix_owner(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.home.local.opt.apps import exists as apps_exists
    from ixtlilton_tools.admin.directory.user.home.local.opt.apps import fix_owner as fix_apps_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/home/'+username+'/local/opt/apps')

    if not apps_exists(username):
        raise DirectoryConflict('The apps directory of user {username} does not exists')
    else:
        owner = path.owner()
        group = path.group()
        if owner!=username or group!=username:
            subprocess.run(['chown', '-R', f'{username}:{username}', str(path)])

    pass
示例#11
0
def fix_owner(username):

    from ixtlilton_tools.admin.user import exists as user_exists
    from ixtlilton_tools.admin.directory.user.scratch import exists as scratch_exists
    from ixtlilton_tools.admin.directory.user.scratch import fix_owner as fix_scratch_owner

    if not user_exists(username):
        raise UserDoesNotExist(username=username)

    path = pathlib.Path('/scratch/' + username)

    if not scratch_exists(username):
        raise DirectoryConflict(
            'The scratch directory of user {username} does not exists')
    else:
        owner = path.owner()
        group = path.group()
        if owner != username or group != username:
            subprocess.run(
                ['chown', '-R', f'{username}:{username}',
                 str(path)])

    pass