Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 56 lines (42 sloc) 1.66 KB
#!/usr/bin/env python3
"""Creates a symlink to the current user's web directory in their home folder.
The symlink is called "public_html" by default and points to
"/services/http/users/<first letter of username>/<username>". This script is
idempotent: if the symlink exists and points to the correct path, makehttp
takes no action; otherwise, it creates the symlink after removing broken
symlinks or renaming any file or directory with the same path.
import datetime
import os.path
from argparse import ArgumentParser
from ocflib.account.utils import home_dir
from ocflib.account.utils import web_dir
from ocflib.misc.whoami import current_user
def rectify_link(path, webdir):
if os.path.islink(path):
if os.readlink(path) == webdir:
# Do nothing if link is correct
print('public_html already points to web directory')
elif not os.path.exists(path):
# Delete any broken link
print('Removing broken symlink')
if os.path.exists(path):
ext ='%s')
print('{} is an existing file, folder, or symlink'.format(path))
print('Renaming to {}.{}'.format(path, ext))
os.rename(path, path + '.' + ext)
print('Creating symlink to web directory')
os.symlink(webdir, path)
os.chmod(path, 0o755)
def main():
parser = ArgumentParser(description=__doc__)
user = current_user()
path = home_dir(user) + '/public_html'
webdir = web_dir(user)
rectify_link(path, webdir)
print('Your public_html directory is ready to use!')
if __name__ == '__main__':
You can’t perform that action at this time.