Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df8bb61

Browse files
Added 'Master Script' base JSON DB (avinashkranjan#963)
Added the Database
1 parent 7943416 commit df8bb61

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

‎Master Script/Script.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from optparse import OptionParser
2+
import json
3+
import sys
4+
import os
5+
6+
usage = """
7+
<Script> [Options]
8+
9+
[Options]
10+
-h, --help Show this help message and exit.
11+
-a, --add Goes straight to the add script phase
12+
"""
13+
# Load args
14+
parser = OptionParser()
15+
parser.add_option("-a", "--add", action="store_true", dest="add", help="Goes straight to the add script phase")
16+
17+
def add_script():
18+
""" Add a Contributor script through a series of inputs """
19+
print("Double check inputs before pressing enter. If one input is incorrect press CTRL-C and re-run the script")
20+
category = input("Enter What category does your script belongs to > ")
21+
name = input("Enter script title > ")
22+
path = input("Enter folder name that contains your script > ")
23+
requirments_path = input("Enter requirements.txt path (else none) > ")
24+
entry = input("Enter name of the file that runs the script > ")
25+
arguments = input("Enter scripts arugments if needed ( '-' seperated + no whitespaces) (else none) > ")
26+
contributor = input("Enter your GitHub username > ")
27+
description = input("Enter a description for your script > ")
28+
29+
new_data = {category: {name: [path, entry, arguments, requirments_path, contributor, description]}}
30+
data_store = read_data()
31+
32+
try:
33+
# If category doesn't exist try will fail and except will ask to add a new category with the project
34+
if data_store[category]: # Check for existing category or a new one
35+
data_store[category].update(new_data[category]) # Add script
36+
except:
37+
sure = "Y"
38+
sure = input("A new category is about to be added. You sure? Y/n > ")
39+
if sure.lower() == "y" or sure == "":
40+
data_store.update(new_data) # Add new category
41+
else:
42+
print("Data wasn't added please re-run the script and add the correct inputs.")
43+
sys.exit(1)
44+
45+
with open("datastore.json", "w") as file:
46+
json.dump(data_store, file)
47+
print("Script added to database")
48+
49+
50+
def read_data():
51+
""" Loads datastore.json """
52+
with open("datastore.json", "r") as file:
53+
data = json.load(file)
54+
return data
55+
56+
57+
def check_data():
58+
""" Validates that all projects exists in the datastore and prints out those are not in the DB """
59+
data = read_data()
60+
paths = []
61+
for category in data:
62+
for project in data[category]:
63+
paths.append(data[category][project][0])
64+
i=0
65+
repo_dir = os.listdir("../")
66+
ignore = [".deepsource.toml", ".git", ".github", ".gitignore",
67+
"CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "LICENSE",
68+
"README.md", "SCRIPTS.md", "script_updater.py",
69+
"Template for README.md", "Master Script", ]
70+
for element in repo_dir:
71+
if (not element in paths) and (not element in ignore):
72+
print(element)
73+
i+=1
74+
75+
print(f"Total of {i} non-added projects.")
76+
77+
78+
79+
80+
# Start checkpoint
81+
if __name__ == "__main__":
82+
(options, args) = parser.parse_args()
83+
84+
# Inputs
85+
add = options.add
86+
87+
if add:
88+
add_script()
89+
#add_script()
90+
check_data()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /