Skip to content
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
16 changes: 0 additions & 16 deletions .idea/csv-editor.xml

This file was deleted.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions CODE/Logicytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import psutil
from prettytable import PrettyTable

from logicytics import Log, Execute, Check, Get, FileManagement, Flag, DEBUG, DELETE_LOGS, config
from logicytics import Log, execute, check, get, file_management, flag, DEBUG, DELETE_LOGS, config

# Initialization
log = Log({"log_level": DEBUG, "delete_log": DELETE_LOGS})
Expand Down Expand Up @@ -66,7 +66,7 @@ def __generate_execution_list(self) -> list[str]:
- Logs the final execution list for debugging purposes
- Warns users about potential long execution times for certain actions
"""
execution_list = Get.list_of_files(".", only_extensions=(".py", ".exe", ".ps1", ".bat"),
execution_list = get.list_of_files(".", only_extensions=(".py", ".exe", ".ps1", ".bat"),
exclude_files=["Logicytics.py"],
exclude_dirs=["logicytics", "SysInternal_Suite"])
files_to_remove = {
Expand Down Expand Up @@ -101,7 +101,7 @@ def __generate_execution_list(self) -> list[str]:

elif ACTION == "modded":
# Add all files in MODS to execution list
execution_list = Get.list_of_files("../MODS", only_extensions=(".py", ".exe", ".ps1", ".bat"),
execution_list = get.list_of_files("../MODS", only_extensions=(".py", ".exe", ".ps1", ".bat"),
append_file_list=execution_list, exclude_files=["Logicytics.py"],
exclude_dirs=["logicytics", "SysInternal_Suite"])

Expand Down Expand Up @@ -144,7 +144,7 @@ def __script_handler(script: str) -> tuple[str, Exception | None]:
"""
log.debug(f"Executing {script}")
try:
log.execution(Execute.script(script))
log.execution(execute.script(script))
log.info(f"{script} executed successfully")
return script, None
except Exception as err:
Expand Down Expand Up @@ -207,7 +207,7 @@ def __performance(self):
gc.collect()
start_time = datetime.now()
start_memory = process.memory_full_info().uss / 1024 / 1024 # MB
log.execution(Execute.script(self.execution_list[file]))
log.execution(execute.script(self.execution_list[file]))
end_time = datetime.now()
end_memory = process.memory_full_info().uss / 1024 / 1024 # MB
elapsed_time = end_time - start_time
Expand Down Expand Up @@ -352,7 +352,7 @@ def get_flags():
"""
global ACTION, SUB_ACTION
# Get flags_list
ACTION, SUB_ACTION = Flag.data()
ACTION, SUB_ACTION = flag.data()
log.debug(f"Action: {ACTION}")
log.debug(f"Sub-Action: {SUB_ACTION}")

Expand Down Expand Up @@ -382,7 +382,7 @@ def handle_special_actions():
log.info("Opening debug menu...")
SpecialAction.execute_new_window("_debug.py")

messages = Check.sys_internal_zip()
messages = check.sys_internal_zip()
if messages:
# If there are messages, log them with debug
log.debug(messages)
Expand All @@ -407,7 +407,7 @@ def handle_special_actions():
"Sorry, this feature is yet to be implemented. You can manually Restore your backups, We will open "
"the location for you"
)
FileManagement.open_file("../ACCESS/BACKUP/")
file_management.open_file("../ACCESS/BACKUP/")
input("Press Enter to exit...")
exit(1)

Expand Down Expand Up @@ -438,7 +438,7 @@ def check_privileges():
- Depends on global `DEBUG` configuration variable
- Logs warnings or critical messages based on privilege and UAC status
"""
if not Check.admin():
if not check.admin():
if DEBUG == "DEBUG":
log.warning("Running in debug mode, continuing without admin privileges - This may cause issues")
else:
Expand All @@ -447,7 +447,7 @@ def check_privileges():
input("Press Enter to exit...")
exit(1)

if Check.uac():
if check.uac():
log.warning("UAC is enabled, this may cause issues - Please disable UAC if possible")


Expand All @@ -462,7 +462,7 @@ def files(cls):
@staticmethod
def __and_log(directory: str, name: str):
log.debug(f"Zipping directory '{directory}' with name '{name}' under action '{ACTION}'")
zip_values = FileManagement.Zip.and_hash(
zip_values = file_management.Zip.and_hash(
directory,
name,
ACTION if ACTION is not None else f"ERROR_NO_ACTION_SPECIFIED_{datetime.now().isoformat()}"
Expand Down Expand Up @@ -530,9 +530,10 @@ def Logicytics():
try:
Logicytics()
except KeyboardInterrupt:
log.warning("⚠️ Force shutdown detected! Some temporary files might be left behind.")
log.warning("💡 Pro tip: Next time, let the program finish naturally.")
# TODO v3.4.2 -> Cleanup function
log.warning("Force shutdown detected! Some temporary files might be left behind.")
log.warning("Next time, let the program finish naturally for complete cleanup.")
# Emergency cleanup - zip generated files
ZIP.files()
exit(0)
else:
log.error("This script cannot be imported!")
Expand Down
24 changes: 12 additions & 12 deletions CODE/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import psutil
import requests

from logicytics import Log, DEBUG, VERSION, Check
from logicytics import Log, DEBUG, VERSION, check, config

log_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "ACCESS\\LOGS\\DEBUG\\DEBUG.log")
log = Log({"log_level": DEBUG, "filename": log_path, "truncate_message": False, "delete_log": True})
url = config.get("System Settings", "config_url")


class VersionManager:
Expand Down Expand Up @@ -149,10 +150,9 @@ def get_online_config() -> dict | None:
Retrieves configuration data from a remote repository.
"""
try:
url = "https://raw.githubusercontent.com/DefinetlyNotAI/Logicytics/main/CODE/config.ini"
config = configparser.ConfigParser()
config.read_string(requests.get(url, timeout=15).text)
return config
_config = configparser.ConfigParser()
_config.read_string(requests.get(url, timeout=15).text)
return _config
except requests.exceptions.RequestException as e:
log.error(f"Connection error: {e}")
return None
Expand Down Expand Up @@ -194,27 +194,27 @@ def debug():
Executes a comprehensive system debug routine, performing various checks and logging system information.
"""
# Online Configuration Check
config = ConfigManager.get_online_config()
if config:
HealthCheck.check_versions(VERSION, config["System Settings"]["version"])
_config = ConfigManager.get_online_config()
if _config:
HealthCheck.check_versions(VERSION, _config["System Settings"]["version"])

# File Integrity Check
required_files = config["System Settings"].get("files", "").split(",")
required_files = _config["System Settings"].get("files", "").split(",")
FileManager.check_required_files(".", required_files)

# SysInternal Binaries Check
SysInternalManager.check_binaries("SysInternal_Suite")

# System Checks
log.info("Admin privileges found" if Check.admin() else "Admin privileges not found")
log.info("UAC enabled" if Check.uac() else "UAC disabled")
log.info("Admin privileges found" if check.admin() else "Admin privileges not found")
log.info("UAC enabled" if check.uac() else "UAC disabled")
log.info(f"Execution path: {psutil.__file__}")
log.info(f"Global execution path: {sys.executable}")
log.info(f"Local execution path: {sys.prefix}")
log.info(
"Running in a virtual environment" if sys.prefix != sys.base_prefix else "Not running in a virtual environment")
log.info(
"Execution policy is unrestricted" if Check.execution_policy() else "Execution policy is restricted")
"Execution policy is unrestricted" if check.execution_policy() else "Execution policy is restricted")

# Python Version Check
SystemInfoManager.python_version()
Expand Down
12 changes: 7 additions & 5 deletions CODE/_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import configobj

from logicytics import log, Get, FileManagement, CURRENT_FILES, VERSION
from logicytics import log, get, file_management, CURRENT_FILES, VERSION


def color_print(text, color="reset", is_input=False) -> None | str:
Expand All @@ -21,8 +21,8 @@ def color_print(text, color="reset", is_input=False) -> None | str:
color_code = colors.get(color.lower(), colors["reset"])
if is_input:
return input(f"{color_code}{text}{colors['reset']}")
else:
print(f"{color_code}{text}{colors['reset']}")
print(f"{color_code}{text}{colors['reset']}")
return None


def _update_ini_file(filename: str, new_data: list | str, key: str) -> None:
Expand Down Expand Up @@ -88,6 +88,7 @@ def _prompt_user(question: str, file_to_open: str = None, special: bool = False)
return True
except Exception as e:
color_print(f"[x] {e}", "red")
return None


def _perform_checks() -> bool:
Expand Down Expand Up @@ -116,7 +117,8 @@ def _handle_file_operations() -> None:
Handles file operations and logging for added, removed, and normal files.
"""
EXCLUDE_FILES = ["logicytics\\User_History.json.gz", "logicytics\\User_History.json"]
files = Get.list_of_files(".", exclude_files=EXCLUDE_FILES, exclude_dirs=["SysInternal_Suite"])
files = get.list_of_files(".", exclude_files=EXCLUDE_FILES, exclude_dirs=["SysInternal_Suite"],
exclude_extensions=[".pyc"])
added_files, removed_files, normal_files = [], [], []
clean_files_list = [file.replace('"', '') for file in CURRENT_FILES]

Expand Down Expand Up @@ -187,7 +189,7 @@ def dev_checks() -> None:
- Updates configuration file with current files and version
- Logs warnings or errors during the process
"""
FileManagement.mkdir()
file_management.mkdir()
if not _perform_checks():
return
_handle_file_operations()
Expand Down
6 changes: 4 additions & 2 deletions CODE/bluetooth_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import subprocess
from typing import TextIO

from logicytics import log

Expand Down Expand Up @@ -84,7 +85,7 @@ def _query_bluetooth_devices() -> bool | list[dict[str, str]]:
return device_info_list


def _write_device_info_to_file(devices, filename):
def _write_device_info_to_file(devices: list[dict[str, str]], filename: str):
"""
Writes the details of Bluetooth devices to a specified file.

Expand All @@ -105,11 +106,12 @@ def _write_device_info_to_file(devices, filename):
with open(filename, "w", encoding="UTF-8") as file:
for device_info in devices:
_write_single_device_info(file, device_info)
log.info(f"Successfully wrote device details to '{filename}'")
except Exception as e:
log.error(f"Failed to write device information to file: {e}")


def _write_single_device_info(file, device_info):
def _write_single_device_info(file: TextIO, device_info: dict[str, str]):
"""
Writes detailed information for a single Bluetooth device to the specified file.

Expand Down
44 changes: 5 additions & 39 deletions CODE/bluetooth_logger.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import datetime
import re
import subprocess
from typing import LiteralString

from logicytics import log


# Utility function to log data to a file
def save_to_file(filename, section_title, data):
def save_to_file(filename: str, section_title: str, data: str):
"""
Appends data to a file with a section title.

Expand Down Expand Up @@ -35,7 +36,7 @@ def save_to_file(filename, section_title, data):


# Utility function to run PowerShell commands
def run_powershell_command(command):
def run_powershell_command(command: str) -> None | list[LiteralString]:
"""
Runs a PowerShell command and returns the output as a list of lines.

Expand Down Expand Up @@ -67,7 +68,7 @@ def run_powershell_command(command):


# Unified parsing function for PowerShell output
def parse_output(lines, regex, group_names):
def parse_output(lines: list[LiteralString], regex: str, group_names: list[str]):
"""
Parses the output lines using the provided regex and group names.

Expand Down Expand Up @@ -101,7 +102,7 @@ def parse_output(lines, regex, group_names):


# Function to get paired Bluetooth devices
def get_paired_bluetooth_devices():
def get_paired_bluetooth_devices() -> list[str]:
"""
Retrieves a list of paired Bluetooth devices with their names and MAC addresses.

Expand Down Expand Up @@ -168,41 +169,6 @@ def log_bluetooth():
save_to_file(filename, section_title, paired_devices or ["No paired Bluetooth devices found."])
log.debug(f"{section_title}: {paired_devices}")

# Collect and log event logs
def collect_logs(title: str, command: str):
"""
Collects and logs event logs by executing a PowerShell command and saving the results.

Args:
title (str): The title or description of the log section being collected.
command (str): The PowerShell command to execute for retrieving event logs.

Behavior:
- Runs the specified PowerShell command using `run_powershell_command()`
- Saves the log results to a file using `save_to_file()`
- Logs an informational message about the log collection
- If no logs are found, saves a default "No logs found." message
- Uses the global `filename` variable for log file destination

Raises:
Potential exceptions from `run_powershell_command()` and `save_to_file()` which are handled internally
"""
logs = run_powershell_command(command)
save_to_file(filename, title, logs or ["No logs found."])
log.info(f"Getting {title}...")

collect_logs(
"Bluetooth Connection/Disconnection Logs",
'Get-WinEvent -LogName "Microsoft-Windows-Bluetooth-BthLEServices/Operational" '
'| Select-Object TimeCreated, Id, Message | Format-Table -AutoSize'
)

collect_logs(
"Bluetooth File Transfer Logs",
'Get-WinEvent -LogName "Microsoft-Windows-Bluetooth-BthLEServices/Operational" '
'| Select-String -Pattern "file.*transferred" | Format-Table -AutoSize'
)

log.info("Finished Bluetooth data logging.")


Expand Down
4 changes: 2 additions & 2 deletions CODE/cmd_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from logicytics import log, Execute
from logicytics import log, execute


@log.function
Expand All @@ -17,7 +17,7 @@ def command(file: str, commands: str, message: str, encoding: str = "UTF-8") ->
"""
log.info(f"Executing {message}")
try:
output = Execute.command(commands)
output = execute.command(commands)
with open(file, "w", encoding=encoding) as f:
f.write(output)
log.info(f"{message} Successful - {file}")
Expand Down
Loading