Build Ubuntu utilities using Python

Sohaib Anser
2 min readJun 2, 2023

According to the w3techs stats, nearly 14% of the websites are using Ubuntu Operating System. Most of the developers choose Linux for development and Ubuntu is the most prominent flavor. You can check the official stats of Ubuntu from here. Ubuntu package management system has most of the common utilities but there are always some custom utilities are required for a developer's productivity according to their need. Here you will focused on how we can convert Python script into a usable Ubuntu utility.

CPU and memory(RAM) are the very important information of the system. We will write a Python script to find that information. Then will convert that script to a Ubuntu package.

The above script is using a shell command to get the current CPU usage and psutil to find the current RAM usage.

To build a Ubuntu package setup.py is a very important file. You define all the project configurations in that file. Make that file in your system and copy the following configuration but make sure your project configuration might be different. So make changes in the setup.py according to your project configuration. My project directory structure is as follows.

.
├── LICENSE
├── README.md
├── setup.py
├── system_info
│ ├── cpu_memory_utilization.py
│ └── __init__.py
└── system_utilization.desktop
setup.py

Next, create the system_utilization.desktop file which holds the Debian configuration and is referenced in the setup.py file.

system_utilization.desktop

Go to the setup.py file directory and run the following command to build the Ubuntu package.

python setup.py --command-packages=stdeb.command bdist_deb

There might be some dependencies are required for your system to properly run the above command. After successfully running the above command, the following directories will be created

deb_dist
dist
system_info.egg-info
system_info-1.0.0.tar.gz

Cheers!!! you have successfully created the Ubuntu utility.

Next, we will be looking at how we can install to install the Debian package. Go the deb_dist/ directory and run the following command.

cd deb_dist/
sudo dpkg -i python3-system-info_1.0.0-1_all.deb

You have installed the utility and now run the command from anywhere in the terminal and you will see the CPU and Memory utilization percentage.

system_info
system_info output

If you want to remove that utility run the following command

sudo dpkg --remove python3-system-info

--

--

Sohaib Anser

Backend Engineer, Python, AWS, Committed to making a difference. Follow me on LinkedIn: https://www.linkedin.com/in/muhammad-sohaib-python