diff --git a/.my_commands.sh b/.my_commands.sh index a99f9c2..88c91b3 100644 --- a/.my_commands.sh +++ b/.my_commands.sh @@ -3,12 +3,22 @@ function create() { cd python create.py $1 - cd /Users/kalle/Documents/Projects/MyProjects/$1 + cd ~/Documents/Projects/MyProjects/$1 git init - git remote add origin git@github.com:KalleHallden/$1.git + git remote add origin git@github.com:$2/$1.git touch README.md git add . git commit -m "Initial commit" git push -u origin master code . -} \ No newline at end of file +} + +function remove() { + cd ~/Documents/Projects/MyProjects + read -p "Are you sure?[y/n]" confirm + if [ "$confirm" = "n" ] || [ "$confirm" = "N" ]; then + return + fi + rm -rf $1 + python remove.py $1 +} diff --git a/README.md b/README.md index dad267e..86e1bfd 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,12 @@ git clone "https://github.com/KalleHallden/ProjectInitializationAutomation.git" cd ProjectInitializationAutomation pip install -r requirements.txt source ~/.my_commands.sh -Then go to create.py and set the username and password to be your username and password. -Also make sure to change all directories to your directories so it should be '/Users//path/to/your/project' + +# if you're using linux, you can add source ~/.my_commands.sh to your ~/.bashrc, so you dont have to type that every time you open the terminal ``` ### Usage: ```bash -To run the script type in 'create ' +To create project type in 'create ' +To remove project type in 'remove ' ``` diff --git a/create.py b/create.py index e459fb9..beb6ab4 100644 --- a/create.py +++ b/create.py @@ -1,16 +1,25 @@ import sys import os +import getpass from github import Github -path = "/Users/kalle/Documents/Projects/MyProjects/" - -username = "" #Insert your github username here -password = "" #Insert your github password here +path = "~/Documents/Projects/MyProjects/" def create(): folderName = str(sys.argv[1]) - os.makedirs(path + str(folderName) - user = Github(username, password).get_user() + os.makedirs(path + str(folderName)) + isLogedIn = False + + while not isLogedIn: + username = raw_input("Username for 'www.github.com': ") + password = getpass.getpass("Password for '" + username + "@github.com': ") + user = Github(username, password).get_user() + try: + user.login + isLoggedIn = True + except: + print("Credentials are wrong.") + repo = user.create_repo(folderName) print("Succesfully created repository {}".format(folderName)) diff --git a/remove.py b/remove.py index 6780127..fede490 100644 --- a/remove.py +++ b/remove.py @@ -1,26 +1,19 @@ import sys -from selenium import webdriver - -username = sys.argv[1] -password = sys.argv[2] -reponame = sys.argv[3] - -browser = webdriver.Chrome() -browser.get('http://github.com/login') +import getpass +from github import Github +reponame = sys.argv[1] def remove(): - browser.find_elements_by_xpath("//input[@name='login']")[0].send_keys(username) - browser.find_elements_by_xpath("//input[@name='password']")[0].send_keys(password) - browser.find_elements_by_xpath("//input[@name='commit']")[0].click() - browser.get('https://github.com/silv4b/' + reponame + '/settings') - browser.find_elements_by_xpath('//*[@id="options_bucket"]/div[9]/ul/li[4]/details/summary')[0].click() - browser.find_elements_by_xpath( - '//*[@id="options_bucket"]/div[9]/ul/li[4]/details/details-dialog/div[3]/form/p/input')[0].send_keys(reponame) - browser.find_elements_by_xpath( - '//*[@id="options_bucket"]/div[9]/ul/li[4]/details/details-dialog/div[3]/form/button')[0].click() - browser.get("https://github.com/" + username) - + username = raw_input("Username for 'www.github.com': ") + password = getpass.getpass("Password for '" + username + "@github.com': ") + user = Github(username, password) + try: + repo = user.get_repo(username + "/" + reponame) + repo.delete() + print("Repository deleted.") + except: + print("No repo found!") if __name__ == "__main__": remove()