fabfile.py for Automating Git Repo Creation
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
#!/bin/python3 from fabric.api import * from fabric.contrib import files # Local git managment automation tools # copyright matt birkland, Savelono.com 2017 # License: GPLv2 # # # Set the username env.user = "git" # Set the password [NOT RECOMMENDED] env.password = "" env.hosts = "10.1.10.10" class FabricException(Exception): pass env.abort_exception = FabricException # # newgit pseudo code # ------------ # # - Prompt for name of newcode # - Prompt for install directory # - Test that directory starts with / # - Test for tailing / & remove it # - Display Git Repo build info # - Test to see if project already exsist # - Create git folder and intialize # - Clone to local folder of choice # #------------------------------------------ def newgit(): while True: git_name = input("Please enter name. Example, 'myproject' :") if not git_name: print("You must enter a name. Please try again or quit(ctrl-c).") print() continue else: break print() print() print("Current ~/git/ tree:") print("----------------------------------------------------") local("ls -al ~/git") print("----------------------------------------------------") print() while True: git_dir = input("Please enter folder(default ~/git). Example, '/home/matt/software' :") if not git_dir: git_dir = "~/git" break # check for slash as first character in valid unix directory elif git_dir[:1] != "/" and git_dir[:1] != "~": print("ERROR: {}/{}".format(git_dir,git_name)) print("Please enter valid directory path. Example, '/home/matt/git/somedir' or ~/git/somedir.") continue # check for trailing slash and remove it elif git_dir[-1:] == "/": git_dir = git_dir[:-1] break else: break print("====================================================") print(" Git Server info") print("---------------------------") print("Git Server: {}".format(env.hosts)) print("Git User: {}".format(env.user)) print("Git Project: {}:/git/{}.git".format(env.hosts,git_name)) print() print(" Git Local info") print("---------------------------") print("Git Poject name: {}".format(git_name)) print("Git Directory: {}/{}".format(git_dir,git_name)) print("=====================================================") print() print() while True: this_ok = input("Is this correct? ('yes' or 'no') :") if this_ok == "yes": try: with settings(warn_only=False): check = run("mkdir ~/code/{}.git".format(git_name)) print() print() break except FabricException: print("Git repo already in use! Please run again and select a different name for the git project") print() exit(1) elif this_ok == "no": print("Exiting...") exit() else: print() print("=====================================================") print(" Please Enter 'yes' or 'no'. Lowercase only please. ") print("=====================================================") print() continue # Intialize Git directory try: with settings(warn_only=False): intialize_git = run("git init --bare ~/code/{}.git".format(git_name)) print() print("Remote Git repo configured!") print() print() except FabricException: print("Unknown error") print() exit(1) # Create Project directory try: with settings(warn_only=False): clone_git = local("mkdir {}".format(git_dir)) print() print() except FabricException: print("Directory exist already!") print() # Clone Git repo try: with settings(warn_only=False) and lcd("{}".format(git_dir)): clone_git = local("git clone git@10.1.10.10:/git/{}.git".format(git_name)) print() print("Git repo cloned to {}/{}!".format(git_dir,git_name)) print() exit(1) except FabricException: print("Unknown error") print() exit(1) |