-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignorefile.py
84 lines (75 loc) · 2.91 KB
/
ignorefile.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
from os import listdir
from os.path import isfile, join
#Globally ignored files
globalignore = ['bin', 'lib', 'lib64', 'include', '__pycache__']
#Files which are specifically allowed by a specific ignorefile
specificallow = {'.gitignore': ['.git']}
path = str(input('Enter path for script: '))
if os.path.exists(path):
#Ignorefiles to create with script
ignorefilelist = []
while True:
filename = str(input('Enter filenames (e.g. .dockerignore, .gitignore) one at a time, or enter "D" for done: '))
if filename in ['d', 'D']:
if len(ignorefilelist) == 0:
print('Please enter at least one filename')
else:
break
else:
ignorefilelist.append(filename)
ignorefiles = {}
for f in ignorefilelist:
ignorefiles[f] = open(path + '/' + f, "w")
folderlist = []
filelist = []
for i in specificallow:
globalignore += specificallow[i]
for f in listdir(path):
written = []
if f in globalignore or f in list(ignorefiles.keys()):
for i in ignorefiles:
if f != i and (i not in specificallow or (i in specificallow and f not in specificallow[i])):
ignorefiles[i].write(f + '\n')
written.append(i)
print(f + ' added to ' + ', '.join(written))
else:
if isfile(join(path, f)):
filelist.append(f)
else:
folderlist.append(f)
for f in folderlist + filelist:
written = []
while True:
userchoice = str(input('Should ' + f + ' be added to ' + ', '.join(list(ignorefiles.keys())) + '? (Yes/No/Modify): ')).lower()
if userchoice in ['y', 'yes']:
for i in ignorefiles:
ignorefiles[i].write(f + '\n')
written.append(i)
break
elif userchoice in ['n', 'no']:
break
elif userchoice in ['m', 'modify']:
for i in ignorefiles:
while True:
userchoice = str(input('Should ' + f + ' be added to ' + i + '? (Yes/No): ')).lower()
if userchoice in ['y', 'yes']:
ignorefiles[i].write(f + '\n')
written.append(i)
break
elif userchoice in ['n', 'no']:
break
else:
print("Sorry, I didn't understand that")
continue
break
else:
print("Sorry, I didn't understand that")
continue
if len(written) != 0:
print(f + ' added to ' + ', '.join(written))
for i in ignorefiles:
ignorefiles[i].close()
print('Done!')
else:
print('Path does not exist!')