Mercurial > hg > Applications > ie-cloud
view create.py @ 0:61bc8410d480
add files
author | taiki |
---|---|
date | Wed, 11 Feb 2015 20:23:09 +0900 |
parents | |
children | 6ebce132ee89 |
line wrap: on
line source
#!/usr/bin/python import os, re import argparse import portops base_path = "/home/k138582/docker-hg/" def ie_mkdir(projectname): username = os.getlogin() m = re.match('^([ek]\d\d[58]\d\d\d)$', username) if m is not None: dir = base_path + "students/" + username[:3] + os.sep + username mkdir1(dir) os.system("/bin/chown "+os.getlogin()+" "+ dir) if (len(os.listdir(dir)) > 4): print("[!] Too many project.") exit() dir = dir + os.sep + projectname mkdir1(dir) os.system("/bin/chown " + os.getlogin() + " " + dir) return dir print("[!] Permission denied. You are not permitted user.") exit() # make necessary sub directory # /etc/libvirt/qemu/teachers # /var/log/libvirt/qemu/teachers # /var/run/libvirt/qemu/teachers def mkdir1(name): if not os.path.exists(name): os.makedirs(name); def change_own(base_path): if not os.path.isdir(base_path): os.system("/bin/chown " + os.getlogin() + " " + base_path) return for f in os.listdir(base_path): path = os.path.join(base_path, f) os.system("/bin/chown " + os.getlogin() + " " + path) if os.path.isdir(path): change_own(path) def make_hgrepo(projpath): os.chdir(projpath) os.system("hg init") dockerfile = "Dockerfile" fd = open(dockerfile, "w") fd.write("# Using ie-docker, you sould edit this file\n") fd.write("FROM fedora\n") fd.close() os.system("hg add " + dockerfile) os.system("hg commit -u " + os.getlogin() + " -m systemcommit") change_own(os.getcwd()) # # main method # if __name__ == "__main__": parser = argparse.ArgumentParser(description='Create new project for ie-docker.') parser.add_argument('projectname', metavar='project name', help='ie-docker project name') args = parser.parse_args() if not portops.reserve_port(os.getlogin(), args.projectname): print("[!] Can't get port to use for project.") print("[!] Check your number of projects.") sys.exit() projpath = ie_mkdir(args.projectname) make_hgrepo(projpath) print("Create your project on " + projpath) print("Exec on your client : hg clone ssh://your_account@" + os.uname()[1] + os.sep + projpath) # end