+from os.path import expanduser
+ opts, args = getopt.getopt(argv, "hug:d", ["help", "user=", "gopath="])
+ except getopt.GetoptError:
+ if opt in ("-h", "--help"):
+ elif opt in ("-u", "--user"):
+ elif opt in ("-g", "--gopath"):
+ bashrc = home + "/.bashrc"
+ zshrc = home + "/.zshrc"
+ os.system("mkdir %s" % home + "/" + gopath)
+ if not userName == "user":
+ os.system("mkdir -p %s" % home + "/src/github.com/" + userName)
+ append_line_to_file("export GOPATH=$gopath", bashrc)
+ append_line_to_file("export GOROOT=/usr/local/opt/go/libexec", bashrc)
+ append_line_to_file("export PATH=$PATH:$GOPATH/bin", bashrc)
+ append_line_to_file("export PATH=$PATH:$GOROOT/bin", bashrc)
+ append_line_to_file("export GOPATH=$gopath", zshrc)
+ append_line_to_file("export GOROOT=/usr/local/opt/go/libexec", zshrc)
+ append_line_to_file("export PATH=$PATH:$GOPATH/bin", zshrc)
+ append_line_to_file("export PATH=$PATH:$GOROOT/bin", zshrc)
+ if (which("brew") == None):
+ installBrew = query_yes_no("Do you want to intstall brew?")
+ success = os.system('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')
+ print "Failed to install brew! Maybe try manual instal?"
+ print "Aborting instalation"
+ os.system('brew update')
+ os.system('brew install go')
+ os.system('brew install git')
+ os.system('brew install mercurial')
+ success = os.system('go get golang.org/x/tools/cmd/godoc | go get golang.org/x/tools/cmd/vet')
+ print "Successfully installed golang"
+ print "Failed to install golang"
+ print "Failed to install golang"
+ print "python golangInstall.py [-u gitUserName] [-g gopath] [-h]"
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+ fpath, fname = os.path.split(program)
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program)
+def query_yes_no(question, default="yes"):
+ """Ask a yes/no question via raw_input() and return their answer.
+ "question" is a string that is presented to the user.
+ "default" is the presumed answer if the user just hits <Enter>.
+ It must be "yes" (the default), "no" or None (meaning
+ an answer is required of the user).
+ The "answer" return value is True for "yes" or False for "no".
+ valid = {"yes": True, "y": True, "ye": True,
+ "no": False, "n": False}
+ raise ValueError("invalid default answer: '%s'" % default)
+ sys.stdout.write(question + prompt)
+ choice = raw_input().lower()
+ if default is not None and choice == '':
+ sys.stdout.write("Please respond with 'yes' or 'no' "
+def append_line_to_file(line, file):
+ with open(file, 'a+') as f:
+ if not any(value == x.rstrip('\r\n') for x in f):
+if __name__ == "__main__":