-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpygnore
executable file
·54 lines (48 loc) · 1.77 KB
/
pygnore
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
#!/usr/bin/env python3
from os.path import exists
from os.path import expanduser
from sys import exit
HOME = expanduser("~")
def write_gitignore():
if exists(f"{HOME}/.pygnore"):
with open(".gitignore", "w") as f:
with open(f"{HOME}/.pygnore") as template:
print("Writing gitignore file...")
for line in template:
f.write(line)
else:
raise FileNotFoundError
def write_template():
with open("Python.gitignore", "r") as template:
with open(f"{HOME}/.pygnore", "w") as f:
print("Installing template in home directory...")
for line in template:
f.write(line)
print("Template installed successfully")
from sys import exit
exit()
if __name__ == "__main__":
if exists(".gitignore"):
print("Gitignore file already exists")
proceed = input("Proceed? [y/n] ")
if proceed.lower() not in ("yes", "y", ""):
print("Cya later alligator")
exit()
try:
write_gitignore()
except FileNotFoundError:
# install template in ~/.pygnore
print("Template file not found")
import os
if os.path.basename (os.getcwd()) in ("pygnore", "pygnore-cli"):
print("Initiating repo based installation of the gitignore template")
try:
write_template()
except FileNotFoundError:
print("Error: you are either not in the project repo or the file Python.gitignore has been removed.")
else:
print("Template file not installed -> please cd into the cloned project dir and either do `make install` or `python3 pygnore`")
except:
print("Error occured")
else:
print("Pygnore successful")