-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
executable file
·56 lines (47 loc) · 1.47 KB
/
bootstrap.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import subprocess as sub
import hashlib
import shutil
from six.moves import input
noprompt = '-f' in sys.argv
os.chdir (os.path.dirname (sys.argv[0]))
sub.check_call ('git pull origin master'.split ())
def md5 (filename):
if not os.path.exists (filename):
return ''
m = hashlib.md5 ()
with open (filename, 'rb') as f:
m.update (f.read ())
return m.digest ()
def prompt (msg):
reply = input (msg)
return reply.lower().startswith ('y')
for root, dirs, files in os.walk (os.curdir):
root = root[2:] # strip leading ./
if '.git' in dirs:
dirs.remove ('.git')
for d in dirs:
outdir = os.path.join (os.pardir, root, d)
if not os.path.isdir (outdir):
print('Creating directory %s' % outdir)
os.mkdir (outdir)
for newf in files:
newf = os.path.join (root, newf)
if not newf.startswith ('.'):
#print "Skipping %s" % newf
continue
oldf = os.path.join (os.pardir, newf)
if not os.path.exists (oldf):
print('Installing %s' % oldf)
shutil.copy (newf, oldf)
continue
if md5 (oldf) != md5 (newf):
sub.call (['diff', '-Naur', oldf, newf])
if noprompt or prompt ("\nReplace %s? " % newf):
shutil.copy (newf, oldf)
else:
#print "%s is up to date." % newf
pass