Skip to content

Commit

Permalink
[Release] Merge pull request #10 from Smilin-Dominator/Add-directory-…
Browse files Browse the repository at this point in the history
…aliases

Added A System That Keeps Directory Aliases
  • Loading branch information
Smilin-Dominator authored Nov 11, 2021
2 parents b410fbf + d89eed4 commit a31fe64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
13 changes: 9 additions & 4 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def first_time_check():
setup()


def config() -> str:
def config() -> [str, tuple]:

def update():
number = ar['update_check_frequency']
Expand Down Expand Up @@ -52,21 +52,26 @@ def write(file: Path, contents: str):
try:
if ar['update_check_frequency'] != 0:
update()
return ar['default_dir']
return ar['default_dir'], ar['aliases']
except KeyError:
error("There's been an unsatisfied option, rebuilding config")
conf.write_config()


if __name__ == "__main__":
default = config()
default, aliases = config()
directory = ""
try:
if len(argv) < 2:
directory = default
chdir(directory)
else:
directory = argv[1]
for entry in aliases:
if entry['Name'] == argv[1]:
directory = entry['Directory']
break
else:
directory = argv[1]
chdir(directory)
except FileNotFoundError:
error(f"Directory '{directory}' Not Found!")
Expand Down
28 changes: 21 additions & 7 deletions functions/configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from config import print, input, warning
from config import info, input, warning
from pathlib import Path
from json import loads, dumps

Expand All @@ -18,19 +18,33 @@ def write_config(self) -> None:
choice = input("\tDefault Directory (goes here if no args are given)", override="orange1")
config.__add__("default_dir", choice)

info("Add Your Directory Aliases Below (Ctrl+C when Done)")
aliases = []
while True:
try:
temp_dict = {
"Name": input("\tName", override="pale_turquoise1"),
"Directory": input("\tDirectory", override="gold3")
}
aliases.append(temp_dict)
except KeyboardInterrupt:
break
config.__add__("aliases", aliases)

config_file = open(self.file, "w+")
json_dump = dumps(config.__get__(), indent=4)
config_file.write(json_dump)
config_file.flush()
config_file.close()

def parse_config(self) -> dict:
try:
config_file = open(self.file, "r")
return loads(config_file.read())
except FileNotFoundError:
warning("No Config File Found, Making One")
self.write_config()
while True:
try:
config_file = open(self.file, "r")
return loads(config_file.read())
except FileNotFoundError:
warning("No Config File Found, Making One")
self.write_config()

class WriteJSON(object):

Expand Down

0 comments on commit a31fe64

Please sign in to comment.