Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess
- import sys
- import os.path
- import shutil
- def menu(*options, preamble=None, prompt="Select option: "):
- NUMBERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- if len(options) > len(NUMBERS):
- raise ValueError("Too many options!")
- while True:
- if preamble is not None:
- print(preamble)
- for i, opt in enumerate(options):
- print(" {}. {}".format(NUMBERS[i], opt))
- n = input(prompt).upper()
- try:
- i = NUMBERS.index(n)
- return options[i]
- except (ValueError, IndexError):
- print("Please select a valid option")
- def git_init(dirname, *, bare=False):
- if not os.path.exists(dirname):
- os.mkdir(dirname)
- subprocess.check_call(['git', 'init', ('--bare' if bare else '')], cwd=dirname)
- def git_init_from_other(newdir, olddir):
- shutil.copytree(olddir, newdir)
- def templates():
- return os.listdir('templates')
- if __name__ == '__main__':
- if len(sys.argv) > 2:
- sys.exit("Too many args!")
- elif len(sys.argv) == 2:
- target = sys.argv[1]
- else:
- target = input("New repo name? ")
- if os.path.exists(target):
- sys.exit("Repository already exists")
- tpls = templates()
- tpl = menu(None, *tpls, preamble="Select a template:")
- if tpl is None:
- git_init(target, bare=True)
- else:
- git_init_from_other(target, os.path.join('templates', tpl))
- print("Remote URL: storage:code/{}".format(target))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement