project_permissions.py (AEN 4.1.1) — Anaconda Enterprise 4.4 documentation

Anaconda Enterprise: Documentation

# project_permissions.py (AEN 4.1.1)

    #!/usr/bin/env python

    import argparse
    import os
    import pwd
    from os.path import join
    import subprocess

    def parser():
        p = argparse.ArgumentParser()
        p.add_argument("project_directory")
        return p

    def run(project_directory):
        #this will be something like /projects/<username>
        project_dirs = os.listdir(project_directory)
        for dirname in project_dirs:
            print dirname
            path = join(project_directory, dirname)
            owner = pwd.getpwuid(os.stat(path).st_uid).pw_name
            subprocess.check_output(['chown', '-R', '%s:%s' % (owner, owner), path])
            subprocess.check_output(['chmod', '-R', 'g-s', path])
    subprocess.check_output(['chown', '-R', 'wakari:wakari', '/opt/wakari/anaconda'])
    subprocess.check_output(['chmod', '-R', 'a+r', '/opt/wakari/anaconda'])
    subprocess.check_output(['chmod', '-R', 'o-w', '/opt/wakari/anaconda'])

    if __name__ == "__main__":
        p = parser()
        args = p.parse_args()
        run(args.project_directory)