Amount of code developed by Purism for the Librem 5 phone

I was curious how much code Purism has developed for the Librem 5 phone, so I wrote a little Python script that downloads the source code from the projects that Purism started, runs the code through cloc to count lines of code, and then sums the total.

Here is what I get:

$ python3 locPurism.py
Lines of code in Purism projects for the Librem 5:
	libhandy: 47730
	libadwaita: 51270
	calls: 20745
	chatty: 49661
	squeekboard: 17993
	libcall-ui: 4426
	phoc: 15277
	phosh: 48301
	feedbackd: 5970
	feedbackd-device-themes: 603
	gtherm: 1734
	haegtesse: 2105
	wys: 2442
Total lines of code: 268257

This excludes PO translation files and Markdown documentation files. Of course, a number of people outside of Purism have contributed to these projects, such as the GNOME community, Mobian, postmarketOS, etc., but I would guesstimate that to only be about 10% of the total. This only includes the projects that Purism created (although phoc and squeekboard did inherit some code from rootston and eekboard, respectively*). If we include all the code that Purism has contributed to other projects (such as the Linux kernel, wlroots, ModemManager, GeoClue, GTK, and roughly 20 GTK/GNOME apps), the total lines of code would be significantly higher.

Over a quarter of a million lines of code is a pretty big contribution to the Linux ecosystem. When we consider that Purism is providing a way for the GTK/GNOME ecosystem to run on mobile devices and Phosh is now packaged in most of the major distro families except Gentoo, Purism is making a significant contribution to Linux as a whole. Because of Purism’s dev work, Debian->Ubuntu->Mint, Fedora, openSUSE and Arch->Manjaro will be able to run on mobile devices that are supported by the Linux kernel.

Of course, KDE Plasma Mobile and Lomiri are working on the same goal, but Phosh got packaged faster in many of the major distros, because it was designed as a thin overlay on top of a desktop stack, so it is easier to integrate into the desktop distros. Even people who use desktop GTK/GNOME are seeing the benefits of libhandy/libadwaita since it makes their software more adaptive and touch-friendly. Calls and Chats/Chatty are also going to be useful for many desktop users as well.

I thought I would mention this, because I see a lot of people bashing Purism on the Purism forum and r/Purism lately, so it is important to keep in mind the positives, and not only focus on the negatives.

Below is the script, just in case anyone wants to run it in the future to see how much code has been added. If you want all the gory details, run it as:
python3 locPurism.py -d

# locPurism.py counts lines of code developed by Purism for the Librem 5
# Shows details from cloc with the "-d" option: python3 locPurism.py -d
#
# Author: Amos Batto <amosbatto@yahoo.com>
# License: public domain 
# Requires Python 3.6 or later. Needs the "cloc" package installed. In Debian family: sudo apt install cloc

import shutil, subprocess, tempfile, re, os, os.path, sys
from urllib.request import urlretrieve
from urllib.parse import urlparse

projectUrls = {
	"libhandy"   : "https://gitlab.gnome.org/GNOME/libhandy/-/archive/master/libhandy-master.tar.bz2",
	"libadwaita" : "https://gitlab.gnome.org/GNOME/libadwaita/-/archive/main/libadwaita-main.tar.bz2",
	"calls"      : "https://gitlab.gnome.org/GNOME/calls/-/archive/master/calls-master.tar.bz2",
	"chatty"     : "https://source.puri.sm/Librem5/chatty/-/archive/master/chatty-master.tar.bz2",
	"squeekboard": "https://gitlab.gnome.org/World/Phosh/squeekboard/-/archive/master/squeekboard-master.tar.bz2",
	"libcall-ui" : "https://gitlab.gnome.org/World/Phosh/libcall-ui/-/archive/main/libcall-ui-main.tar.bz2",
	"phoc"       : "https://gitlab.gnome.org/World/Phosh/phoc/-/archive/master/phoc-master.tar.bz2",
	"phosh"      : "https://gitlab.gnome.org/World/Phosh/phosh/-/archive/main/phosh-main.tar.bz2",
	"feedbackd"  : "https://source.puri.sm/Librem5/feedbackd/-/archive/master/feedbackd-master.tar.bz2",
	"feedbackd-device-themes": "https://source.puri.sm/Librem5/feedbackd-device-themes/-/archive/master/feedbackd-device-themes-master.tar.bz2",
	"gtherm"     : "https://source.puri.sm/Librem5/gtherm/-/archive/master/gtherm-master.tar.bz2",
	"haegtesse"  : "https://source.puri.sm/Librem5/haegtesse/-/archive/master/haegtesse-master.tar.bz2",
	"wys"        : "https://source.puri.sm/Librem5/wys/-/archive/master/wys-master.tar.bz2" 
}

def main():
	print("Lines of code in Purism's projects for the Librem 5:")
	
	totalLoc = 0; #running total of lines of code
	
	for projName, projUrl in projectUrls.items():
		
		tmpDir = tempfile.mkdtemp(prefix="loc-")
		
		a = urlparse(projUrl) 
		compressedFilename = os.path.basename(a.path)
		pathToFileName = os.path.join(tmpDir, compressedFilename)  
		fileName, headers = urlretrieve(projUrl, filename = pathToFileName)
		
		#Get the LOC sum:
		output = subprocess.check_output(["cloc", "--exclude-lang=Markdown,PO File", fileName])
		found = re.search( r'^SUM:.*?\s+(\d+)$', output.decode('utf-8'), re.M)
		
		if found:
			loc = int(found.group(1))
			totalLoc += loc
		else:
			print(f"Error: no SUM of the lines of code in {projName}.")
			sys.exit();
		
		if "-d" in sys.argv[1:] :
			print(projName)
			os.system("cloc --exclude-lang='PO File,Markdown' " + fileName); 
			print('');
		else:
			print(f"\t{projName}: {loc}")
		
		shutil.rmtree(tmpDir) 
	
	print("Total lines of code: " + str(totalLoc));
 
 
if __name__ == "__main__":
	main()

* The Purism devs posted graphs of when lines of code were added to phoc and to squeekboard. Eyeballing those two graphs, it looks like roughly 25% (4.5/18) of phoc’s code comes from rootston and 9% (1/11) of squeekboard’s code comes from eekboard.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s