-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.py
More file actions
executable file
·42 lines (34 loc) · 1.32 KB
/
migrate.py
File metadata and controls
executable file
·42 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
# This script migrates the files from a git checkout into the home directory.
# It assumes that it is being run from the git top-level checkout directory.
import os
import sys
GITCONFIG_TEMPLATE = """
[user]
name = {name}
email = {email}
"""
# Abort if current directory doesn't look like a git repo.
if not os.path.exists("./.git"):
raise Exception("not running in git checkout")
# Copy files from checkout into home directory.
target = os.path.expanduser("~")
os.rename("./.git", os.path.join(target, ".config.git"))
for entry in os.listdir("."):
if entry == os.path.basename(sys.argv[0]):
continue
os.rename(os.path.join(".", entry), os.path.join(target, entry))
# Since we're presumably commissioning a new system, this is a good point
# to remind the user to configure their git name and email.
if not os.path.exists(os.path.join(target, ".gitconfig")):
print "No .gitconfig - enter name and email (or ^C to skip)"
try:
name = email = ""
while not name:
name = raw_input("Name: ")
while not email:
email = raw_input("Email: ")
with open(os.path.join(target, ".gitconfig"), "w") as fd:
fd.write(GITCONFIG_TEMPLATE.format(name=name, email=email))
except KeyboardInterrupt:
print "Creation of .gitconfig skipped"