From 69e51c8684831ff7942aef863d398b76340eda04 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 02:33:01 -0400 Subject: [PATCH 01/25] Initial forked commit --- test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test diff --git a/test b/test new file mode 100644 index 0000000..f457f4b --- /dev/null +++ b/test @@ -0,0 +1 @@ +"testing this works, first time" From a66337a124d4ea6086bfdeaa1040e399103452d0 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 02:50:12 -0400 Subject: [PATCH 02/25] Initial forked, things are ok --- windows_OS/choose.py | 57 +++++++++++++++++++++++++++++++++++ windows_OS/create.bat | 40 +++++++++++++++--------- windows_OS/create_working.txt | 32 ++++++++++++++++++++ windows_OS/remote.py | 53 +++++++++++++++++++++++--------- 4 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 windows_OS/choose.py create mode 100644 windows_OS/create_working.txt diff --git a/windows_OS/choose.py b/windows_OS/choose.py new file mode 100644 index 0000000..e4dd94d --- /dev/null +++ b/windows_OS/choose.py @@ -0,0 +1,57 @@ +import os +import sys + +def choose(): + print(f"sys.argv --> {str(sys.argv)}") + + args = {} + try: + args["name"] = str(sys.argv[1]) + except IndexError: + print("Index error, need name. Showing usage") + + for i in range(1, len(sys.argv)): + + # Test for -h or --help + if str(sys.argv[i]) == "-h" or str(sys.argv[i]) == "--help" or str(sys.argv[i]) == "help()": + if len(sys.argv) != 3: + help_usage() + sys.exit() + + print("Print either general usage or usage for next arg, exiting this program") + + # Test for -l or --local + if str(sys.argv[i]) == "-l" or str(sys.argv[i]) == "--local": + print("testing if only a name is included") + if len(sys.argv) != 3: + print("you didn't include a name, showing usage and exiting") + print("Running local, exiting this program") + + # Test for -d or --description + if str(sys.argv[i]) == "-d" or str(sys.argv[i]) == "--description": + print(f"Adding your description: {str(sys.argv[i+1])}") + + # Test for -p or --private + if str(sys.argv[i]) == "-p" or str(sys.argv[i]) == "--private": + print("Setting repo to private and continuing") + + +def help_usage(): + print("Syntax is incorrect.") + print("Usage:") + print(" create -h") + print(" create --help") + print(" create help()") + print() + print(" create [option] -h") + print(" create [option] --help") + print(" create [option] help()") + print() + print("Description:") + print(" Explains usage of the \"create\" command and its options") + + + + +if __name__ == "__main__": + choose() \ No newline at end of file diff --git a/windows_OS/create.bat b/windows_OS/create.bat index 8e3e0d0..7c7d5a7 100644 --- a/windows_OS/create.bat +++ b/windows_OS/create.bat @@ -1,17 +1,29 @@ @echo off - -set fn=%1 -set flag=%2 cd /d %~dp0 +setlocal + +rem pyParams variable to contain python script's parameters +rem Helper flag for parameter presence. default to 0/FALSE. +set prmOk=0 + +rem Variable to contain python script name to use. default is remote. +set pyName=choose + +rem Process batch parameters +:getParam + +set pyParams=%pyParams% %1 +set prmOk=1 + +shift +rem After SHIFT, %0 is replaced by %1, %1 replaced by %2, %2 replaced by %3, etc. +if "%~1" neq "" goto getParam + +rem Check python script's parameter presence +if %prmOk% == 0 ( + echo Batch parameter is missing. + goto :eof +) -If "%1"=="" ( - echo "error" -) else ( - if "%2"=="" ( - python remote.py %fn% %flag% - ) else ( - if "%2"=="l" ( - python local.py %fn% - ) - ) - ) +python %pyName%.py%pyParams% +:eof \ No newline at end of file diff --git a/windows_OS/create_working.txt b/windows_OS/create_working.txt new file mode 100644 index 0000000..4cc28e2 --- /dev/null +++ b/windows_OS/create_working.txt @@ -0,0 +1,32 @@ +@echo off +setlocal + +rem Variable to contain python script's parameters +REM set pyParams +rem Helper flag for parameter presence. default to 0/FALSE. +set prmOk=0 + +rem Variable to contain python script name to use. default is remote. +set pyName=remote + +rem Process batch parameters +:getParam +if "%~1" == "-l" ( + set pyName=local +) else if "%~1" == "--local" ( + set pyName=local +) else ( + set pyParams=%pyParams% %1 + set prmOk=1 +) +shift +rem After SHIFT, %0 is replaced by %1, %1 replaced by %2, %2 replaced by %3, etc. +if "%~1" neq "" goto getParam + +rem Check python script's parameter presence +if %prmOk% == 0 ( + echo Batch parameter is missing. + goto :eof +) + +echo python %pyName%.py%pyParams% \ No newline at end of file diff --git a/windows_OS/remote.py b/windows_OS/remote.py index e842a0f..634b6fc 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -2,32 +2,55 @@ import os from github import Github -foldername = str(sys.argv[1]) -path = os.environ.get('mp') # add projects dirctory to the env vars -token = os.environ.get('gt') # add github token to the env vars -_dir = path + '/' + foldername + +if len(sys.argv) < 2 or len(sys.argv) > 3: + print("Invalid syntax.\n") + + print("Usage:") + print(" create [options]\n") + + print("Commands:") + print(" create\t\t\t\tCreate a repository.") + print(" remove\t\t\t\tRemove a repository.") + print() + print("Optional Parameters:") + print(" -h, --help") + print(" -d, --description\t\t\t\tAdd a description to the remote repository.") + print(" -") + sys.exit(1) + +repo_name = str(sys.argv[1]) + +try: + repo_description = str(sys.argv[2]) +except IndexError: + print("No description will be included") + repo_description = "" +sys.exit(0) +path = "Be sure to add a path" +_dir = path + '\\' + repo_name + +token = "Be sure to add a token" g = Github(token) user = g.get_user() login = user.login -repo = user.create_repo(foldername) +repo = user.create_repo(name=repo_name, description=repo_description) + +os.mkdir(_dir) +os.chdir(_dir) commands = [f'echo "# {repo.name}" >> README.md', 'git init', - f'git remote add origin https://github.com/{login}/{foldername}.git', + f'git remote add origin https://github.com/{login}/{repo.name}.git', 'git add .', 'git commit -m "Initial commit"', 'git push -u origin master'] -if sys.argv[2] == "g": - os.mkdir(_dir) - os.chdir(_dir) - for c in commands: - os.system(c) - print(f'{foldername} created locally') - os.system('code .') +for c in commands: + os.system(c) -else: - print("create ") +print(f'Repository "{repo_name}" created locally') +os.system('code .') \ No newline at end of file From 148b79a9d4aa88bcc6bf0238a52953a81f174340 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 02:58:22 -0400 Subject: [PATCH 03/25] Delete test dumb thing that I deleted --- test | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test diff --git a/test b/test deleted file mode 100644 index f457f4b..0000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -"testing this works, first time" From 65ac3c96c3695f3e0de6a6972205b8b71e7eaa21 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 02:59:16 -0400 Subject: [PATCH 04/25] deleted test and add updatelog.txt --- test | 1 - windows_OS/updatelog.txt | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) delete mode 100644 test create mode 100644 windows_OS/updatelog.txt diff --git a/test b/test deleted file mode 100644 index f457f4b..0000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -"testing this works, first time" diff --git a/windows_OS/updatelog.txt b/windows_OS/updatelog.txt new file mode 100644 index 0000000..68283a9 --- /dev/null +++ b/windows_OS/updatelog.txt @@ -0,0 +1,10 @@ +Ok, basically I thought the .env file was stupid if you +could easily just write in the token and path. +I'm also adding new functionalities that will +take in parameters like a description or having +the choice for it to be private and whatnot. +Also trying to make things more simple, and +adding the option to have repo names with spaces in it +/ user comfortability. Also, I'm new to pull requests, +if you couldn't already tell by this crappy txt. +Ok thx, bye \ No newline at end of file From a2d2c3c4025a551f0a1fe8d0ca7a0520c6671c01 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 10:31:35 -0400 Subject: [PATCH 05/25] Fixed issue in reading duplicate file 1/2 --- windows_OS/choose.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/windows_OS/choose.py b/windows_OS/choose.py index e4dd94d..d7a2d8e 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -7,6 +7,7 @@ def choose(): args = {} try: args["name"] = str(sys.argv[1]) + print("Name is set.") except IndexError: print("Index error, need name. Showing usage") @@ -34,7 +35,29 @@ def choose(): # Test for -p or --private if str(sys.argv[i]) == "-p" or str(sys.argv[i]) == "--private": print("Setting repo to private and continuing") + + # Test for -y or --yes + if str(sys.argv[i]) == "-y" or str(sys.argv[i]) == "--yes": + print("Will initialize repo automatically, without confirmation message.") + + print("Done") + +def general_usage(): + print("Usage:") + print(" create [options]\n") + + print("Commands:") + print(" create\t\t\t\tCreate a repository.") + print(" remove\t\t\t\tRemove a repository.") + print() + print("Optional Parameters:") + print(" -h, --help") + print(" -d, --description\t\t\t\tAdd a description to the remote repository.") + print(" -p, --private\t\t\t\tSet remote repository to private.") + print(" -l, --local\t\t\t\tCreate a local repository; does not push to Github.") + print("\t\t\t\t\tUse only a repository name and this parameter") + print(" -y, --yes\t\t\t\tAutomatically initialize repository without confirmation message.") def help_usage(): print("Syntax is incorrect.") From c093a382846796f43def15d069d118ca5bba13de Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 10:31:35 -0400 Subject: [PATCH 06/25] Fixed issue in reading duplicate file --- windows_OS/choose.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/windows_OS/choose.py b/windows_OS/choose.py index e4dd94d..d7a2d8e 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -7,6 +7,7 @@ def choose(): args = {} try: args["name"] = str(sys.argv[1]) + print("Name is set.") except IndexError: print("Index error, need name. Showing usage") @@ -34,7 +35,29 @@ def choose(): # Test for -p or --private if str(sys.argv[i]) == "-p" or str(sys.argv[i]) == "--private": print("Setting repo to private and continuing") + + # Test for -y or --yes + if str(sys.argv[i]) == "-y" or str(sys.argv[i]) == "--yes": + print("Will initialize repo automatically, without confirmation message.") + + print("Done") + +def general_usage(): + print("Usage:") + print(" create [options]\n") + + print("Commands:") + print(" create\t\t\t\tCreate a repository.") + print(" remove\t\t\t\tRemove a repository.") + print() + print("Optional Parameters:") + print(" -h, --help") + print(" -d, --description\t\t\t\tAdd a description to the remote repository.") + print(" -p, --private\t\t\t\tSet remote repository to private.") + print(" -l, --local\t\t\t\tCreate a local repository; does not push to Github.") + print("\t\t\t\t\tUse only a repository name and this parameter") + print(" -y, --yes\t\t\t\tAutomatically initialize repository without confirmation message.") def help_usage(): print("Syntax is incorrect.") From 0fcb01405ceb0936d2cd4738f4cd75b3db50a3d6 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 11:31:18 -0400 Subject: [PATCH 07/25] Added params dict to make param testing easier Adding params variable will also make it simpler to add more arguments when the time comes. In this commit, also supplied paths for different uses of such parameters --- windows_OS/choose.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/windows_OS/choose.py b/windows_OS/choose.py index d7a2d8e..2170564 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -7,40 +7,54 @@ def choose(): args = {} try: args["name"] = str(sys.argv[1]) - print("Name is set.") except IndexError: print("Index error, need name. Showing usage") + general_usage() + params = { + "help" : ["-h", "--help", "help()"], + "description" : ["-d", "--description"], + "private" : ["-p", "--private"], + "local" : ["-l", "--local"], + "auto_confirm" : ["-y", "--yes"] + } for i in range(1, len(sys.argv)): # Test for -h or --help - if str(sys.argv[i]) == "-h" or str(sys.argv[i]) == "--help" or str(sys.argv[i]) == "help()": - if len(sys.argv) != 3: + if str(sys.argv[i]) in params["help"]: + if len(sys.argv) == 2: # "create -h" prints general usage + general_usage() + elif len(sys.argv) > 3: # "create -d -p -h" user doesn't know how to use -h properly help_usage() - sys.exit() - - print("Print either general usage or usage for next arg, exiting this program") + else: # "create --description --help" proper use for option parameter + print("Show optional usage") + + # try: + # # test for regular syntax --> create [option] --help + + # except: + # # test for reversed syntax --> create --help [option] + + sys.exit(0) # Test for -l or --local - if str(sys.argv[i]) == "-l" or str(sys.argv[i]) == "--local": + if str(sys.argv[i]) in params["local"]: print("testing if only a name is included") if len(sys.argv) != 3: print("you didn't include a name, showing usage and exiting") print("Running local, exiting this program") # Test for -d or --description - if str(sys.argv[i]) == "-d" or str(sys.argv[i]) == "--description": + if str(sys.argv[i]) in params["description"]: print(f"Adding your description: {str(sys.argv[i+1])}") # Test for -p or --private - if str(sys.argv[i]) == "-p" or str(sys.argv[i]) == "--private": + if str(sys.argv[i]) in params["private"]: print("Setting repo to private and continuing") # Test for -y or --yes - if str(sys.argv[i]) == "-y" or str(sys.argv[i]) == "--yes": + if str(sys.argv[i]) in params["auto_confirm"]: print("Will initialize repo automatically, without confirmation message.") - - print("Done") def general_usage(): @@ -52,7 +66,7 @@ def general_usage(): print(" remove\t\t\t\tRemove a repository.") print() print("Optional Parameters:") - print(" -h, --help") + print(" -h, --help\t\t\t\tPrints general usage or usage of a specific option.") print(" -d, --description\t\t\t\tAdd a description to the remote repository.") print(" -p, --private\t\t\t\tSet remote repository to private.") print(" -l, --local\t\t\t\tCreate a local repository; does not push to Github.") From 71567ec48204869f412d78afeec08a5313812838 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 13:40:16 -0400 Subject: [PATCH 08/25] Added logic for help parameter usage Next should be usage for the other parameters --- windows_OS/choose.py | 56 +++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/windows_OS/choose.py b/windows_OS/choose.py index 2170564..f644009 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -12,28 +12,43 @@ def choose(): general_usage() params = { - "help" : ["-h", "--help", "help()"], - "description" : ["-d", "--description"], - "private" : ["-p", "--private"], - "local" : ["-l", "--local"], - "auto_confirm" : ["-y", "--yes"] + "help" : ["-h", "--help", "help()"], + "description" : ["-d", "--description"], + "private" : ["-p", "--private"], + "local" : ["-l", "--local"], + "auto_confirm" : ["-y", "--yes"] } + for i in range(1, len(sys.argv)): # Test for -h or --help if str(sys.argv[i]) in params["help"]: - if len(sys.argv) == 2: # "create -h" prints general usage + + if len(sys.argv) == 2: # "create -h" prints general usage general_usage() - elif len(sys.argv) > 3: # "create -d -p -h" user doesn't know how to use -h properly + + elif len(sys.argv) > 3: # "create -d -p -h" user doesn't know how to use -h properly help_usage() - else: # "create --description --help" proper use for option parameter - print("Show optional usage") - - # try: - # # test for regular syntax --> create [option] --help - # except: - # # test for reversed syntax --> create --help [option] + else: # "create --description --help" proper use for option parameter + print("Showing optional usage:\n\n") + op_param = str(sys.argv[len(sys.argv) - i]) # len(sys.argv) is 3, checking non help or create param + + if op_param in params["description"]: + print("Showing description usage") + + elif op_param in params["private"]: + print("Showing private usage") + + elif op_param in params["local"]: + print("Showing local usage") + + elif op_param in params["auto_confirm"]: + print("Showing auto confirm usage") + + else: + print("That option is not recognized") + sys.exit(1) sys.exit(0) @@ -43,6 +58,7 @@ def choose(): if len(sys.argv) != 3: print("you didn't include a name, showing usage and exiting") print("Running local, exiting this program") + # TODO Can't exit here, case "create --local help()" # Test for -d or --description if str(sys.argv[i]) in params["description"]: @@ -86,6 +102,18 @@ def help_usage(): print() print("Description:") print(" Explains usage of the \"create\" command and its options") + +def description_usage(): + pass + +def private_usage(): + pass + +def local_usage(): + pass + +def auto_confirm_usage(): + pass From 5c39b6c9d586fcd4457abecda3edf8f20efaa704 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 15:56:37 -0400 Subject: [PATCH 09/25] Added usage for other params and smart description sense The smart description sense fixed an issue where typing "create "my repo" -d -p" (essentially not providing a description even though the tag is used) wrote "-p" (in this case) as the description. A helper method is_tag(tag, dict) was created to see if the added description is a tag. Thus, you cannot have tags as descriptions --- windows_OS/choose.py | 144 +++++++++++++++++++++++++++++++++---------- 1 file changed, 113 insertions(+), 31 deletions(-) diff --git a/windows_OS/choose.py b/windows_OS/choose.py index f644009..dc60390 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -4,24 +4,29 @@ def choose(): print(f"sys.argv --> {str(sys.argv)}") - args = {} - try: - args["name"] = str(sys.argv[1]) - except IndexError: - print("Index error, need name. Showing usage") + if len(sys.argv) == 1: general_usage() + sys.exit(0) + + args = { # Example input: + "name" : "", # "My repo name" + "description" : "", # "My repo description" + "publicity" : "public", # public + "auto_confirm" : "false" # true + } + args["name"] = str(sys.argv[1]) params = { "help" : ["-h", "--help", "help()"], "description" : ["-d", "--description"], "private" : ["-p", "--private"], "local" : ["-l", "--local"], - "auto_confirm" : ["-y", "--yes"] + "auto_confirm" : ["-y", "--yes", "--auto-confirm"] } for i in range(1, len(sys.argv)): - # Test for -h or --help + # Test for -h, --help, or help() if str(sys.argv[i]) in params["help"]: if len(sys.argv) == 2: # "create -h" prints general usage @@ -31,51 +36,73 @@ def choose(): help_usage() else: # "create --description --help" proper use for option parameter - print("Showing optional usage:\n\n") op_param = str(sys.argv[len(sys.argv) - i]) # len(sys.argv) is 3, checking non help or create param if op_param in params["description"]: - print("Showing description usage") + description_usage() elif op_param in params["private"]: - print("Showing private usage") + private_usage() elif op_param in params["local"]: - print("Showing local usage") + local_usage() elif op_param in params["auto_confirm"]: - print("Showing auto confirm usage") + auto_confirm_usage() else: - print("That option is not recognized") + print(f"Unknown Option Error: \"{op_param}\" is not recognized") sys.exit(1) sys.exit(0) # Test for -l or --local if str(sys.argv[i]) in params["local"]: - print("testing if only a name is included") - if len(sys.argv) != 3: - print("you didn't include a name, showing usage and exiting") - print("Running local, exiting this program") - # TODO Can't exit here, case "create --local help()" - + if len(sys.argv) == 2: # No name is included ("create -l") + print("Naming Error: Repository name not included.") + sys.exit(1) + elif len(sys.argv) == 3 and i == 2: + # TODO Run local.py with name parameter + print("Here I am, running local.py with the name parameter.") + elif len(sys.argv) == 3 and str(sys.argv[i+1]) in params["help"]: + local_usage() + else: + print("Syntax Error: Type \"create -l help()\" for usage.") + sys.exit(0) + # Test for -d or --description if str(sys.argv[i]) in params["description"]: - print(f"Adding your description: {str(sys.argv[i+1])}") + # TODO Add description + try: + if not is_tag(tag=str(sys.argv[i+1]), dict=params): + args["description"] = str(sys.argv[i+1]) + except IndexError: + print("Unknown Option Error: A description tag was used but no description was provided.") + sys.exit(1) + + print(f"Added your description: {str(sys.argv[i+1])}") # Test for -p or --private if str(sys.argv[i]) in params["private"]: + # TODO Set repo to private + args["publicity"] = "private" print("Setting repo to private and continuing") - # Test for -y or --yes + # Test for -y, --yes, or --auto-confirm if str(sys.argv[i]) in params["auto_confirm"]: - print("Will initialize repo automatically, without confirmation message.") + # TODO Set repo to push automatically + args["auto_confirm"] = "true" + print("Set repo to automatically, without confirmation message.") + + print("Here I am, we finished!!!") + print("Oh, and here are the passed arguments:") + print(str(args)) def general_usage(): + print() print("Usage:") - print(" create [options]\n") + print(" create [options]\n") print("Commands:") print(" create\t\t\t\tCreate a repository.") @@ -83,13 +110,15 @@ def general_usage(): print() print("Optional Parameters:") print(" -h, --help\t\t\t\tPrints general usage or usage of a specific option.") - print(" -d, --description\t\t\t\tAdd a description to the remote repository.") + print(" -d, --description\t\t\tAdd a description to the remote repository.") print(" -p, --private\t\t\t\tSet remote repository to private.") print(" -l, --local\t\t\t\tCreate a local repository; does not push to Github.") - print("\t\t\t\t\tUse only a repository name and this parameter") - print(" -y, --yes\t\t\t\tAutomatically initialize repository without confirmation message.") + print("\t\t\t\t\tUse only a repository name and this parameter.") + print(" -y, --yes, --auto-confirm\t\tAutomatically initialize repository without confirmation message.") + print() def help_usage(): + print() print("Syntax is incorrect.") print("Usage:") print(" create -h") @@ -102,21 +131,74 @@ def help_usage(): print() print("Description:") print(" Explains usage of the \"create\" command and its options") + print() def description_usage(): - pass + print() + print("Usage:") + print(" create -d \"[repository description]\"") + print(" create --description \"[repository description]\"") + print() + print(" create -d \"[repository description]\" [option]") + print(" create --description \"[repository description]\" [option]") + print() + print("Description:") + print(" The description tag adds a descripiption to the remote repository.") + print(" NOTE: Multi-word descriptions need to be surrounded by quotation marks (\"\")") + print() def private_usage(): - pass + print() + print("Usage:") + print(" create -p") + print(" create --private") + print() + print(" create [option] -p") + print(" create [option] --private") + print() + print("Description:") + print(" The private tag sets the remote repository to private, as it is") + print(" defaulted to public.") + print(" NOTE: The local tag must not be included, as local repositories") + print(" cannot be public or private.") + print() def local_usage(): - pass + print() + print("Usage:") + print(" create -l") + print(" create --local") + print() + print("Description:") + print(" The local tag is used to create a repository locally, not") + print(" pushing to GitHub.") + print(" NOTE: To create a local project, only include the project name") + print(" (in quotation marks if it is multi-word), otherwise you will") + print(" recieve an error.") + print() def auto_confirm_usage(): - pass + print() + print("Usage:") + print(" create -y") + print(" create --yes") + print(" create --auto-confirm") + print() + print(" create [options] -y") + print(" create [options] --yes") + print(" create [options] --auto-confirm") + print() + print("Description:") + print(" The auto-confirmation tag is used to automatically create a remote") + print(" repository without confirming that the details are correct.") + print() - +def is_tag(tag, dict): + for key in dict: + if tag in dict[key]: + return True + return False if __name__ == "__main__": choose() \ No newline at end of file From a189f37632aa80b510b937e629955554f1427654 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 17:33:53 -0400 Subject: [PATCH 10/25] Finished choose.py --- windows_OS/choose.py | 53 +++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/windows_OS/choose.py b/windows_OS/choose.py index dc60390..7372cf4 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -2,17 +2,16 @@ import sys def choose(): - print(f"sys.argv --> {str(sys.argv)}") if len(sys.argv) == 1: general_usage() sys.exit(0) - args = { # Example input: + args = { # Example input: create "My repo name" -d "My repo description" -y "name" : "", # "My repo name" "description" : "", # "My repo description" "publicity" : "public", # public - "auto_confirm" : "false" # true + "auto_confirm" : False # True } args["name"] = str(sys.argv[1]) @@ -29,14 +28,15 @@ def choose(): # Test for -h, --help, or help() if str(sys.argv[i]) in params["help"]: - if len(sys.argv) == 2: # "create -h" prints general usage + if len(sys.argv) == 2: # "create -h" prints general usage general_usage() - elif len(sys.argv) > 3: # "create -d -p -h" user doesn't know how to use -h properly + elif len(sys.argv) > 3: # "create -d -p -h" user doesn't know how to use -h properly help_usage() - else: # "create --description --help" proper use for option parameter - op_param = str(sys.argv[len(sys.argv) - i]) # len(sys.argv) is 3, checking non help or create param + else: # "create --description --help" proper use for option parameter + # len(sys.argv) is 3, checking non help or create param + op_param = str(sys.argv[len(sys.argv) - i]) if op_param in params["description"]: description_usage() @@ -57,7 +57,7 @@ def choose(): sys.exit(0) # Test for -l or --local - if str(sys.argv[i]) in params["local"]: + elif str(sys.argv[i]) in params["local"]: if len(sys.argv) == 2: # No name is included ("create -l") print("Naming Error: Repository name not included.") sys.exit(1) @@ -71,33 +71,31 @@ def choose(): sys.exit(0) # Test for -d or --description - if str(sys.argv[i]) in params["description"]: - # TODO Add description + elif str(sys.argv[i]) in params["description"]: try: if not is_tag(tag=str(sys.argv[i+1]), dict=params): - args["description"] = str(sys.argv[i+1]) + args["description"] = str(sys.argv[i+1]) # If desc. is a tag, leaves it empty except IndexError: print("Unknown Option Error: A description tag was used but no description was provided.") sys.exit(1) - - print(f"Added your description: {str(sys.argv[i+1])}") # Test for -p or --private - if str(sys.argv[i]) in params["private"]: - # TODO Set repo to private + elif str(sys.argv[i]) in params["private"]: args["publicity"] = "private" - print("Setting repo to private and continuing") # Test for -y, --yes, or --auto-confirm - if str(sys.argv[i]) in params["auto_confirm"]: - # TODO Set repo to push automatically + elif str(sys.argv[i]) in params["auto_confirm"]: args["auto_confirm"] = "true" - print("Set repo to automatically, without confirmation message.") + + else: + # TODO Extra input testing for reduced bugs? + pass + + if not args["auto_confirm"]: + if not confirm_info(args): + sys.exit(0) + os.system("python remote.py \"{name}\" \"{description}\" {publicity}".format(**args)) - print("Here I am, we finished!!!") - print("Oh, and here are the passed arguments:") - print(str(args)) - def general_usage(): print() @@ -193,6 +191,15 @@ def auto_confirm_usage(): print(" repository without confirming that the details are correct.") print() +def confirm_info(dict): + print() + print("The following arguments will be passed:") + print(" Name: {name}".format(**dict)) + print(" Description: {description}".format(**dict)) + print(" Publicity: {publicity}".format(**dict)) + print() + usr = input("Is this information correct (y/n)? ") + return usr.lower() == "y" def is_tag(tag, dict): for key in dict: From 8948c84b075691c87ee62fe8bbd5f98bbe127d4a Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 17:53:09 -0400 Subject: [PATCH 11/25] Finished choose.py and remote.py It works! choose.py correctly passes the arguments to remote.py and remote.py correctly pushes to GitHub. Next on the list is to integrate local.py. Also, fixed in issue in remote.py where initializing the README.md file didn't create a title, rather plain text, due to a syntax error. --- windows_OS/remote.py | 45 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/windows_OS/remote.py b/windows_OS/remote.py index 634b6fc..c9d18c1 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -2,55 +2,40 @@ import os from github import Github - -if len(sys.argv) < 2 or len(sys.argv) > 3: - print("Invalid syntax.\n") - - print("Usage:") - print(" create [options]\n") - - print("Commands:") - print(" create\t\t\t\tCreate a repository.") - print(" remove\t\t\t\tRemove a repository.") - print() - print("Optional Parameters:") - print(" -h, --help") - print(" -d, --description\t\t\t\tAdd a description to the remote repository.") - print(" -") - sys.exit(1) - +# Set variables repo_name = str(sys.argv[1]) +repo_description = str(sys.argv[2]) +if str(sys.argv[3]) == "public": + repo_publicity = False +else: + repo_publicity = True + -try: - repo_description = str(sys.argv[2]) -except IndexError: - print("No description will be included") - repo_description = "" -sys.exit(0) -path = "Be sure to add a path" +path = "[Path to workspace here]" _dir = path + '\\' + repo_name -token = "Be sure to add a token" +token = "[GitHub Token here]" g = Github(token) user = g.get_user() login = user.login -repo = user.create_repo(name=repo_name, description=repo_description) +repo = user.create_repo(name=repo_name, + description=repo_description, + private=repo_publicity) os.mkdir(_dir) os.chdir(_dir) -commands = [f'echo "# {repo.name}" >> README.md', +commands = [f'echo # {repo.name} >> README.md', 'git init', f'git remote add origin https://github.com/{login}/{repo.name}.git', 'git add .', 'git commit -m "Initial commit"', 'git push -u origin master'] - - for c in commands: os.system(c) -print(f'Repository "{repo_name}" created locally') +print(f'Repository "{repo_name}" created locally and pushed to GitHub!') +print(f"Check it out at https://github.com/{login}/{repo.name}.git") os.system('code .') \ No newline at end of file From 9e4f7b9800e660cc1917b3e903eed54632c5866f Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 19:15:02 -0400 Subject: [PATCH 12/25] Added readme, finished local and remote scripts --- windows_OS/README.md | 5 +++-- windows_OS/choose.py | 3 ++- windows_OS/local.py | 31 +++++++++++++++---------------- windows_OS/remote.py | 5 ++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/windows_OS/README.md b/windows_OS/README.md index 4fef476..8074f89 100644 --- a/windows_OS/README.md +++ b/windows_OS/README.md @@ -1,8 +1,9 @@ ### pre-setup: +##### Note I still need to update this. ``` create env vars : -> projects directory as - "mp" -> Github tocken as - "gt" +> projects directory as - "PWFA-Path" +> Github tocken as - "PWFA-Token" ``` ### setup: diff --git a/windows_OS/choose.py b/windows_OS/choose.py index 7372cf4..9b20e46 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -63,7 +63,8 @@ def choose(): sys.exit(1) elif len(sys.argv) == 3 and i == 2: # TODO Run local.py with name parameter - print("Here I am, running local.py with the name parameter.") + os.system("python local.py \"{}\"".format(str(sys.argv[1]))) + elif len(sys.argv) == 3 and str(sys.argv[i+1]) in params["help"]: local_usage() else: diff --git a/windows_OS/local.py b/windows_OS/local.py index 4c61a59..8bfdec2 100644 --- a/windows_OS/local.py +++ b/windows_OS/local.py @@ -1,21 +1,20 @@ -import sys import os +import sys -foldername = str(sys.argv[1]) -path = os.environ.get('mp') -_dir = path + '/' + foldername - -try: - os.mkdir(_dir) - os.chdir(_dir) - os.system('git init') - os.system(f'echo "# {foldername}" > README.md') - os.system('git add README.md') - os.system('git commit -m "first commit"') +# Get repository name +repo_name = str(sys.argv[1]) - print(f'{foldername} created locally') - os.system('code .') +# Set directory +_dir = "{}\{}".format(os.environ.get("PWFA-Path"), repo_name) +# Create local repository +os.mkdir(_dir) +os.chdir(_dir) +os.system('git init') +os.system(f'echo # {repo_name} > README.md') +os.system('git add README.md') +os.system('git commit -m "Initial commit"') -except: - print("create l") +# Rejoice Hallelujah! +print(f'{repo_name} created locally!') +os.system('code .') \ No newline at end of file diff --git a/windows_OS/remote.py b/windows_OS/remote.py index c9d18c1..e0f100b 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -11,10 +11,9 @@ repo_publicity = True -path = "[Path to workspace here]" -_dir = path + '\\' + repo_name +_dir = "{}\\{}".format(os.environ.get("PWFA-Path"), repo_name) -token = "[GitHub Token here]" +token = os.environ.get("PWFA-Token") g = Github(token) user = g.get_user() From 9ead7f1c15563acc23d5197e2044ef62e09ce172 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Wed, 15 Jul 2020 22:41:06 -0400 Subject: [PATCH 13/25] Updated Readme and other things Capitalized some things and added some comments. Deleted some no longer needed files --- windows_OS/README.md | 107 +++++++++++++++++++++++++++++----- windows_OS/choose.py | 7 ++- windows_OS/create_working.txt | 32 ---------- windows_OS/remove.bat | 1 + 4 files changed, 98 insertions(+), 49 deletions(-) delete mode 100644 windows_OS/create_working.txt create mode 100644 windows_OS/remove.bat diff --git a/windows_OS/README.md b/windows_OS/README.md index 8074f89..ea880ea 100644 --- a/windows_OS/README.md +++ b/windows_OS/README.md @@ -1,25 +1,104 @@ -### pre-setup: -##### Note I still need to update this. +## Pre-setup: + +### Create user variables + +#### Manually ``` -create env vars : -> projects directory as - "PWFA-Path" -> Github tocken as - "PWFA-Token" +Go to +> environment vairables +> Click "New" in User variables (the top one) +> Set name as "PWFA-Path" +> Set value as your workspace path ``` +#### Through CMD +``` +> setx [user variable name] "[user variable token] -### setup: +For example: +> setx PWFA-Path "ThisIsMyTokenInQuotes" +``` +Either way, you'll have to reset your pc before using them. +## Setup: ```bash -git clone "https://github.com/wikyprash/projectInitializerAutomation.git" +git clone "https://github.com/Red-CS/ProjectInitializationAutomation.git" cd projectInitializerAutomation pip install -r requirements.txt -path: -"projectInitializerAutomation" folder directory to path +If you are on Windows, which you probably are, be sure to add the "projectInitializerAutomation\windows_OS" +folder directory to path, instead you will use the files meant for Mac ``` -### Usage: -```bash -Command to run the program type +## Usage: +#### General Use + +Basically, the core of the command is this: +``` +create [options] +``` +The repository name can now have spaces! Just be sure to put them in quotes: +``` +create "Subscribe to Kalle Halden" +``` +#### Descriptions +Additonally, it's nice to give you're repository a description, yeah? You can type: +``` +create "Subscribe to Kalle Halden" -d "Remember to like and comment" +OR +create "Subscribe to Kalle Halden" --description "Share with your friends!" +``` +#### Private Repositories +Want to set your repo to private? Just add -p or --private +``` +create "Subscribe to Kalle Halden" -d "Like the video" -p. +> Initializes a Github repository set to private. +``` +Don't include this tag for public repos, those are the default. +#### Local Repositories +Creating a local repository is as simple as typing: +``` +create "My Local Repository" -l +OR +create "My Local Repository" --local +``` +Note that it follows that strict syntax (create [repo name] -l/--local) -'create ' -'create ' - for just locally +## Example +Say I wanted to build a remote repository named "Subscribe to Kalle Halden" with a description of "Leave a like and comment!" We'll set as public, too. Just type: ``` +create "Subscribe to Kalle Halden" -d "Leave a like and comment!" +``` +You'll see a message on Command prompt that looks like this: +``` +The following arguments will be passed: + Name: Subscribe to Kalle Halden + Description: Leave a like and comment! + Publicity: Public + +Is this information correct (y/n)? +``` +Simply type "y" or "Y" and your remote Repository will be instantiated. + +If you want to skip that auto confirmation, just add one of the following to the end of the command: +``` +-y --yes --auto-confirm +``` +I recommend doing this for longer repository names and descriptions. + +## Troubleshooting and Help +If you ever need more info on a tag, type either: +``` +-h --help help() +``` +after a tag. For example: +``` +create -d -h +> Outputs description tag usage +``` +Additionally, just typing +``` +create +OR +create -h / --help / help() +``` +will bring up general usage for all tags and commands. + diff --git a/windows_OS/choose.py b/windows_OS/choose.py index 9b20e46..ec4636e 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -10,7 +10,7 @@ def choose(): args = { # Example input: create "My repo name" -d "My repo description" -y "name" : "", # "My repo name" "description" : "", # "My repo description" - "publicity" : "public", # public + "publicity" : "Public", # public "auto_confirm" : False # True } args["name"] = str(sys.argv[1]) @@ -82,14 +82,15 @@ def choose(): # Test for -p or --private elif str(sys.argv[i]) in params["private"]: - args["publicity"] = "private" + args["publicity"] = "Private" # Test for -y, --yes, or --auto-confirm elif str(sys.argv[i]) in params["auto_confirm"]: - args["auto_confirm"] = "true" + args["auto_confirm"] = True else: # TODO Extra input testing for reduced bugs? + # Or more tags/optional params for the future pass if not args["auto_confirm"]: diff --git a/windows_OS/create_working.txt b/windows_OS/create_working.txt deleted file mode 100644 index 4cc28e2..0000000 --- a/windows_OS/create_working.txt +++ /dev/null @@ -1,32 +0,0 @@ -@echo off -setlocal - -rem Variable to contain python script's parameters -REM set pyParams -rem Helper flag for parameter presence. default to 0/FALSE. -set prmOk=0 - -rem Variable to contain python script name to use. default is remote. -set pyName=remote - -rem Process batch parameters -:getParam -if "%~1" == "-l" ( - set pyName=local -) else if "%~1" == "--local" ( - set pyName=local -) else ( - set pyParams=%pyParams% %1 - set prmOk=1 -) -shift -rem After SHIFT, %0 is replaced by %1, %1 replaced by %2, %2 replaced by %3, etc. -if "%~1" neq "" goto getParam - -rem Check python script's parameter presence -if %prmOk% == 0 ( - echo Batch parameter is missing. - goto :eof -) - -echo python %pyName%.py%pyParams% \ No newline at end of file diff --git a/windows_OS/remove.bat b/windows_OS/remove.bat new file mode 100644 index 0000000..caead2a --- /dev/null +++ b/windows_OS/remove.bat @@ -0,0 +1 @@ +rem File for remove command when I make it \ No newline at end of file From 70956289a21fab262a68a01410256113302e1222 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Thu, 16 Jul 2020 02:02:30 -0400 Subject: [PATCH 14/25] Finished remove.py Still need to work on exiting batch scripts in the right directories. Also need to add usage for remove command --- windows_OS/remove.bat | 32 ++++++++++++++++++++++- windows_OS/remove.py | 59 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 windows_OS/remove.py diff --git a/windows_OS/remove.bat b/windows_OS/remove.bat index caead2a..c4dbba6 100644 --- a/windows_OS/remove.bat +++ b/windows_OS/remove.bat @@ -1 +1,31 @@ -rem File for remove command when I make it \ No newline at end of file +@echo off + +cd /d %~dp0 +setlocal + +rem pyParams variable to contain python script's parameters +rem Helper flag for parameter presence. default to 0/FALSE. +set prmOk=0 + +rem Variable to contain python script name to use. default is remote. +set pyName=remove + +rem Process batch parameters +:getParam + +set pyParams=%pyParams% %1 +set prmOk=1 + +shift +rem After SHIFT, %0 is replaced by %1, %1 replaced by %2, %2 replaced by %3, etc. +if "%~1" neq "" goto getParam + +rem Check python script's parameter presence +if %prmOk% == 0 ( + echo Batch parameter is missing. + goto :eof +) + +python %pyName%.py%pyParams% + +:eof \ No newline at end of file diff --git a/windows_OS/remove.py b/windows_OS/remove.py new file mode 100644 index 0000000..c7ef74c --- /dev/null +++ b/windows_OS/remove.py @@ -0,0 +1,59 @@ +import os +import sys +from github import Github + +if len(sys.argv) != 2: + print("Syntax incorrect") + sys.exit(1) + +# Log in +g = Github("b89f916c23a7287dd7b637c90075863cd8c872c3") +user = g.get_user() +login = user.login + +list = ["-l", "--list"] + +def remove(): + # remove -l, --list + if str(sys.argv[1]) in list: + pos = 0 + print() + for repo in user.get_repos(): + pos += 1 + print(f" {pos}. {repo.name}") + print() + + sys.exit(0) + else: + try: + git_url = "https://github.com/" + # remove -3 + if str(sys.argv[1]).startswith("-") and str(sys.argv[1])[1:].isnumeric(): + passed_int = int(str(sys.argv[1])[1:]) + repo_url = "{}{}".format(git_url, user.get_repos()[passed_int - 1].full_name) + if delete_repo(repo_url): + user.get_repos()[passed_int - 1].delete() + print(f"Deleted repository {repo_url}") + else: + # remove repoName + passed_str = str(sys.argv[1]) + repo_url = "{}{}".format(git_url, user.get_repo(passed_str).full_name) + if delete_repo(repo_url): + user.get_repo(passed_str).delete() + print(f"Deleted repository {repo_url}") + except: + print("Error in processing request") + print() + +def delete_repo(repo_name): + for x in range(0, 3): print() + print("Warning!") + print(f" Executing this command would remove {repo_name}") + print() + usr = input("Are you sure you want to delete this repository (y/n)? ") + return usr.lower() == "y" + +def general_usage() + +if __name__ == "__main__": + remove() From 4ea95e18535656176c4051c4053b565b8feedafa Mon Sep 17 00:00:00 2001 From: Red Williams Date: Thu, 16 Jul 2020 03:27:27 -0400 Subject: [PATCH 15/25] removed literal token from remove.py I'm stupid. Guess how I found out this was a problem --- windows_OS/README.md | 3 +++ windows_OS/remove.bat | 3 ++- windows_OS/remove.py | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/windows_OS/README.md b/windows_OS/README.md index ea880ea..7fe08b4 100644 --- a/windows_OS/README.md +++ b/windows_OS/README.md @@ -9,6 +9,9 @@ Go to > Click "New" in User variables (the top one) > Set name as "PWFA-Path" > Set value as your workspace path +> Get a token here: https://github.com/settings/tokens/new + > Must have repo, user, and delete_repo permissions +> Set "PWFA-Token" to the given token. ``` #### Through CMD ``` diff --git a/windows_OS/remove.bat b/windows_OS/remove.bat index c4dbba6..75ee36a 100644 --- a/windows_OS/remove.bat +++ b/windows_OS/remove.bat @@ -1,5 +1,6 @@ @echo off +pushd cd /d %~dp0 setlocal @@ -27,5 +28,5 @@ if %prmOk% == 0 ( ) python %pyName%.py%pyParams% - +popd :eof \ No newline at end of file diff --git a/windows_OS/remove.py b/windows_OS/remove.py index c7ef74c..629d18e 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -7,7 +7,9 @@ sys.exit(1) # Log in -g = Github("b89f916c23a7287dd7b637c90075863cd8c872c3") +token = os.environ.get("PWFA-Token") + +g = Github(token) user = g.get_user() login = user.login @@ -53,7 +55,8 @@ def delete_repo(repo_name): usr = input("Are you sure you want to delete this repository (y/n)? ") return usr.lower() == "y" -def general_usage() +def general_usage(): + pass if __name__ == "__main__": remove() From c77e5fc64329c98b6f1ce4acc619627eca2a4680 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Thu, 16 Jul 2020 17:59:27 -0400 Subject: [PATCH 16/25] Fixed bat files, remove.py syntax, and Readme Fixed an issue where, after launching create or remove, cmd would exit in path of batch script instead of the current working directory. Add usage for remove command and fixed readme accordingly --- windows_OS/README.md | 61 ++++++++++++++++++++++++++++++++++++++----- windows_OS/choose.py | 7 ++--- windows_OS/create.bat | 3 ++- windows_OS/remove.bat | 6 ++--- windows_OS/remove.py | 20 +++++++++++--- 5 files changed, 80 insertions(+), 17 deletions(-) diff --git a/windows_OS/README.md b/windows_OS/README.md index 7fe08b4..125b55e 100644 --- a/windows_OS/README.md +++ b/windows_OS/README.md @@ -1,4 +1,4 @@ -## Pre-setup: +# Pre-setup: ### Create user variables @@ -21,7 +21,7 @@ For example: > setx PWFA-Path "ThisIsMyTokenInQuotes" ``` Either way, you'll have to reset your pc before using them. -## Setup: +# Setup: ```bash git clone "https://github.com/Red-CS/ProjectInitializationAutomation.git" cd projectInitializerAutomation @@ -31,9 +31,9 @@ If you are on Windows, which you probably are, be sure to add the "projectInitia folder directory to path, instead you will use the files meant for Mac ``` -## Usage: +# Usage: +## Create #### General Use - Basically, the core of the command is this: ``` create [options] @@ -64,8 +64,7 @@ OR create "My Local Repository" --local ``` Note that it follows that strict syntax (create [repo name] -l/--local) - -## Example +### Example Say I wanted to build a remote repository named "Subscribe to Kalle Halden" with a description of "Leave a like and comment!" We'll set as public, too. Just type: ``` create "Subscribe to Kalle Halden" -d "Leave a like and comment!" @@ -87,7 +86,7 @@ If you want to skip that auto confirmation, just add one of the following to the ``` I recommend doing this for longer repository names and descriptions. -## Troubleshooting and Help +### Troubleshooting and Help If you ever need more info on a tag, type either: ``` -h --help help() @@ -104,4 +103,52 @@ OR create -h / --help / help() ``` will bring up general usage for all tags and commands. +## Remove +#### General Use +``` +remove +``` +Yes, it's that simple. As of this version, you are can remove just the remote repository. Your passed repository name has to match GitHub's version of it. For example: + +If you called +``` +create "Subscribe To Kalle" +``` +Github would read it as +``` +Subscribe-To-Kalle +``` + +To remove this repostory, simply type: +``` +remove Subscribe-To-Kalle +``` +to see a warning and confirmation message to remove the repository remotely. +#### Other Parameters +Let's say you forget the name of the repository you're trying to delete. Typing: +``` +remote -l +OR +remote --list +``` +shows a numbered list of your repositories. +``` +> remove --list + + 1. Like + 2. Comment + 3. Share + 4. And-Subscribe + + ``` +You can use this to delete repositories by position. For example, say you wanted to delete repository #4, "And-Subscribe". Enter: +``` +> remove -4 + + +Warning! + Executing this command would remove https://github.com/User/And-Subscribe + +Are you sure you want to delete this repository (y/n)? y +Deleted repository https://github.com/User/And-Subscribe diff --git a/windows_OS/choose.py b/windows_OS/choose.py index ec4636e..6f21f5a 100644 --- a/windows_OS/choose.py +++ b/windows_OS/choose.py @@ -89,8 +89,8 @@ def choose(): args["auto_confirm"] = True else: - # TODO Extra input testing for reduced bugs? - # Or more tags/optional params for the future + # TODO More tags/optional params for the future. + # That's up to you, creator! pass if not args["auto_confirm"]: @@ -119,7 +119,8 @@ def general_usage(): def help_usage(): print() - print("Syntax is incorrect.") + print("Syntax Error: Help tag is used incorrectly.") + print() print("Usage:") print(" create -h") print(" create --help") diff --git a/windows_OS/create.bat b/windows_OS/create.bat index 7c7d5a7..ca544ce 100644 --- a/windows_OS/create.bat +++ b/windows_OS/create.bat @@ -1,6 +1,7 @@ @echo off -cd /d %~dp0 setlocal +cd /d %~dp0 + rem pyParams variable to contain python script's parameters rem Helper flag for parameter presence. default to 0/FALSE. diff --git a/windows_OS/remove.bat b/windows_OS/remove.bat index 75ee36a..fc7b041 100644 --- a/windows_OS/remove.bat +++ b/windows_OS/remove.bat @@ -1,8 +1,7 @@ @echo off +setlocal -pushd cd /d %~dp0 -setlocal rem pyParams variable to contain python script's parameters rem Helper flag for parameter presence. default to 0/FALSE. @@ -28,5 +27,6 @@ if %prmOk% == 0 ( ) python %pyName%.py%pyParams% -popd + +cd .. :eof \ No newline at end of file diff --git a/windows_OS/remove.py b/windows_OS/remove.py index 629d18e..3b43dbf 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -3,7 +3,7 @@ from github import Github if len(sys.argv) != 2: - print("Syntax incorrect") + print("Syntax Error") sys.exit(1) # Log in @@ -48,15 +48,29 @@ def remove(): print() def delete_repo(repo_name): - for x in range(0, 3): print() + print() + print() print("Warning!") print(f" Executing this command would remove {repo_name}") print() + print() usr = input("Are you sure you want to delete this repository (y/n)? ") return usr.lower() == "y" def general_usage(): - pass + print() + print("Usage:") + print(" remove \n") + + print("Commands:") + print(" create\t\t\t\tCreate a repository.") + print(" remove\t\t\t\tRemove a repository.") + print() + print("Required Parameters:") + print(" -l, --list\t\t\t\tPrints a list of your remote repositories.") + print(" -X \t\t\t\tRemoves the Xth repository. View list by typing \"remove -l\".") + print(" \t\t\tRemoves the remote repository with the given name.") + print() if __name__ == "__main__": remove() From a9c7ccf5e1e2b7c771a084635c032e9b1ca493c9 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Thu, 16 Jul 2020 18:21:02 -0400 Subject: [PATCH 17/25] Updated updatelog.txt Also commited mid sentence of remove.py, so that's why that is part of this commit :) --- windows_OS/remove.py | 8 +++++++- windows_OS/updatelog.txt | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/windows_OS/remove.py b/windows_OS/remove.py index 3b43dbf..e616dbc 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -16,6 +16,9 @@ list = ["-l", "--list"] def remove(): + + """Remove remote repository""" + # remove -l, --list if str(sys.argv[1]) in list: pos = 0 @@ -29,7 +32,7 @@ def remove(): else: try: git_url = "https://github.com/" - # remove -3 + # remove -X if str(sys.argv[1]).startswith("-") and str(sys.argv[1])[1:].isnumeric(): passed_int = int(str(sys.argv[1])[1:]) repo_url = "{}{}".format(git_url, user.get_repos()[passed_int - 1].full_name) @@ -47,6 +50,9 @@ def remove(): print("Error in processing request") print() + """Remove local repository""" + + def delete_repo(repo_name): print() print() diff --git a/windows_OS/updatelog.txt b/windows_OS/updatelog.txt index 68283a9..108ebfc 100644 --- a/windows_OS/updatelog.txt +++ b/windows_OS/updatelog.txt @@ -7,4 +7,9 @@ Also trying to make things more simple, and adding the option to have repo names with spaces in it / user comfortability. Also, I'm new to pull requests, if you couldn't already tell by this crappy txt. -Ok thx, bye \ No newline at end of file +Ok thx, bye + +So since I'm getting close to finishing, just pointing +out that I'll be deleting this file. Something like this +will be found in the description of the pull request, whenever +I make it, probably some time tonight \ No newline at end of file From badecd71a7c87f3bba8d9b612f7d730e15ccfd09 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Thu, 16 Jul 2020 23:06:48 -0400 Subject: [PATCH 18/25] Fixed critical bug in remote.py My stupid head forget to add a sys.exit in remote.py after block of code that creates and inits a repo. As you can imagine, the bug caused the script to initialize a whole new repo in the current directory. This commit is just so we know everything is ok at this point. Also, I started the code for deleting files (which I was testing). Nearly complete --- windows_OS/README.md | 2 +- windows_OS/remote.py | 11 ++-- windows_OS/remove.py | 116 +++++++++++++++++++++++++++++++------------ 3 files changed, 94 insertions(+), 35 deletions(-) diff --git a/windows_OS/README.md b/windows_OS/README.md index 125b55e..1a2f208 100644 --- a/windows_OS/README.md +++ b/windows_OS/README.md @@ -151,4 +151,4 @@ Warning! Are you sure you want to delete this repository (y/n)? y -Deleted repository https://github.com/User/And-Subscribe +Deleted repository https://github.com/User/And-Subscribe \ No newline at end of file diff --git a/windows_OS/remote.py b/windows_OS/remote.py index e0f100b..6b7df5b 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -5,7 +5,7 @@ # Set variables repo_name = str(sys.argv[1]) repo_description = str(sys.argv[2]) -if str(sys.argv[3]) == "public": +if str(sys.argv[3]) == "Public": repo_publicity = False else: repo_publicity = True @@ -22,8 +22,13 @@ description=repo_description, private=repo_publicity) -os.mkdir(_dir) -os.chdir(_dir) +try: + os.mkdir(_dir) +except FileExistsError: + print(f"{_dir} already exists.") + sys.exit(1) +else: + os.chdir(_dir) commands = [f'echo # {repo.name} >> README.md', 'git init', diff --git a/windows_OS/remove.py b/windows_OS/remove.py index e616dbc..43eb9d1 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -2,6 +2,8 @@ import sys from github import Github + + if len(sys.argv) != 2: print("Syntax Error") sys.exit(1) @@ -19,39 +21,60 @@ def remove(): """Remove remote repository""" - # remove -l, --list - if str(sys.argv[1]) in list: - pos = 0 - print() - for repo in user.get_repos(): - pos += 1 - print(f" {pos}. {repo.name}") - print() - - sys.exit(0) - else: - try: - git_url = "https://github.com/" - # remove -X - if str(sys.argv[1]).startswith("-") and str(sys.argv[1])[1:].isnumeric(): - passed_int = int(str(sys.argv[1])[1:]) - repo_url = "{}{}".format(git_url, user.get_repos()[passed_int - 1].full_name) - if delete_repo(repo_url): - user.get_repos()[passed_int - 1].delete() - print(f"Deleted repository {repo_url}") - else: - # remove repoName - passed_str = str(sys.argv[1]) - repo_url = "{}{}".format(git_url, user.get_repo(passed_str).full_name) - if delete_repo(repo_url): - user.get_repo(passed_str).delete() - print(f"Deleted repository {repo_url}") - except: - print("Error in processing request") + # remove -l, --list + if str(sys.argv[1]) in list: + pos = 0 + print() + for repo in user.get_repos(): + pos += 1 + print(f" {pos}. {repo.name}") + print() + + sys.exit(0) + else: + try: + git_url = "https://github.com/" + # remove -X + if str(sys.argv[1]).startswith("-") and str(sys.argv[1])[1:].isnumeric(): + passed_int = int(str(sys.argv[1])[1:]) + l_repo_name = user.get_repos()[passed_int - 1].name # For removing local + repo_url = "{}{}".format(git_url, user.get_repos()[passed_int - 1].full_name) + if delete_repo(repo_url): + user.get_repos()[passed_int - 1].delete() + print(f"Deleted repository {repo_url}") + else: + # remove repoName + passed_str = str(sys.argv[1]) + l_repo_name = passed_str # For removing local + repo_url = "{}{}".format(git_url, user.get_repo(passed_str).full_name) + if delete_repo(repo_url): + user.get_repo(passed_str).delete() + print(f"Deleted repository {repo_url}") + except: + print("Error in processing request") print() + sys.exit(1) + + if not continue_local(): + sys.exit(0) + + """Remove local repository""" + + path = os.environ.get("PWFA-Path") + + # Try searching for a local Repos with spaces or dashes + if os.path.isdir(f"{path}\\{l_repo_name}"): + if delete_repo(l_repo_name): + delete_local(path, l_repo_name) + elif os.path.isdir(f"{path}\\{refactor_local(l_repo_name)}"): + l_repo_name = refactor_local(l_repo_name) + if delete_repo(l_repo_name): + delete_local(path, l_repo_name) + else: + print("Nope, DNE") + + - """Remove local repository""" - def delete_repo(repo_name): print() @@ -63,6 +86,37 @@ def delete_repo(repo_name): usr = input("Are you sure you want to delete this repository (y/n)? ") return usr.lower() == "y" +def continue_local(): + print() + print() + usr = input("Continue to search for and delete a local repository (y/n)? ") + return usr.lower() == "y" + +def refactor_local(repo_name): + local_name = "" + for char in repo_name: + if char == "-": + local_name += " " + else: + local_name += char + return local_name + +def delete_local(path_stem, path_head): + print() + for dirpath, dirnames, filename in os.walk((path_stem + "\\" + path_head), topdown=False): + for file in filename: + try: + os.remove("{}\\{}\\{}".format(path_stem, path_head, file)) + except: + print(f"Failed with removing {path_head}\\{file}") + print("Passed:") + print(" {}\\{}\\{}".format(path_stem, path_head, file)) + sys.exit(1) + else: + print(f" Deleted: {path_head}\\{file}") + + + def general_usage(): print() print("Usage:") From 2394d9940c9ef48f0db5d480ef9c687f8eb3b18a Mon Sep 17 00:00:00 2001 From: Red Williams Date: Fri, 17 Jul 2020 01:20:56 -0400 Subject: [PATCH 19/25] Fixed some bugs, more to go Fixed a logic error with creating directories and changing into them. Added a couple TODOs of what needs to be developed later, it's like 1 am now. Removing files locally is EXTREMELY buggy right now, but I know what's going on it's just writing the code to fix that, which we'll hopefully see in the next commit. Ok, sleep's calling --- windows_OS/local.py | 3 ++- windows_OS/remote.py | 9 +++------ windows_OS/remove.py | 12 +++++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/windows_OS/local.py b/windows_OS/local.py index 8bfdec2..68d1eb8 100644 --- a/windows_OS/local.py +++ b/windows_OS/local.py @@ -8,7 +8,8 @@ _dir = "{}\{}".format(os.environ.get("PWFA-Path"), repo_name) # Create local repository -os.mkdir(_dir) +if not os._isdir(_dir): + os.mkdir(_dir) os.chdir(_dir) os.system('git init') os.system(f'echo # {repo_name} > README.md') diff --git a/windows_OS/remote.py b/windows_OS/remote.py index 6b7df5b..93c5a78 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -22,13 +22,10 @@ description=repo_description, private=repo_publicity) -try: + +if not os._isdir(_dir): os.mkdir(_dir) -except FileExistsError: - print(f"{_dir} already exists.") - sys.exit(1) -else: - os.chdir(_dir) +os.chdir(_dir) commands = [f'echo # {repo.name} >> README.md', 'git init', diff --git a/windows_OS/remove.py b/windows_OS/remove.py index 43eb9d1..93fd8fb 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -51,8 +51,8 @@ def remove(): user.get_repo(passed_str).delete() print(f"Deleted repository {repo_url}") except: - print("Error in processing request") - print() + # TODO Run refactor local to test other possible repo name + print(f"Naming Error: Error in finding remote repository \"{l_repo_name}\"") sys.exit(1) if not continue_local(): @@ -106,14 +106,16 @@ def delete_local(path_stem, path_head): for dirpath, dirnames, filename in os.walk((path_stem + "\\" + path_head), topdown=False): for file in filename: try: - os.remove("{}\\{}\\{}".format(path_stem, path_head, file)) + os.remove("{}\\{}".format(dirpath, file)) except: - print(f"Failed with removing {path_head}\\{file}") + print(f"Failed with removing {dirpath}\\{file}") print("Passed:") - print(" {}\\{}\\{}".format(path_stem, path_head, file)) + print(" {}\\{}".format(dirpath, file)) sys.exit(1) else: + # TODO Fix issue where subdirectories containing files aren't shown print(f" Deleted: {path_head}\\{file}") + print("Next step is to delete local repo") From 952055f78b79f1ab4f77f538607c11c6d0b2d710 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Fri, 17 Jul 2020 19:03:12 -0400 Subject: [PATCH 20/25] Finished file removal and print process Deletes all files in a local repository correctly, displaying the relative path of each deleted file and directory. With that, this pull is basically done! Just have to add finishing touches in the form of neater code, colored output (yay!), better comments, and more try/except handling for clearer user error reports --- windows_OS/remote.py | 3 ++- windows_OS/remove.py | 46 +++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/windows_OS/remote.py b/windows_OS/remote.py index 93c5a78..803a106 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -23,7 +23,7 @@ private=repo_publicity) -if not os._isdir(_dir): +if not os.path.isdir(_dir): os.mkdir(_dir) os.chdir(_dir) @@ -37,6 +37,7 @@ for c in commands: os.system(c) +# TODO Add file path instead of "created locally" print(f'Repository "{repo_name}" created locally and pushed to GitHub!') print(f"Check it out at https://github.com/{login}/{repo.name}.git") os.system('code .') \ No newline at end of file diff --git a/windows_OS/remove.py b/windows_OS/remove.py index 93fd8fb..b05f141 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -1,9 +1,8 @@ import os +import stat import sys from github import Github - - if len(sys.argv) != 2: print("Syntax Error") sys.exit(1) @@ -60,22 +59,24 @@ def remove(): """Remove local repository""" + # path = "{}\\\\{}".format(os.environ.get("PWFA-Path"), l_repo_name) + # path = os.environ.get(f"{PWFA-Path}\\{l_repo_name}") path = os.environ.get("PWFA-Path") + print(f"path --> {path}") # Try searching for a local Repos with spaces or dashes - if os.path.isdir(f"{path}\\{l_repo_name}"): + if os.path.isdir(f"{path}\\\\{l_repo_name}"): + path += "\\\\" + l_repo_name if delete_repo(l_repo_name): - delete_local(path, l_repo_name) + rmtree(path, l_repo_name) elif os.path.isdir(f"{path}\\{refactor_local(l_repo_name)}"): l_repo_name = refactor_local(l_repo_name) + path += "\\\\" + l_repo_name if delete_repo(l_repo_name): - delete_local(path, l_repo_name) + rmtree(path, l_repo_name) else: print("Nope, DNE") - - - def delete_repo(repo_name): print() print() @@ -101,21 +102,22 @@ def refactor_local(repo_name): local_name += char return local_name -def delete_local(path_stem, path_head): +def rmtree(top, dir_name): + print() + for root, dirs, files in os.walk(top, topdown=False): + relative_path = root[root.index(dir_name):] + for name in files: + filename = os.path.join(root, name) + os.chmod(filename, stat.S_IWUSR) + os.remove(filename) + print(" Deleted File: {}\\{}".format(relative_path, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) + print(" Deleted Directory: {}\\{}".format(relative_path, name)) + os.rmdir(top) + print() + print(f" Deleted Parent Directory: {top}") print() - for dirpath, dirnames, filename in os.walk((path_stem + "\\" + path_head), topdown=False): - for file in filename: - try: - os.remove("{}\\{}".format(dirpath, file)) - except: - print(f"Failed with removing {dirpath}\\{file}") - print("Passed:") - print(" {}\\{}".format(dirpath, file)) - sys.exit(1) - else: - # TODO Fix issue where subdirectories containing files aren't shown - print(f" Deleted: {path_head}\\{file}") - print("Next step is to delete local repo") From 11c025adfdcd855ba0df263a527670efbc6f709a Mon Sep 17 00:00:00 2001 From: Red Williams Date: Sat, 18 Jul 2020 00:49:08 -0400 Subject: [PATCH 21/25] Added colour! Used colorama module to add some colour to the output, green when stuff is created and red when asking to destroy repos. Also added some comments to make it easier to understand. That pretty much finished output. Next is to refactor some variables and method names to make it more readable. After that I should be done and ready to issue a pull request. But on that note, I'll need to update the File structure too to make it more even. And add an extra readme. Thanks for reading this commit description. If you're seeing this, you're awesome! :) --- windows_OS/remote.py | 16 +++++++++--- windows_OS/remove.py | 51 +++++++++++++++++++++++-------------- windows_OS/requirements.txt | 3 ++- windows_OS/updatelog.txt | 15 ----------- 4 files changed, 46 insertions(+), 39 deletions(-) delete mode 100644 windows_OS/updatelog.txt diff --git a/windows_OS/remote.py b/windows_OS/remote.py index 803a106..4e8ff45 100644 --- a/windows_OS/remote.py +++ b/windows_OS/remote.py @@ -1,8 +1,12 @@ -import sys import os +import sys + +from colorama import init, Fore, Style from github import Github -# Set variables +init() + +# Set passed repository attributes repo_name = str(sys.argv[1]) repo_description = str(sys.argv[2]) if str(sys.argv[3]) == "Public": @@ -13,16 +17,17 @@ _dir = "{}\\{}".format(os.environ.get("PWFA-Path"), repo_name) +# Login to GitHub token = os.environ.get("PWFA-Token") - g = Github(token) user = g.get_user() login = user.login +# Create remote repository repo = user.create_repo(name=repo_name, description=repo_description, private=repo_publicity) - +# Create local directory and cd if not os.path.isdir(_dir): os.mkdir(_dir) os.chdir(_dir) @@ -34,10 +39,13 @@ 'git commit -m "Initial commit"', 'git push -u origin master'] +# Initialize local repo and push for c in commands: os.system(c) # TODO Add file path instead of "created locally" +print(Fore.GREEN) print(f'Repository "{repo_name}" created locally and pushed to GitHub!') print(f"Check it out at https://github.com/{login}/{repo.name}.git") +print(Style.RESET_ALL) os.system('code .') \ No newline at end of file diff --git a/windows_OS/remove.py b/windows_OS/remove.py index b05f141..e5f5feb 100644 --- a/windows_OS/remove.py +++ b/windows_OS/remove.py @@ -1,15 +1,19 @@ import os import stat import sys + +from colorama import init, Fore, Style from github import Github +init() + +# Check for only 2 arguments if len(sys.argv) != 2: print("Syntax Error") sys.exit(1) # Log in token = os.environ.get("PWFA-Token") - g = Github(token) user = g.get_user() login = user.login @@ -17,7 +21,6 @@ list = ["-l", "--list"] def remove(): - """Remove remote repository""" # remove -l, --list @@ -27,25 +30,34 @@ def remove(): for repo in user.get_repos(): pos += 1 print(f" {pos}. {repo.name}") - print() - + print() sys.exit(0) else: try: git_url = "https://github.com/" + # remove -X - if str(sys.argv[1]).startswith("-") and str(sys.argv[1])[1:].isnumeric(): + if ( + str(sys.argv[1]).startswith("-") and + str(sys.argv[1])[1:].isnumeric() + ): passed_int = int(str(sys.argv[1])[1:]) - l_repo_name = user.get_repos()[passed_int - 1].name # For removing local - repo_url = "{}{}".format(git_url, user.get_repos()[passed_int - 1].full_name) + l_repo_name = user.get_repos()[passed_int - 1].name + repo_url = "{}{}".format(git_url, + user.get_repos()[passed_int - 1].full_name) + + # Confirm deletion if delete_repo(repo_url): user.get_repos()[passed_int - 1].delete() print(f"Deleted repository {repo_url}") else: # remove repoName passed_str = str(sys.argv[1]) - l_repo_name = passed_str # For removing local - repo_url = "{}{}".format(git_url, user.get_repo(passed_str).full_name) + l_repo_name = passed_str + repo_url = "{}{}".format(git_url, + user.get_repo(passed_str).full_name) + + # Confirm deletion if delete_repo(repo_url): user.get_repo(passed_str).delete() print(f"Deleted repository {repo_url}") @@ -54,37 +66,38 @@ def remove(): print(f"Naming Error: Error in finding remote repository \"{l_repo_name}\"") sys.exit(1) + # Move on to local or exit if not continue_local(): sys.exit(0) """Remove local repository""" - # path = "{}\\\\{}".format(os.environ.get("PWFA-Path"), l_repo_name) - # path = os.environ.get(f"{PWFA-Path}\\{l_repo_name}") path = os.environ.get("PWFA-Path") - print(f"path --> {path}") - # Try searching for a local Repos with spaces or dashes + # Search local repos with dashes if os.path.isdir(f"{path}\\\\{l_repo_name}"): path += "\\\\" + l_repo_name + # Delete if selected if delete_repo(l_repo_name): rmtree(path, l_repo_name) + # Search local repos with spaces elif os.path.isdir(f"{path}\\{refactor_local(l_repo_name)}"): l_repo_name = refactor_local(l_repo_name) path += "\\\\" + l_repo_name + # Delete if selected if delete_repo(l_repo_name): rmtree(path, l_repo_name) else: + # Local repository not found + # TODO change print statement here print("Nope, DNE") def delete_repo(repo_name): print() - print() - print("Warning!") - print(f" Executing this command would remove {repo_name}") - print() - print() - usr = input("Are you sure you want to delete this repository (y/n)? ") + print(Fore.RED) + print(f"Warning! Executing this command would remove {repo_name}") + print("Are you sure you want to delete this repository (y/n)? ", end=Style.RESET_ALL) + usr = input() return usr.lower() == "y" def continue_local(): diff --git a/windows_OS/requirements.txt b/windows_OS/requirements.txt index b393fb0..9cffd63 100644 --- a/windows_OS/requirements.txt +++ b/windows_OS/requirements.txt @@ -1 +1,2 @@ -PyGithub \ No newline at end of file +PyGithub +colorama \ No newline at end of file diff --git a/windows_OS/updatelog.txt b/windows_OS/updatelog.txt deleted file mode 100644 index 108ebfc..0000000 --- a/windows_OS/updatelog.txt +++ /dev/null @@ -1,15 +0,0 @@ -Ok, basically I thought the .env file was stupid if you -could easily just write in the token and path. -I'm also adding new functionalities that will -take in parameters like a description or having -the choice for it to be private and whatnot. -Also trying to make things more simple, and -adding the option to have repo names with spaces in it -/ user comfortability. Also, I'm new to pull requests, -if you couldn't already tell by this crappy txt. -Ok thx, bye - -So since I'm getting close to finishing, just pointing -out that I'll be deleting this file. Something like this -will be found in the description of the pull request, whenever -I make it, probably some time tonight \ No newline at end of file From 962878a29e81a72c42e1beeffb52cdb113b3d54a Mon Sep 17 00:00:00 2001 From: Red Williams Date: Sat, 18 Jul 2020 04:42:19 -0400 Subject: [PATCH 22/25] Final commit Final commit. Cleaned code and refactored some variables, cleaned output. Reworked file structure and added additional README for more . . . central usage. --- .my_commands.sh => Mac-OS/.my_commands.sh | 0 Mac-OS/README.md | 21 ++ create.py => Mac-OS/create.py | 0 remove.py => Mac-OS/remove.py | 0 requirements.txt => Mac-OS/requirements.txt | 0 README.md | 27 +-- {windows_OS => Windows}/.gitignore | 0 {windows_OS => Windows}/README.md | 11 +- {windows_OS => Windows}/choose.py | 63 +++++- {windows_OS => Windows}/create.bat | 4 + Windows/local.py | 43 ++++ {windows_OS => Windows}/remote.py | 27 ++- {windows_OS => Windows}/remove.bat | 5 + Windows/remove.py | 208 ++++++++++++++++++++ {windows_OS => Windows}/requirements.txt | 0 windows_OS/local.py | 21 -- windows_OS/remove.py | 153 -------------- 17 files changed, 369 insertions(+), 214 deletions(-) rename .my_commands.sh => Mac-OS/.my_commands.sh (100%) create mode 100644 Mac-OS/README.md rename create.py => Mac-OS/create.py (100%) rename remove.py => Mac-OS/remove.py (100%) rename requirements.txt => Mac-OS/requirements.txt (100%) rename {windows_OS => Windows}/.gitignore (100%) rename {windows_OS => Windows}/README.md (89%) rename {windows_OS => Windows}/choose.py (74%) rename {windows_OS => Windows}/create.bat (87%) create mode 100644 Windows/local.py rename {windows_OS => Windows}/remote.py (61%) rename {windows_OS => Windows}/remove.bat (87%) create mode 100644 Windows/remove.py rename {windows_OS => Windows}/requirements.txt (100%) delete mode 100644 windows_OS/local.py delete mode 100644 windows_OS/remove.py diff --git a/.my_commands.sh b/Mac-OS/.my_commands.sh similarity index 100% rename from .my_commands.sh rename to Mac-OS/.my_commands.sh diff --git a/Mac-OS/README.md b/Mac-OS/README.md new file mode 100644 index 0000000..8c5f9e8 --- /dev/null +++ b/Mac-OS/README.md @@ -0,0 +1,21 @@ +### Install: +```bash +git clone "https://github.com/KalleHallden/ProjectInitializationAutomation.git" +cd ProjectInitializationAutomation +pip install -r requirements.txt +touch .env +Then open the .env file and store your username, password, and desired file destination. Use the provided format at the bottom of this README. +source ~/.my_commands.sh +``` + +### Usage: +```bash +To run the script type in 'create ' +``` + +### Env File Format: +```bash +USERNAME="Username123" +PASSWORD="Password123" +FILEPATH="/path/to/your/project/" +``` diff --git a/create.py b/Mac-OS/create.py similarity index 100% rename from create.py rename to Mac-OS/create.py diff --git a/remove.py b/Mac-OS/remove.py similarity index 100% rename from remove.py rename to Mac-OS/remove.py diff --git a/requirements.txt b/Mac-OS/requirements.txt similarity index 100% rename from requirements.txt rename to Mac-OS/requirements.txt diff --git a/README.md b/README.md index 8c5f9e8..96ed851 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,8 @@ -### Install: -```bash -git clone "https://github.com/KalleHallden/ProjectInitializationAutomation.git" -cd ProjectInitializationAutomation -pip install -r requirements.txt -touch .env -Then open the .env file and store your username, password, and desired file destination. Use the provided format at the bottom of this README. -source ~/.my_commands.sh -``` +# Project Initialization Automation +See the respective folder for your operating system. Additional README files can be found there. -### Usage: -```bash -To run the script type in 'create ' -``` - -### Env File Format: -```bash -USERNAME="Username123" -PASSWORD="Password123" -FILEPATH="/path/to/your/project/" -``` +## Author +* **Kalle Halden** - [KalleHalden](https://github.com/KalleHalden) +## Contributors: +* **Prakash** - [wikyprash](https://github.com/wikyprash) +* **Red Williams** - [Red-CS](https://github.com/Red-CS) \ No newline at end of file diff --git a/windows_OS/.gitignore b/Windows/.gitignore similarity index 100% rename from windows_OS/.gitignore rename to Windows/.gitignore diff --git a/windows_OS/README.md b/Windows/README.md similarity index 89% rename from windows_OS/README.md rename to Windows/README.md index 1a2f208..cce66e5 100644 --- a/windows_OS/README.md +++ b/Windows/README.md @@ -8,11 +8,13 @@ Go to > environment vairables > Click "New" in User variables (the top one) > Set name as "PWFA-Path" -> Set value as your workspace path +> Set value as your workspace path (use double backslash (\\) as path separators) > Get a token here: https://github.com/settings/tokens/new > Must have repo, user, and delete_repo permissions > Set "PWFA-Token" to the given token. ``` +You can, of course, name these whatever you'd like. Just be sure to go through +remote.py, local.py, and remove.py and change that argument. #### Through CMD ``` > setx [user variable name] "[user variable token] @@ -22,7 +24,7 @@ For example: ``` Either way, you'll have to reset your pc before using them. # Setup: -```bash +``` git clone "https://github.com/Red-CS/ProjectInitializationAutomation.git" cd projectInitializerAutomation pip install -r requirements.txt @@ -151,4 +153,7 @@ Warning! Are you sure you want to delete this repository (y/n)? y -Deleted repository https://github.com/User/And-Subscribe \ No newline at end of file +Deleted repository https://github.com/User/And-Subscribe +``` +# Authors +Windows files created by Red Williams (Red-CS)[https://github.com/Red-CS] and sharers of previously commited pull requests. See pull request history for more. \ No newline at end of file diff --git a/windows_OS/choose.py b/Windows/choose.py similarity index 74% rename from windows_OS/choose.py rename to Windows/choose.py index 6f21f5a..1db48b1 100644 --- a/windows_OS/choose.py +++ b/Windows/choose.py @@ -1,8 +1,25 @@ import os import sys +""" +Author: Red Williams (Red-CS) +Email: red.devcs@gmail.com + +July 18, 2020 +""" + def choose(): + """Chooses which file, remote.py or local.py, is to be run. + Also parses optional parameters (as definied in the params dict) + for additional options when creating a repoisotry remotely. The + API allows for a multiple arguments, but I've included the most + used options. That is why this is meant to be dynamic: if you + want to add more commands, simply create a new tag in the params + dictionary, add it to the if/else block, add to args if necessary, + and read it in the appropriate file (remote.py or local.py). + """ + # create: Case where only the create command is called if len(sys.argv) == 1: general_usage() sys.exit(0) @@ -28,14 +45,18 @@ def choose(): # Test for -h, --help, or help() if str(sys.argv[i]) in params["help"]: - if len(sys.argv) == 2: # "create -h" prints general usage + # create -h / create --help / create help() + if len(sys.argv) == 2: general_usage() - elif len(sys.argv) > 3: # "create -d -p -h" user doesn't know how to use -h properly + # create -d -p -h: User doesn't know how to use -h properly + elif len(sys.argv) > 3: help_usage() - else: # "create --description --help" proper use for option parameter - # len(sys.argv) is 3, checking non help or create param + # create --description --help: Proper use for optional parameter + else: + + # Retrieve help-requested parameter op_param = str(sys.argv[len(sys.argv) - i]) if op_param in params["description"]: @@ -58,25 +79,34 @@ def choose(): # Test for -l or --local elif str(sys.argv[i]) in params["local"]: - if len(sys.argv) == 2: # No name is included ("create -l") + + # create -l: Cases where no name is included + if len(sys.argv) == 2: print("Naming Error: Repository name not included.") sys.exit(1) + + # create --local "My Repo Name": Cases where local creation is used correctly elif len(sys.argv) == 3 and i == 2: - # TODO Run local.py with name parameter - os.system("python local.py \"{}\"".format(str(sys.argv[1]))) + os.system("python local.py \"{}\"".format(str(sys.argv[1]))) # Must inlcude quotes + # create -l help(): Get help on using the local tag elif len(sys.argv) == 3 and str(sys.argv[i+1]) in params["help"]: local_usage() + else: print("Syntax Error: Type \"create -l help()\" for usage.") sys.exit(0) # Test for -d or --description elif str(sys.argv[i]) in params["description"]: + try: + # create -d --private: Cases where description tag is used, but no description included if not is_tag(tag=str(sys.argv[i+1]), dict=params): - args["description"] = str(sys.argv[i+1]) # If desc. is a tag, leaves it empty + args["description"] = str(sys.argv[i+1]) # If next parameter is a tag, leaves description empty + except IndexError: + # create --private -d: Cases where description tag is last, where sys.argv[i+1] will raise IndexError print("Unknown Option Error: A description tag was used but no description was provided.") sys.exit(1) @@ -93,13 +123,19 @@ def choose(): # That's up to you, creator! pass + # Presents confirmation message to user if not args["auto_confirm"]: if not confirm_info(args): sys.exit(0) - os.system("python remote.py \"{name}\" \"{description}\" {publicity}".format(**args)) + # Execution, baby! + os.system("python remote.py \"{name}\" \"{description}\" {publicity}".format(**args)) def general_usage(): + """Shows general usage of the create command, as well as the existence of + the remove command. Shows optional paramters as well. Remember to add to this list + and the corresponding usage function when adding new tags. + """ print() print("Usage:") print(" create [options]\n") @@ -118,6 +154,7 @@ def general_usage(): print() def help_usage(): + """Shows how to use the help tags.""" print() print("Syntax Error: Help tag is used incorrectly.") print() @@ -135,6 +172,7 @@ def help_usage(): print() def description_usage(): + """Shows how to use the description tags""" print() print("Usage:") print(" create -d \"[repository description]\"") @@ -149,6 +187,7 @@ def description_usage(): print() def private_usage(): + """Shows how to use the private tags""" print() print("Usage:") print(" create -p") @@ -165,6 +204,7 @@ def private_usage(): print() def local_usage(): + """Shows how to use the local tags""" print() print("Usage:") print(" create -l") @@ -179,6 +219,7 @@ def local_usage(): print() def auto_confirm_usage(): + """Shows how to use to automatic confirm tags""" print() print("Usage:") print(" create -y") @@ -195,6 +236,9 @@ def auto_confirm_usage(): print() def confirm_info(dict): + """Confirms if the called arguments are correct. This method only calls when + one of the automatic confirm tags aren't listed. + """ print() print("The following arguments will be passed:") print(" Name: {name}".format(**dict)) @@ -205,6 +249,7 @@ def confirm_info(dict): return usr.lower() == "y" def is_tag(tag, dict): + """Helper method testing if a passed paramter is a defined tag.""" for key in dict: if tag in dict[key]: return True diff --git a/windows_OS/create.bat b/Windows/create.bat similarity index 87% rename from windows_OS/create.bat rename to Windows/create.bat index ca544ce..cee085f 100644 --- a/windows_OS/create.bat +++ b/Windows/create.bat @@ -2,6 +2,10 @@ setlocal cd /d %~dp0 +rem Author: Red Williams (Red-CS) +rem Email: red.devcs@gmail.com + +rem July 18, 2020 rem pyParams variable to contain python script's parameters rem Helper flag for parameter presence. default to 0/FALSE. diff --git a/Windows/local.py b/Windows/local.py new file mode 100644 index 0000000..013aa42 --- /dev/null +++ b/Windows/local.py @@ -0,0 +1,43 @@ +import os +import sys + +from colorama import init, Fore, Style + +""" +Author: Red Williams (Red-CS) +Email: red.devcs@gmail.com + +July 18, 2020 +""" + +# The world is dark enough, let's add some color! +init() + +# Get repository name +repo_name = str(sys.argv[1]) + +# Set directory +_dir = "{}\\\\{}".format(os.environ.get("PWFA-Path"), repo_name) + +# Create local repository +if not os.path.isdir(_dir): + os.mkdir(_dir) +os.chdir(_dir) + +# Test if git is initialzed +if os.path.isdir(f"{_dir}\\.git"): + usr = input("Git is already initialized. Reinitialize git (y/n)? ") + if not usr.lower() == "y": + sys.exit(0) + +# Initialize git +os.system('git init') +os.system(f'echo # {repo_name} > README.md') +os.system('git add README.md') +os.system('git commit -m "Initial commit"') + +# Rejoice Hallelujah! +print(Fore.GREEN) +print(f"Created \"{repo_name}\" locally!") +print(Style.RESET_ALL) +os.system('code .') \ No newline at end of file diff --git a/windows_OS/remote.py b/Windows/remote.py similarity index 61% rename from windows_OS/remote.py rename to Windows/remote.py index 4e8ff45..be0a8fc 100644 --- a/windows_OS/remote.py +++ b/Windows/remote.py @@ -4,6 +4,16 @@ from colorama import init, Fore, Style from github import Github +""" +Author: Red Williams (Red-CS) +Email: red.devcs@gmail.com + +July 18, 2020 +""" + +"""Creates and pushes a repository locally and remotely with the passed arguments""" + +# Color is beautiful! init() # Set passed repository attributes @@ -15,23 +25,25 @@ repo_publicity = True -_dir = "{}\\{}".format(os.environ.get("PWFA-Path"), repo_name) +_dir = "{}\\\\{}".format(os.environ.get("PWFA-Path"), repo_name) # Login to GitHub token = os.environ.get("PWFA-Token") g = Github(token) user = g.get_user() login = user.login + # Create remote repository repo = user.create_repo(name=repo_name, description=repo_description, private=repo_publicity) -# Create local directory and cd +# Create local directory and change into said directory if not os.path.isdir(_dir): os.mkdir(_dir) os.chdir(_dir) +# TODO Add README.md commit message parameter in choose.py commands = [f'echo # {repo.name} >> README.md', 'git init', f'git remote add origin https://github.com/{login}/{repo.name}.git', @@ -39,13 +51,12 @@ 'git commit -m "Initial commit"', 'git push -u origin master'] -# Initialize local repo and push -for c in commands: - os.system(c) +# Initialize local repository and push to GitHub +for command in commands: + os.system(command) -# TODO Add file path instead of "created locally" print(Fore.GREEN) -print(f'Repository "{repo_name}" created locally and pushed to GitHub!') +print(f"Created \"{_dir}\" locally and pushed to GitHub!") print(f"Check it out at https://github.com/{login}/{repo.name}.git") print(Style.RESET_ALL) -os.system('code .') \ No newline at end of file +os.system('code .') # TODO Add if/else block and os.environ.get for setting code editor preference, or another tag \ No newline at end of file diff --git a/windows_OS/remove.bat b/Windows/remove.bat similarity index 87% rename from windows_OS/remove.bat rename to Windows/remove.bat index fc7b041..6838189 100644 --- a/windows_OS/remove.bat +++ b/Windows/remove.bat @@ -3,6 +3,11 @@ setlocal cd /d %~dp0 +rem Author: Red Williams (Red-CS) +rem Email: red.devcs@gmail.com + +rem July 18, 2020 + rem pyParams variable to contain python script's parameters rem Helper flag for parameter presence. default to 0/FALSE. set prmOk=0 diff --git a/Windows/remove.py b/Windows/remove.py new file mode 100644 index 0000000..9e910ed --- /dev/null +++ b/Windows/remove.py @@ -0,0 +1,208 @@ +import os +import stat +import sys + +from colorama import init, Fore, Style +from github import Github + +""" +Author: Red Williams (Red-CS) +Email: red.devcs@gmail.com + +July 18, 2020 +""" + +def remove(): + """Removes first a remote repository, then a local one. If a local + repository isn't found, it will abort (since this is mainly for GitHub) + Note that the argument called is os.environ.get() can be anything, as + long as it is definied in your user variable list. + """ + # Setup + + # Activiate color mode! + init() + + if len(sys.argv) == 1: + general_usage() + sys.exit(0) + + elif len(sys.argv) > 2: + print(f"Syntax Error: Command requires only one argument, {int(len(sys.argv) - 1)} were given.") + general_usage() + sys.exit(1) + + # Log in + token = os.environ.get("PWFA-Token") + g = Github(token) + user = g.get_user() + login = user.login + + list = ["-l", "--list"] + + # Remove remote repository + + # remove -l, --list + if str(sys.argv[1]) in list: + repo_number = 0 + print() + for repo in user.get_repos(): + repo_number += 1 + print(f" {repo_number}. {repo.name}") + print() + sys.exit(0) + else: + try: + + git_url = "https://github.com/" + + # remove -X + if ( + str(sys.argv[1]).startswith("-") and + str(sys.argv[1])[1:].isnumeric() + ): + passed_int = int(str(sys.argv[1])[1:]) + local_repo_name = user.get_repos()[passed_int - 1].name + repo_url = "{}{}".format(git_url, + user.get_repos()[passed_int - 1].full_name) + + # Confirm deletion + if ask_delete_repo(repo_url): + user.get_repos()[passed_int - 1].delete() + print(f"Deleted repository {repo_url}") + else: + print("Remote repository not deleted.") + else: + # remove repoName + passed_str = str(sys.argv[1]) + local_repo_name = passed_str + repo_url = "{}{}".format(git_url, + user.get_repo(passed_str).full_name) + + # Confirm deletion + if ask_delete_repo(repo_url): + user.get_repo(passed_str).delete() + print(f"Deleted repository {repo_url}") + else: + print("Remote repository not deleted.") + except: + # TODO Run refactor local to test other possible repo name + print(f"Naming Error: Error in finding remote repository \"{local_repo_name}\"") + sys.exit(1) + + # Move on to local or exit + if not ask_continue_local(): + sys.exit(0) + + # Remove local repository + + path = os.environ.get("PWFA-Path") + + # Search local repos with dashes + if os.path.isdir(f"{path}\\\\{local_repo_name}"): + + path += "\\\\" + local_repo_name + + # Delete if selected + if ask_delete_repo(local_repo_name): + remove_local_directory(path, local_repo_name) + else: + print("Local repository not deleted.\n") + + # Search local repos with spaces + elif os.path.isdir(f"{path}\\{refactor_local(local_repo_name)}"): + + local_repo_name = refactor_local(local_repo_name) + path += "\\\\" + local_repo_name + + # Delete if selected + if ask_delete_repo(path): + remove_local_directory(path, local_repo_name) + else: + print("Local repository not deleted.\n") + + # Local repository not found + else: + print("A directory with that name could not be found.") + +def ask_delete_repo(repo_name): + """Prompts the user if they are sure they want to delete the + repository. Used for both deleting the local and remote repository. + There is no auto confirm tag since this is a special process, I don't + want anyone to accidentally delete a repository. + """ + print() + print(Fore.RED) + print(f"Warning! Executing this command would remove {repo_name}") + print("Are you sure you want to delete this repository (y/n)? ", end=Style.RESET_ALL) + usr = input() + return usr.lower() == "y" + +def ask_continue_local(): + """Prompts the user if they want to continue to search for and delete + a local repository after being asked to delete a remote repository. + """ + print() + print() + usr = input("Continue to search for and delete a local repository (y/n)? ") + return usr.lower() == "y" + +def refactor_local(repo_name): + """Changes the name of the repository staged for remote deletion to + test if it was saved under a slightly different name locally. For example + and as you know, GitHub repository names have dashes instead of spaces. + This project allows for repository names with spaces. Thus, a remote name + could be "Remote-Repository" while a local name could be "Remote Repository" + This method changes the passed repo_name by replacing dashes with spaces. + Note that repository names with apostrophes (') also appear with dashes, + so don't use those when creating a repository with this project. + """ + local_name = "" + for char in repo_name: + if char == "-": + local_name += " " + else: + local_name += char + return local_name + +def remove_local_directory(directory_path, directory_name): + """Removes all files, directories, and sub directories of a + local repository, printing what is deleted with every iteration. + Note some files initialized with git are read only and can't be + deleted normally. This gives access and deletes the proper files, + giving a better output if there is an error. + """ + print() + for root_path, directories, files in os.walk(directory_path, topdown=False): + relative_path = root_path[root_path.index(directory_name):] + for name in files: + filename = os.path.join(root_path, name) + os.chmod(filename, stat.S_IWUSR) + os.remove(filename) + print(" Deleted File: {}\\{}".format(relative_path, name)) + for name in directories: + os.rmdir(os.path.join(root_path, name)) + print(" Deleted Directory: {}\\{}".format(relative_path, name)) + os.rmdir(directory_path) + print() + print(f" Deleted Parent Directory: {directory_path}") + print() + +def general_usage(): + """Prints general usage of the remove command""" + print() + print("Usage:") + print(" remove \n") + + print("Commands:") + print(" create\t\t\t\tCreate a repository.") + print(" remove\t\t\t\tRemove a repository.") + print() + print("Required Parameters:") + print(" -l, --list\t\t\t\tPrints a list of your remote repositories.") + print(" -X \t\t\t\tRemoves the Xth repository. View list by typing \"remove -l\".") + print(" \t\t\tRemoves the remote repository with the given name.") + print() + +if __name__ == "__main__": + remove() diff --git a/windows_OS/requirements.txt b/Windows/requirements.txt similarity index 100% rename from windows_OS/requirements.txt rename to Windows/requirements.txt diff --git a/windows_OS/local.py b/windows_OS/local.py deleted file mode 100644 index 68d1eb8..0000000 --- a/windows_OS/local.py +++ /dev/null @@ -1,21 +0,0 @@ -import os -import sys - -# Get repository name -repo_name = str(sys.argv[1]) - -# Set directory -_dir = "{}\{}".format(os.environ.get("PWFA-Path"), repo_name) - -# Create local repository -if not os._isdir(_dir): - os.mkdir(_dir) -os.chdir(_dir) -os.system('git init') -os.system(f'echo # {repo_name} > README.md') -os.system('git add README.md') -os.system('git commit -m "Initial commit"') - -# Rejoice Hallelujah! -print(f'{repo_name} created locally!') -os.system('code .') \ No newline at end of file diff --git a/windows_OS/remove.py b/windows_OS/remove.py deleted file mode 100644 index e5f5feb..0000000 --- a/windows_OS/remove.py +++ /dev/null @@ -1,153 +0,0 @@ -import os -import stat -import sys - -from colorama import init, Fore, Style -from github import Github - -init() - -# Check for only 2 arguments -if len(sys.argv) != 2: - print("Syntax Error") - sys.exit(1) - -# Log in -token = os.environ.get("PWFA-Token") -g = Github(token) -user = g.get_user() -login = user.login - -list = ["-l", "--list"] - -def remove(): - """Remove remote repository""" - - # remove -l, --list - if str(sys.argv[1]) in list: - pos = 0 - print() - for repo in user.get_repos(): - pos += 1 - print(f" {pos}. {repo.name}") - print() - sys.exit(0) - else: - try: - git_url = "https://github.com/" - - # remove -X - if ( - str(sys.argv[1]).startswith("-") and - str(sys.argv[1])[1:].isnumeric() - ): - passed_int = int(str(sys.argv[1])[1:]) - l_repo_name = user.get_repos()[passed_int - 1].name - repo_url = "{}{}".format(git_url, - user.get_repos()[passed_int - 1].full_name) - - # Confirm deletion - if delete_repo(repo_url): - user.get_repos()[passed_int - 1].delete() - print(f"Deleted repository {repo_url}") - else: - # remove repoName - passed_str = str(sys.argv[1]) - l_repo_name = passed_str - repo_url = "{}{}".format(git_url, - user.get_repo(passed_str).full_name) - - # Confirm deletion - if delete_repo(repo_url): - user.get_repo(passed_str).delete() - print(f"Deleted repository {repo_url}") - except: - # TODO Run refactor local to test other possible repo name - print(f"Naming Error: Error in finding remote repository \"{l_repo_name}\"") - sys.exit(1) - - # Move on to local or exit - if not continue_local(): - sys.exit(0) - - """Remove local repository""" - - path = os.environ.get("PWFA-Path") - - # Search local repos with dashes - if os.path.isdir(f"{path}\\\\{l_repo_name}"): - path += "\\\\" + l_repo_name - # Delete if selected - if delete_repo(l_repo_name): - rmtree(path, l_repo_name) - # Search local repos with spaces - elif os.path.isdir(f"{path}\\{refactor_local(l_repo_name)}"): - l_repo_name = refactor_local(l_repo_name) - path += "\\\\" + l_repo_name - # Delete if selected - if delete_repo(l_repo_name): - rmtree(path, l_repo_name) - else: - # Local repository not found - # TODO change print statement here - print("Nope, DNE") - -def delete_repo(repo_name): - print() - print(Fore.RED) - print(f"Warning! Executing this command would remove {repo_name}") - print("Are you sure you want to delete this repository (y/n)? ", end=Style.RESET_ALL) - usr = input() - return usr.lower() == "y" - -def continue_local(): - print() - print() - usr = input("Continue to search for and delete a local repository (y/n)? ") - return usr.lower() == "y" - -def refactor_local(repo_name): - local_name = "" - for char in repo_name: - if char == "-": - local_name += " " - else: - local_name += char - return local_name - -def rmtree(top, dir_name): - print() - for root, dirs, files in os.walk(top, topdown=False): - relative_path = root[root.index(dir_name):] - for name in files: - filename = os.path.join(root, name) - os.chmod(filename, stat.S_IWUSR) - os.remove(filename) - print(" Deleted File: {}\\{}".format(relative_path, name)) - for name in dirs: - os.rmdir(os.path.join(root, name)) - print(" Deleted Directory: {}\\{}".format(relative_path, name)) - os.rmdir(top) - print() - print(f" Deleted Parent Directory: {top}") - print() - - - -def general_usage(): - print() - print("Usage:") - print(" remove \n") - - print("Commands:") - print(" create\t\t\t\tCreate a repository.") - print(" remove\t\t\t\tRemove a repository.") - print() - print("Required Parameters:") - print(" -l, --list\t\t\t\tPrints a list of your remote repositories.") - print(" -X \t\t\t\tRemoves the Xth repository. View list by typing \"remove -l\".") - print(" \t\t\tRemoves the remote repository with the given name.") - print() - -if __name__ == "__main__": - remove() From e204021d90b7116d20cc4d25520910abf8850ccd Mon Sep 17 00:00:00 2001 From: Red Williams Date: Sat, 18 Jul 2020 04:56:58 -0400 Subject: [PATCH 23/25] Update README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96ed851..00396b5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Project Initialization Automation See the respective folder for your operating system. Additional README files can be found there. - ## Author * **Kalle Halden** - [KalleHalden](https://github.com/KalleHalden) ## Contributors: * **Prakash** - [wikyprash](https://github.com/wikyprash) -* **Red Williams** - [Red-CS](https://github.com/Red-CS) \ No newline at end of file +* **Red Williams** - [Red-CS](https://github.com/Red-CS) +## Production +Kalle Halden's Youtube video: [One Day Builds: Automating My Projects With Python](https://www.youtube.com/watch?v=7Y8Ppin12r4) \ No newline at end of file From 596afa455c462184b49789839df12fdd0b821445 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Mon, 20 Jul 2020 17:01:19 -0400 Subject: [PATCH 24/25] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 00396b5..b41d91b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ See the respective folder for your operating system. Additional README files can ## Author * **Kalle Halden** - [KalleHalden](https://github.com/KalleHalden) ## Contributors: -* **Prakash** - [wikyprash](https://github.com/wikyprash) * **Red Williams** - [Red-CS](https://github.com/Red-CS) -## Production -Kalle Halden's Youtube video: [One Day Builds: Automating My Projects With Python](https://www.youtube.com/watch?v=7Y8Ppin12r4) \ No newline at end of file +## Production Inspiration +Kalle Halden's Youtube video: [One Day Builds: Automating My Projects With Python](https://www.youtube.com/watch?v=7Y8Ppin12r4) From 59a1a63a524f6c028c26f80df00fb6ab3dec5190 Mon Sep 17 00:00:00 2001 From: Red Williams Date: Thu, 6 Aug 2020 16:14:43 -0400 Subject: [PATCH 25/25] Fixed typos in readme files --- README.md | 4 ++-- Windows/README.md | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 00396b5..5859e60 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Project Initialization Automation See the respective folder for your operating system. Additional README files can be found there. ## Author -* **Kalle Halden** - [KalleHalden](https://github.com/KalleHalden) +* **Kalle Hallden** - [KalleHallden](https://github.com/KalleHallden) ## Contributors: * **Prakash** - [wikyprash](https://github.com/wikyprash) * **Red Williams** - [Red-CS](https://github.com/Red-CS) ## Production -Kalle Halden's Youtube video: [One Day Builds: Automating My Projects With Python](https://www.youtube.com/watch?v=7Y8Ppin12r4) \ No newline at end of file +Kalle Hallden's Youtube video: [One Day Builds: Automating My Projects With Python](https://www.youtube.com/watch?v=7Y8Ppin12r4) \ No newline at end of file diff --git a/Windows/README.md b/Windows/README.md index cce66e5..758db8e 100644 --- a/Windows/README.md +++ b/Windows/README.md @@ -42,19 +42,19 @@ create [options] ``` The repository name can now have spaces! Just be sure to put them in quotes: ``` -create "Subscribe to Kalle Halden" +create "Subscribe to Kalle Hallden" ``` #### Descriptions Additonally, it's nice to give you're repository a description, yeah? You can type: ``` -create "Subscribe to Kalle Halden" -d "Remember to like and comment" +create "Subscribe to Kalle Hallden" -d "Remember to like and comment" OR -create "Subscribe to Kalle Halden" --description "Share with your friends!" +create "Subscribe to Kalle Hallden" --description "Share with your friends!" ``` #### Private Repositories Want to set your repo to private? Just add -p or --private ``` -create "Subscribe to Kalle Halden" -d "Like the video" -p. +create "Subscribe to Kalle Hallden" -d "Like the video" -p. > Initializes a Github repository set to private. ``` Don't include this tag for public repos, those are the default. @@ -67,14 +67,14 @@ create "My Local Repository" --local ``` Note that it follows that strict syntax (create [repo name] -l/--local) ### Example -Say I wanted to build a remote repository named "Subscribe to Kalle Halden" with a description of "Leave a like and comment!" We'll set as public, too. Just type: +Say I wanted to build a remote repository named "Subscribe to Kalle Hallden" with a description of "Leave a like and comment!" We'll set as public, too. Just type: ``` -create "Subscribe to Kalle Halden" -d "Leave a like and comment!" +create "Subscribe to Kalle Hallden" -d "Leave a like and comment!" ``` You'll see a message on Command prompt that looks like this: ``` The following arguments will be passed: - Name: Subscribe to Kalle Halden + Name: Subscribe to Kalle Hallden Description: Leave a like and comment! Publicity: Public