Skip to content
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

Refactor & clean-up #39

Merged
merged 7 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions brib.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,16 @@
print(language_module.browser + browser)
# gets the version of Alfred
version = versionToPass
# Initialize the encryption key and cipher suite
encryption_key = generate_encryption_key()
cipher_suite = create_cipher(encryption_key)
# gets the info to encrypt
syskey = (
platform.system()
+ platform.release()
+ "-AlfredVer-"
+ version
+ "-"
+ platform.python_version()
+ "-"
+ browser
+ language_code
)
sys_info = f"{platform.system()}{platform.release()}-AlfredVer-{version}-{platform.python_version()}-{browser}{language_code}"
# encrypts the key
encrypted_text = encrypt(syskey)
encrypted_sys_info = encrypt_text(cipher_suite, sys_info)
print(language_module.encrypt1)
# logs the key
saveInfo(config, encrypted_text)
save_encryption_info(config, encryption_key, encrypted_sys_info)
# this prints the start up screen and passes the verion varaible in
logo(colorScheme, "", version, config)
# does config stuff
Expand Down Expand Up @@ -301,7 +294,7 @@
# prints ui stuff
print(Fore.GREEN + f"{language_module.scan1}" + uname + Fore.RESET)
print("===========================================================")
if webscrape == True:
if webscrape:
print(Fore.RED + language_module.note + Fore.RESET + language_module.warning2)
print("===========================================================")
print("")
Expand Down
204 changes: 107 additions & 97 deletions modules/configcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
#
def configC(language_module):
# checks if the nesasary files exist
if os.path.exists("./config/config.ini") == True:
if os.path.exists("./config/config.ini"):
print(language_module.config1)
else:
# If not found, alert the user and attempt to update
print(language_module.error5)
time.sleep(4)
with open("./config/version.cfg", "w") as f:
f.write(language_module.status3)
exec(open("./update.py").read())

if os.path.exists("./update.py") == True:

# Check if update.py script exists
if os.path.exists("./update.py"):
print(language_module.config2)
else:
print(language_module.error5)
Expand All @@ -35,19 +37,19 @@ def configC(language_module):
version = fp.read()
return version


# Get the color scheme from the config file
def colorSchemeGrabber(config):
print("Grabbing Color Configuration")
try:
config.read("config/config.ini")
color = config.get("Personalizations", "colorScheme").upper()
color_code = getattr(Fore, color)
return color_code
except:
print("Could not read configuration file")
return "RED"

except configparser.Error as e:
print(f"Could not read configuration file: {e}")
return Fore.RED

# Delete __pycache__ directories
def delete_pycache(root_dir):
"""
Recursively searches for and deletes __pycache__ folders within the specified directory.
Expand All @@ -63,120 +65,129 @@ def delete_pycache(root_dir):
# Delete the __pycache__ folder
shutil.rmtree(pycache_path)

# Ask user about update checks
def ask_update_check(config, colorScheme, language_module):
try:
cfu = input(language_module.config4)
if cfu.lower() in ("y", "yes"):
exec(open("./update.py").read())
elif cfu.lower() in ("n", "no"):
print(language_module.prompt5)
print_separator()
else:
print(language_module.idk2)
print_separator()
except KeyboardInterrupt:
outstanding_config_updates(config)
exit(1)

# Prompt user at random to enable updates
def random_enable_updates(config, language_module):
getNum = random.randint(1, 10)
# asks the user if they want to enable updates
if getNum == 7 and config.get("main", "checkforupdates") == "no":
changeconfig = input("Updates Are Disabed. Wanna Renable Them? [y/n]: ⤷ ")
# pharses it
if changeconfig.lower() in ("y", "yes"):
config.set("main", "checkforupdates", "yes")
print(language_module.updates)
save_config(config)
elif changeconfig.lower() in ("n", "no"):
print(language_module.prompt5)
else:
print(language_module.idk2)

# Process various config-related tasks
def configUpdateStuff(colorScheme, config, browser, language_module, argument):
config.read("./config/config.ini")
# this is just something Alfred can use to return something when it needs to return nothing
holder = 0
print_first_launch_messages(config, colorScheme, language_module)
decide_random_events(config, colorScheme, language_module)
is_first_launch(config, browser, language_module)

# Handle arguments to prevent update prompts
if any(vars(argument).values()):
return

# checks to see if the user is running a Pre or if its Alfreds first launch.
if config.get("main", "checkforupdates") == "yes":
ask_update_check(config, colorScheme, language_module)

random_enable_updates(config, language_module)
display_random_tip(config, language_module)

# Display a random tip if enabled in config
def display_random_tip(config, language_module):
if config.get("Personalizations", "showtips") == "yes":
# this gets the random tip to display on the screen
randomTip = random.choice(open("./config/tips.txt").readlines())
print(randomTip)

# Check if this is the first application launch
def is_first_launch(config, browser, language_module):
if config.get("main", "firstlaunch") == "yes":
outstanding_config_updates(config, browser)

# Perform outstanding config updates
def outstanding_config_updates(config, browser=None):
if browser and browser == "MSEdgeHTM":
config.set("main", "browser", "Edge")
config.set("main", "firstlaunch", "no")
save_config(config)

# Make random decisions/events at app launch
def decide_random_events(config, colorScheme, language_module):
x = random.randint(1, 4)
if x == 3:
print(language_module.prompt3)
elif x == 2:
print(language_module.prompt4)

# Print messages on the first launch
def print_first_launch_messages(config, colorScheme, language_module):
if config.get("main", "firstlaunch") == "yes":
print(
colorScheme + language_module.note + Fore.RESET + language_module.warning3
)
print("")
print()
if config.get("main", "prerelease") == "yes":
print(
colorScheme + language_module.note + Fore.RESET + language_module.warning4
)
print(language_module.prompt2)
print("")
# this is the function to update the code
x = random.randint(1, 4)
if x == 3 and config.get("main", "checkforupdates") == "yes":
print(language_module.prompt3)
if x == 2:
print(language_module.prompt4)
# desides if arguments are being used. if so, it wont ask to update.
if any(vars(argument).values()):
holder = 1
else:
if config.get("main", "checkforupdates") == "yes":
try:
cfu = input(language_module.config4)
if "Y" in cfu or "y" in cfu:
exec(open("./update.py").read())
elif "N" in cfu or "n" in cfu:
print(language_module.prompt5)
print(
Fore.RESET
+ """
===========================================================================
"""
)
else:
print(language_module.idk2)
print(
Fore.RESET
+ """
print()

