aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2014-05-08 01:55:24 +0200
committerVictor Häggqvist <[email protected]>2014-05-08 01:55:24 +0200
commitfbc5b766242ed438800af5637f8eb1e892fc3cc3 (patch)
tree222d03e2229f31b65c75f3726163995436061df5
init
-rw-r--r--giti.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/giti.py b/giti.py
new file mode 100644
index 0000000..b1c1422
--- /dev/null
+++ b/giti.py
@@ -0,0 +1,68 @@
+# coding=utf-8
+import os
+import sys
+import urllib2
+
+__author__ = 'Victor Häggqvist'
+__version__ = 0.1
+
+
+def gitiglobal(type):
+ """
+ Fetch gitignore from the global directory
+ """
+ print "Fetching .gitignore for", type,"in Global"
+ try:
+ gifile = urllib2.urlopen("https://raw.githubusercontent.com/github/gitignore/master/Global/"+type+".gitignore").read()
+ store(gifile)
+ except:
+ print "Not found in global either"
+
+
+def store(file):
+ """
+ Store content in file
+ """
+ print "storing"
+ if os.path.isfile(".gitignore") == True:
+ try:
+ merge = input("Do you want to merge with existing .gitignore [Y/n]:")
+ except:
+ merge = "y"
+ existingFile = open(".gitignore").read()
+ else:
+ merge = "y"
+ existingFile = ""
+
+ if merge.lower() == "y":
+ gitignore = existingFile + file
+ f = open('.gitignore', 'w')
+ f.write(gitignore)
+ print ".gitignore baked :)"
+ else:
+ print "Did nothing your .gitignore lives like before"
+
+
+
+def giti(type):
+ """
+ Fetch gitignore from directory
+ """
+ type = type[0].upper() + type[1:] # make first upper
+ print "Fetching .gitignore for", type
+
+ try:
+ gifile = urllib2.urlopen("https://raw.githubusercontent.com/github/gitignore/master/"+type+".gitignore").read()
+ store(gifile)
+ except:
+ print "not found in master"
+ gitiglobal(type)
+
+
+def main():
+ if len(sys.argv) == 2:
+ giti(sys.argv[1])
+ else:
+ print "Usage giti [language or stuff]"
+
+main()