Table of contents
Developing BPM Packages
Developing BPM packages is very fun and rewarding. They are very easy to program (if you know basic python), and quick to install.
BPM packages are, at its core, a zip file containing a txt file of command aliases (aliases.txt) and the script itself. This makes the creation of packages accessible to anyone, and makes debugging packaged scripts easy.
General Script Format
A script must be structured with several components. Must-includes are the main() function that must take specific arguments (see below), and a parser to parse those arguments. These are very easy to create and structure. Adaptation of existing scripts should be relatively simple.
main() Function
BUGPy script execution requires that a function called main() exist, and that it takes a list of arguments that are passed by the user when the script was executed. This function is the code that is going to be run when the program is started.
It must accept one argument in the form of an array. This array is the list of arguments passed by the user when the command is run (See "Arguments" for more information).
An example of a basic "Hello World" script would look like this:
def main(args)
print("Hello World")
Note
If you are adapting a script, move everything from
if __name__ == "__main__"to a newmain(args)block.
Arguments
Arguments are anything additional a user adds to a script when it is executed. For example, if the user runs mv file.txt movie.mp4 code.py folder, everything after mv is an argument. Arguments are separated by spaces and passed as a single array of strings to the script's main() function. In the example, the arguments passed to the script is in the form ["file.txt", "movie.mp4", "code.py", "folder"]. If nothing was passed (e.g. only mv was run), the arguments passed would be [].
As a developer, a good idea is to make an if/else statement
from pathlib import Path
from . import color_print
def main(args):
# Set the directory path
script_dir = Path(__file__).resolve().parent
dir_path = Path("")
# Use the current script's directory or specify a path
base_path = Path(__file__).resolve().parent
if args == []:
for entry in dir_path.iterdir():
if entry.is_dir():
color_print.cprint(f"[FOLDER] {entry.name}", "DARKBLUE")
elif entry.is_file():
print(f"[FILE] {entry.name}")
print()
elif "--help" in args or "-h" in args:
print("""
LIST FILES
Usage:
list_files [flags]
Flags:
-h: this help section
Notes:
A program to list the folders and files in the current directory.
""")
else:
print("list_files: Invalid arguments, try using none?")
Lets say you have this script called script.py and you want the user to type script1 or hellolol to launch it while in BUGPy.
You must first create an aliases.txt and fill it with the following content:
script1: script
hellolol: script
where each line is in the format of alias: script_name, where script_name is the name of your script without extension, and alias is the alias.
Now, you must zip the file and
then you bpm install foo_bar.zip
Also include an example script like list_files.py here