Mercurial > hg > Applications > docker-wrapper
diff create.py @ 11:5e2df576a42d
add new command 'create' to ie-docker, create is make new repository for ie-docker.
author | taira |
---|---|
date | Mon, 26 Jan 2015 13:20:35 +0900 |
parents | |
children | 1730494d9ecc |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create.py Mon Jan 26 13:20:35 2015 +0900 @@ -0,0 +1,94 @@ +#!/usr/bin/python + +import os, re +import argparse + +base_path = "/media/fcs/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() + + +def check_name(name): + m=re.match('^([ek](\d\d)[58]\d\d\d)$', name) + if m is not None: + if m.group(1)==m.group(2): + return 0 + else: + return 1 + elif re.match('^[-a-z0-9]+',name): + return 0 + else: + return 1 + +# 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) + print(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() + + 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) + +