Skip to content

Instantly share code, notes, and snippets.

@robert-ancell
Created November 14, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert-ancell/b84df04768c526471f5f7d88f2e32243 to your computer and use it in GitHub Desktop.
Save robert-ancell/b84df04768c526471f5f7d88f2e32243 to your computer and use it in GitHub Desktop.
Get some statistics from GNOME Settings (aka gnome-control-center)
import os
def count_lines (filename):
f = file (filename)
count = 0
for line in f.readlines ():
if not line.isspace ():
count += 1
return count
def pretty_branch_name (name):
if name.startswith ('gnome-'):
return name[6:].replace ('-', '.')
else:
return name
class BranchStats:
def __init__ (self, name):
self.name = name
self.files = []
self.c_lines = 0
self.h_lines = 0
self.ui_lines = 0
self.build_files = []
self.image_files = []
self.audio_files = []
self.data_files = []
self.unknown_files = []
def add_file (self, filename):
self.files.append (filename)
def analyse (self):
for f in self.files:
(dir, basename) = os.path.split (f)
(_, ext) = os.path.splitext (basename)
if ext == '.c':
self.c_lines += count_lines (f)
elif ext == '.h' or basename.endswith ('.h.in'):
self.h_lines += count_lines (f)
elif ext == '.ui':
self.ui_lines += count_lines (f)
elif basename in [ 'meson.build', 'Makefile.am', 'COPYING', 'LINGUAS', 'README', 'TODO' ] or \
basename.endswith ('.gresource.xml') or \
ext in [ '.its', '.loc', '.pro', '.py', '.rb', '.sh' ] or \
basename == 'test-hostname':
self.build_files.append (f)
elif ext in [ '.jpg', '.png', '.svg' ]:
self.image_files.append (f)
elif ext in [ '.ogg' ]:
self.audio_files.append (f)
elif basename.endswith ('.desktop.in') or basename.endswith ('.desktop.in.in') or \
basename.endswith ('.directory.in') or \
basename.endswith ('.menu.in') or \
basename.endswith ('.policy.in') or basename.endswith ('.policy.in.in') or \
basename.endswith ('.service.in') or basename.endswith ('.service.in.in') or \
basename.endswith ('.xml.in') or basename.endswith ('.xml.in.in') or \
basename.endswith ('.pc.in') or \
ext in [ '.css', '.ini', '.list', '.menu', '.po', '.rules', '.txt', '.xml'] or \
basename == 'gnome-control-center.in' or \
f.endswith ('datetime/backward'):
self.data_files.append (f)
elif basename.endswith ('~') or ext in [ '.patch' ]:
pass # Skip
else:
print ('!', f)
self.unknown_files.append (f)
class Section:
def __init__ (self, name):
self.name = name
self.branches = []
def pretty_name (self):
return self.name[0].upper () + self.name[1:]
def get_branch (self, name):
for branch in self.branches:
if branch.name == name:
return branch
branch = BranchStats (name)
self.branches.append (branch)
return branch
sections = []
def get_section (name):
for section in sections:
if section.name == name:
return section
section = Section (name)
sections.append (section)
sections.sort (key = lambda section: section.name)
return section
def analyse ():
for (root, dirs, files) in os.walk ('.'):
# Ignore top files
if root == '.':
continue
# We're only interested in files
if len (files) == 0:
continue
dir_names = root.split ('/')
dir0 = dir_names[1]
# Ignore stuff that we're not interested in
if dir0 in [ '.git', '.gitlab', 'build-aux', 'data', 'docs', 'gettext', 'help', 'm4', 'man', 'po', 'subprojects' ]:
continue
if dir0 == 'panels':
if len (dir_names) > 2:
name = dir_names[2]
else:
continue
elif dir0 in [ 'libgnome-control-center', 'search-provider', 'shell', 'tests' ]:
name = dir0
else:
print ('!', root, files)
continue
section = get_section (name)
b = section.get_branch (branch)
for f in files:
b.add_file (root + '/' + f)
branches = ['gnome-3-0', 'gnome-3-2', 'gnome-3-4', 'gnome-3-6', 'gnome-3-8',
'gnome-3-10', 'gnome-3-12', 'gnome-3-14', 'gnome-3-16', 'gnome-3-18',
'gnome-3-20', 'gnome-3-22', 'gnome-3-24', 'gnome-3-26', 'gnome-3-28',
'gnome-3-30', 'master']
for branch in branches:
os.system ('git checkout ' + branch)
analyse ()
for section in sections:
section.get_branch (branch).analyse ()
def cmp_sections (s1, s2):
b1 = s1.get_branch ('master')
b2 = s2.get_branch ('master')
l1 = b1.c_lines + b1.h_lines + b1.ui_lines
l2 = b2.c_lines + b2.h_lines + b2.ui_lines
return l1 - l2
sections.sort (cmp_sections)
def csv_string (text):
return '="' + text + '"'
csv_data = csv_string ('GNOME Settings Panel Breakdown') + '\n'
csv_data += csv_string ('Release')
for s in sections:
csv_data += ',' + csv_string (s.pretty_name ())
csv_data += '\n'
for branch in branches:
csv_data += csv_string (pretty_branch_name (branch))
for s in sections:
b = s.get_branch (branch)
csv_data += ',' + str (b.c_lines + b.h_lines + b.ui_lines)
csv_data += '\n'
file ('gcc-panel-breakdown.csv', 'w').write (csv_data)
csv_data = csv_string ('GNOME Settings Code Breakdown') + '\n'
csv_data += csv_string ('Release') + ',' + csv_string ('GtkBuilder') + ',' + csv_string ('C Code') + ',' + csv_string ('C Headers') + '\n'
for branch in branches:
c_lines = 0
h_lines = 0
ui_lines = 0
for s in sections:
b = s.get_branch (branch)
c_lines += b.c_lines
h_lines += b.h_lines
ui_lines += b.ui_lines
csv_data += csv_string (pretty_branch_name (branch)) + ',' + str (ui_lines) + ',' + str (c_lines) + ',' + str (h_lines) + '\n'
file ('gcc-code-breakdown.csv', 'w').write (csv_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment