Skip to content

Commit

Permalink
fix formatting and add badge
Browse files Browse the repository at this point in the history
  • Loading branch information
rootiest committed Jun 13, 2023
1 parent de040dd commit bf7bbce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@

# PrintCFG Klipper Suite

[![GitHub Super-Linter](https://github.com/rootiest/printcfg/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/marketplace/actions/super-linter)

![header](docs/pretty_header.png)

This set of macros is a full suite of features for Klipper.

It is designed to be fully customizable to fit any printer or configuration. All without having to edit or understand the macros themselves. All configuration for the macros is done in the [user_profile.cfg](profiles/default/variables.cfg) file.

[Documentation is available in the Wiki](https://github.com/rootiest/printcfg/wiki)
## Documentation

### [Documentation is available in the Wiki](https://github.com/rootiest/printcfg/wiki)

## Features

Expand Down
39 changes: 32 additions & 7 deletions src/printcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@
# Set the repo name
REPO = "printcfg"
# Set arguments
ARGUMENTS_LIST = ["help", "install", "restart", "change", "remove", "update", "repair", "branch", "status" ]

ARGUMENTS_LIST = [
"help",
"install",
"restart",
"change",
"remove",
"update",
"repair",
"branch",
"status",
]
# Get the current user name
current_user = getpass.getuser()
user_home = os.path.expanduser("~")
Expand Down Expand Up @@ -78,6 +87,7 @@
handler.setFormatter(formatter)
logger.addHandler(handler)


def show_help():
"""Show the help message."""
logger.info("Showing help message...")
Expand All @@ -94,9 +104,10 @@ def show_help():
logger.info("Help message shown.")
sys.exit(0)


def find_profile(path: str):
"""Find the profile name in the given file."""
logger.debug("Searching for profile name in file: %s",path)
logger.debug("Searching for profile name in file: %s", path)
# Find the profile name (Eg: '# Profile: default' = 'default')
with open(path, "r", encoding="utf-8") as p_file:
for line in p_file:
Expand All @@ -110,6 +121,7 @@ def find_profile(path: str):
logger.error("Profile not found in file: %s", path)
raise ValueError(f"Profile not found in file: {path}")


def normal_ops():
"""Run the script normally."""
logger.info("Starting normal operations...")
Expand All @@ -132,6 +144,7 @@ def normal_ops():
logger.info("Startup script complete, exiting.")
sys.exit(0)


def generate_service():
"""Generate the printcfg service."""
logger.info("Generating %s service...", REPO)
Expand Down Expand Up @@ -162,14 +175,17 @@ def generate_service():
logger.debug("Command output: %s", result.stdout.decode("utf-8"))
if result.returncode != 0:
print(f"Error: The command '{command}' failed with code {result.returncode}.")
logger.error("Error: The command '%s' failed with code %s.", command, result.returncode)
logger.error(
"Error: The command '%s' failed with code %s.", command, result.returncode
)
print(f"Output from command: {result.stdout.decode('utf-8')}")
print(f"Error from command: {result.stderr.decode('utf-8')}")
return
# Exit gracefully
logger.info("%s service generated successfully.", REPO)
sys.exit(0)


def change_profile(profile_name: str):
"""Change the profile."""
# Define the path to the second script
Expand All @@ -194,6 +210,7 @@ def change_profile(profile_name: str):
print(f"Profile changed to {profile_name} successfully.")
sys.exit(0)


def update_printcfg():
"""Update printcfg."""
# Define the path to the second script
Expand All @@ -218,6 +235,7 @@ def update_printcfg():
print(f"{REPO} updated successfully.")
sys.exit(0)


def restart_service(service_name: str):
"""Restarts a systemctl service.
Expand All @@ -239,6 +257,7 @@ def restart_service(service_name: str):
print(f"Error restarting {service_name} service: {err}")
return False


def change_branch(branch_name: str):
"""Changes the branch of the printcfg repo."""
logger.info("Changing to branch '%s'.", branch_name)
Expand All @@ -254,7 +273,9 @@ def change_branch(branch_name: str):
# Start the change branch script
command = ["bash", script_path, profile_name, branch_name]
logger.debug("Executing command: %s", command)
logger.debug("Changing to branch '%s' with profile '%s'.", branch_name, profile_name)
logger.debug(
"Changing to branch '%s' with profile '%s'.", branch_name, profile_name
)
print(f"Changing to branch '{branch_name}' with profile '{profile_name}'.")
try:
subprocess.run(command, check=False)
Expand All @@ -267,6 +288,7 @@ def change_branch(branch_name: str):
print(f"Succesfully changed to branch '{branch_name}'.")
sys.exit(0)


def repair_printcfg():
"""Repairs printcfg."""
# Define the path to the second script
Expand Down Expand Up @@ -338,7 +360,9 @@ def show_status(service_name: str):
logger.debug("Command output: %s", result.stdout.decode("utf-8"))
if result.returncode != 0:
print(f"Error: The command '{command}' failed with code {result.returncode}.")
logger.error("Error: The command '%s' failed with code %s.", command, result.returncode)
logger.error(
"Error: The command '%s' failed with code %s.", command, result.returncode
)
print(f"Output from command: {result.stdout.decode('utf-8')}")
print(f"Error from command: {result.stderr.decode('utf-8')}")
return False
Expand All @@ -348,6 +372,7 @@ def show_status(service_name: str):
logger.info("Status shown successfully.")
return True


if __name__ == "__main__":
# Check if there are any arguments
if len(sys.argv) < 2:
Expand Down Expand Up @@ -424,7 +449,7 @@ def show_status(service_name: str):
else:
logger.info("Running normal operations.")
normal_ops()

# Exit gracefully
logger.info("%s completed successfully.", REPO)
exit(0)

0 comments on commit bf7bbce

Please sign in to comment.