Amazing-Python-Scripts

Форк
0
/
manual db updater.py 
98 строк · 3.3 Кб
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",
16
                  help="Goes straight to the add script phase")
17

18

19
# The database is automatically updated after the PR is merged.
20
# ONLY Use this function if you were asked to, to manually add projects to the database.
21
def add_script():
22
    """ Add a Contributor script through a series of inputs """
23
    print("Double check inputs before pressing enter. If one input is incorrect press CTRL-C and re-run the script")
24
    category = input("Enter What category does your script belongs to > ")
25
    name = input("Enter script title > ")
26
    path = input("Enter folder name that contains your script > ")
27
    requirments_path = input("Enter requirements.txt path (else none) > ")
28
    entry = input("Enter name of the file that runs the script > ")
29
    arguments = input(
30
        "Enter scripts arugments if needed ( '-' seperated + no whitespaces) (else none) > ")
31
    contributor = input("Enter your GitHub username > ")
32
    description = input("Enter a description for your script > ")
33

34
    new_data = {category: {
35
        name: [path, entry, arguments, requirments_path, contributor, description]}}
36
    data_store = read_data()
37

38
    try:
39
        # If category doesn't exist try will fail and except will ask to add a new category with the project
40
        # Check for existing category or a new one
41
        if data_store[category]:
42
            data_store[category].update(
43
                new_data[category])           # Add script
44
    except:
45
        sure = "Y"
46
        sure = input("A new category is about to be added. You sure? Y/n > ")
47
        if sure.lower() == "y" or sure == "":
48
            # Add new category
49
            data_store.update(new_data)
50
        else:
51
            print(
52
                "Data wasn't added please re-run the script and add the correct inputs.")
53
            sys.exit(1)
54

55
    with open("datastore.json", "w") as file:
56
        json.dump(data_store, file)
57
    print("Script added to database")
58

59

60
def read_data():
61
    """ Loads datastore.json """
62
    with open("datastore.json", "r") as file:
63
        data = json.load(file)
64
    return data
65

66

67
def check_data():
68
    """ Validates that all projects exists in the datastore and prints out those are not in the DB """
69
    data = read_data()
70
    paths = []
71
    for category in data:
72
        for project in data[category]:
73
            paths.append(data[category][project][0])
74
    i = 0
75
    repo_dir = os.listdir("../")
76
    ignore = [".deepsource.toml", ".git", ".github", ".gitignore",
77
              "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "LICENSE",
78
              "README.md", "SCRIPTS.md", "script_updater.py",
79
              "Template for README.md", "Master Script", ]
80
    for element in repo_dir:
81
        if (not element in paths) and (not element in ignore):
82
            print(element)
83
            i += 1
84

85
    print(f"Total of {i} non-added projects.")
86

87

88
# Start checkpoint
89
if __name__ == "__main__":
90
    (options, args) = parser.parse_args()
91

92
    # Inputs
93
    add = options.add
94

95
    if add:
96
        add_script()
97
    # add_script()
98
    check_data()
99

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.