-
Notifications
You must be signed in to change notification settings - Fork 3
/
handle_ignore.py
52 lines (44 loc) · 1.54 KB
/
handle_ignore.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
import os
import sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option('--project', '-p', type= str,default='b',help='project flag, (b)ackend or (f)rontend')
def main():
options,args = parser.parse_args()
print("options: ", options)
print("args: ", args)
prefix_dir = './'
file = '.gitignore'
if not os.path.exists(prefix_dir + file):
print(".gitignore file doesn't exists.")
quit()
with open(prefix_dir + file,'r') as f:
items = f.read().split('\n')
for i in range(len(items)):
item = items[i]
p = ''
if len(item) == 0 or item.startswith('#'):
continue
if item.startswith('!'):
item = item[1:]
p = '!'
if options.project == 'b':
if item.startswith('Backend') continue
if item.startswith('/'):
item = 'Backend' + item
else:
item = 'Backend/' + item
elif project == 'f':
if item.startswith('Frontend') continue
if item.startswith('/'):
item = 'Frontend' + item
else:
item = 'Frontend/' + item
items[i] = p + item
with open(prefix_dir + file, 'w') as f:
print("Writing to new .gitignore :")
for item in items:
f.write(item + '\n')
print(item)
if __name__ == '__main__':
main()