# Print a separator in command line interface
def print_separator():
print(
Fore.RESET
+ """
===========================================================================
"""
)
except KeyboardInterrupt:
config.set("main", "firstlaunch", "no")
if browser == "MSEdgeHTM":
browser = "Edge"
config.set("main", "browser", browser)
with open("./config/config.ini", "w") as f:
config.write(f)
exit(1)
getNum = random.randint(1, 10)
if any(vars(argument).values()):
holder = 1
else:
# asks the user if they want to enable updates
if config.get("main", "checkforupdates") == "no":
if getNum == 7:
changeconfig = input(
"Updates Are Disabed. Wanna Renable Them? [y/n]: ⤷ "
)
# pharses it
if "Y" in changeconfig or "y" in changeconfig:
config.set("main", "checkforupdates", "yes")
print(language_module.updates)
with open("./config/config.ini", "w") as f:
config.write(f)
elif "N" in changeconfig or "n" in changeconfig:
print(language_module.prompt5)
else:
print(language_module.idk2)

if config.get("main", "firstlaunch") == "yes":
config.set("main", "firstlaunch", "no")
if browser == "MSEdgeHTM":
browser = "Edge"
config.set("main", "browser", browser)
with open("./config/config.ini", "w") as f:
config.write(f)

if (
getNum == 3
or getNum == 5
and config.get("Personalizations", "showtips") == "yes"
):
# this gets the random tip to display on the screen
randomTip = random.choice(open("./config/tips.txt").readlines())
print(randomTip)
"""
)

# Save the updated configuration
def save_config(config):
with open("./config/config.ini", "w") as f:
config.write(f)

# Print system keys from configuration
def syskeys(config):
print("Here are your system keys.")
print(str(config.get("main", "privatekey")))
print(str(config.get("main", "syscrypt")))


# Get global default download path from configuration
def globalPath(config):
config.read("./config/config.ini")
path = config.get("main", "defaultDlPath")
return path


# Clearing directory contents
def dirDump(mydir):
filelist = [f for f in os.listdir(mydir)]
for f in filelist:
os.remove(os.path.join(mydir, f))


# Create needed folders on startup
def create_folders(folder_list, language_module):
for folder in folder_list:
if not os.path.exists(folder):
Expand All @@ -186,7 +197,7 @@ def create_folders(folder_list, language_module):
print(f"{language_module.config8}{folder}")


# this is the module that edits the configuration file. needs to be cleaned up tho
# VALID_CHOICES holds possible valid inputs for configuration
VALID_CHOICES = {
"checkforupdates": ["yes", "no"],
"showtips": ["yes", "no"],
Expand All @@ -196,7 +207,7 @@ def create_folders(folder_list, language_module):
"colorscheme": ["RED", "GREEN", "BLUE", "WHITE", "YELLOW", "BLACK"],
}


# Display config options
def display_options(config, section, language_module):
print("Options:")
print("=====================================================")
Expand All @@ -215,13 +226,12 @@ def display_options(config, section, language_module):
print(f"{language_module.configOptionB} ")
print("=====================================================")


# Update configuration with new values
def update_config(config, section, option_key, new_value):
config.set(section, option_key, str(new_value))
with open("./config/config.ini", "w") as f:
config.write(f)

save_config(config)

# Editor function to modify config settings
def config_editor(config, language_module):
selected_option_key = {
"1": ("main", "checkforupdates"),
Expand Down
Loading