forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from avinashkranjan:master #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
Master Script/Script.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from optparse import OptionParser | ||
import json | ||
import sys | ||
import os | ||
|
||
usage = """ | ||
<Script> [Options] | ||
|
||
[Options] | ||
-h, --help Show this help message and exit. | ||
-a, --add Goes straight to the add script phase | ||
""" | ||
# Load args | ||
parser = OptionParser() | ||
parser.add_option("-a", "--add", action="store_true", dest="add", help="Goes straight to the add script phase") | ||
|
||
def add_script(): | ||
""" Add a Contributor script through a series of inputs """ | ||
print("Double check inputs before pressing enter. If one input is incorrect press CTRL-C and re-run the script") | ||
category = input("Enter What category does your script belongs to > ") | ||
name = input("Enter script title > ") | ||
path = input("Enter folder name that contains your script > ") | ||
requirments_path = input("Enter requirements.txt path (else none) > ") | ||
entry = input("Enter name of the file that runs the script > ") | ||
arguments = input("Enter scripts arugments if needed ( '-' seperated + no whitespaces) (else none) > ") | ||
contributor = input("Enter your GitHub username > ") | ||
description = input("Enter a description for your script > ") | ||
|
||
new_data = {category: {name: [path, entry, arguments, requirments_path, contributor, description]}} | ||
data_store = read_data() | ||
|
||
try: | ||
# If category doesn't exist try will fail and except will ask to add a new category with the project | ||
if data_store[category]: # Check for existing category or a new one | ||
data_store[category].update(new_data[category]) # Add script | ||
except: | ||
sure = "Y" | ||
sure = input("A new category is about to be added. You sure? Y/n > ") | ||
if sure.lower() == "y" or sure == "": | ||
data_store.update(new_data) # Add new category | ||
else: | ||
print("Data wasn't added please re-run the script and add the correct inputs.") | ||
sys.exit(1) | ||
|
||
with open("datastore.json", "w") as file: | ||
json.dump(data_store, file) | ||
print("Script added to database") | ||
|
||
|
||
def read_data(): | ||
""" Loads datastore.json """ | ||
with open("datastore.json", "r") as file: | ||
data = json.load(file) | ||
return data | ||
|
||
|
||
def check_data(): | ||
""" Validates that all projects exists in the datastore and prints out those are not in the DB """ | ||
data = read_data() | ||
paths = [] | ||
for category in data: | ||
for project in data[category]: | ||
paths.append(data[category][project][0]) | ||
i=0 | ||
repo_dir = os.listdir("../") | ||
ignore = [".deepsource.toml", ".git", ".github", ".gitignore", | ||
"CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "LICENSE", | ||
"README.md", "SCRIPTS.md", "script_updater.py", | ||
"Template for README.md", "Master Script", ] | ||
for element in repo_dir: | ||
if (not element in paths) and (not element in ignore): | ||
print(element) | ||
i+=1 | ||
|
||
print(f"Total of {i} non-added projects.") | ||
|
||
|
||
|
||
|
||
# Start checkpoint | ||
if __name__ == "__main__": | ||
(options, args) = parser.parse_args() | ||
|
||
# Inputs | ||
add = options.add | ||
|
||
if add: | ||
add_script() | ||
#add_script() | ||
check_data() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.