-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TAKASE Yusuke
committed
Sep 17, 2024
1 parent
1e96046
commit 29231df
Showing
13 changed files
with
299 additions
and
119 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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,145 @@ | ||
#!/usr/bin/env python3 | ||
# -*- encoding: utf-8 -*- | ||
|
||
from base64 import b64decode | ||
import getpass | ||
from pathlib import Path | ||
from time import sleep | ||
from github import Github | ||
from rich import print | ||
from rich.table import Table | ||
import tomlkit | ||
import os | ||
import json | ||
import numpy as np | ||
import toml | ||
|
||
CONFIG_PATH = Path.home() / ".config" / "sbm_dataset" | ||
CONFIG_FILE_PATH = CONFIG_PATH / "sbm_dataset.toml" | ||
|
||
repositories = [] | ||
|
||
|
||
# Convert numpy.int64 to Python int | ||
def custom_encoder(obj): | ||
if isinstance(obj, np.ndarray): | ||
return obj.tolist() | ||
if isinstance(obj, np.int64): | ||
return int(obj) | ||
if isinstance(obj, bytes): | ||
return obj.decode('utf-8') | ||
raise TypeError(f"Type {type(obj)} not serializable") | ||
|
||
def retrieve_local_source(): | ||
print() | ||
path = Path( | ||
input('Please enter the directory where file "sim_config.json" resides: ') | ||
).absolute() | ||
|
||
if not (path / "sim_config.json").is_file(): | ||
print(f'[red]Error:[/red] {path} does not seem to contain a "sim_config.json" file') | ||
create_file = input('Would you like to create a "sim_config.json" file? (y/n): ') | ||
if create_file.lower() == 'y': | ||
gen_jsonfile(path) | ||
print(f'[green]"sim_config.json" has been created at {path}.[/green]') | ||
else: | ||
return | ||
|
||
name = input("Now insert a descriptive name for this location: ") | ||
|
||
repositories.append({"name": name, "location": str(path.resolve())}) | ||
|
||
print( | ||
f""" | ||
[green]Repository "{name}" has been added successfully.[/green] | ||
""" | ||
) | ||
|
||
def run_main_loop() -> bool: | ||
prompt = """Choose a source for the database: | ||
1. [cyan]Local source[/cyan] | ||
A directory on your hard disk. | ||
s. [cyan]Save and quit[/cyan] | ||
q. [cyan]Discard modifications and quit[/cyan] | ||
""" | ||
|
||
while True: | ||
print(prompt) | ||
choice = input("Pick your choice (1, s or q): ").strip() | ||
|
||
if choice == "1": | ||
retrieve_local_source() | ||
elif choice in ("s", "S"): | ||
print( | ||
""" | ||
Saving changes and quitting... | ||
""" | ||
) | ||
return True | ||
|
||
elif choice in ("q", "Q"): | ||
print( | ||
""" | ||
Discarding any change and quitting... | ||
""" | ||
) | ||
return False | ||
|
||
sleep(2) | ||
|
||
|
||
def write_toml_configuration(): | ||
file_path = CONFIG_FILE_PATH | ||
|
||
# Create the directory containing the file, if it does not exist. | ||
file_path.parent.mkdir(parents=True, exist_ok=True) | ||
|
||
with file_path.open("wt") as outf: | ||
outf.write(tomlkit.dumps({"repositories": repositories})) | ||
|
||
print( | ||
f""" | ||
The configuration has been saved into file | ||
"{str(file_path)}" | ||
""" | ||
) | ||
|
||
def extract_location_from_toml(file_path): | ||
with open(file_path, 'r') as file: | ||
data = toml.load(file) | ||
loc = data['repositories'][0]['location'] | ||
return loc | ||
|
||
def main(): | ||
if run_main_loop(): | ||
write_toml_configuration() | ||
if len(repositories) > 0: | ||
print("The following repositories have been configured successfully:") | ||
|
||
table = Table() | ||
table.add_column("Name") | ||
table.add_column("Location") | ||
|
||
for row in repositories: | ||
table.add_row(row["name"], row["location"]) | ||
|
||
print(table) | ||
|
||
else: | ||
print("No repositories have been configured") | ||
|
||
else: | ||
print("Changes have been discarded") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
This file contains 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