2
2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
4
# Copyright (c) 2004-2008 Canonical
4
# Copyright (c) 2004-2013 Canonical
6
# Author: Michael Vogt <mvo@debian.org>
6
# Authors: Michael Vogt <mvo@debian.org>
7
# Michael Terry <michael.terry@canonical.com>
8
9
# This program is free software; you can redistribute it and/or
9
10
# modify it under the terms of the GNU General Public License as
405
def get_ubuntu_flavor():
408
def get_ubuntu_flavor(cache=None):
406
409
""" try to guess the flavor based on the running desktop """
407
410
# this will (of course) not work in a server environment,
408
411
# but the main use case for this is to show the right
410
# TODO: actually examine which meta packages are installed, like
411
# DistUpgrade/DistUpgradeCache.py does and use that to choose a flavor.
412
denv = os.environ.get("DESKTOP_SESSION", "")
417
elif "xfce" in denv or "xubuntu" in denv:
419
elif "LXDE" in denv or "Lubuntu" in denv:
421
# default to ubuntu if nothing more specific is found
425
def get_ubuntu_flavor_name():
426
flavor = get_ubuntu_flavor()
427
if flavor == "kubuntu":
429
elif flavor == "xubuntu":
431
elif flavor == "lubuntu":
413
pkg = get_ubuntu_flavor_package(cache=cache)
414
return pkg.split('-', 1)[0]
417
def _load_meta_pkg_list():
418
# This could potentially introduce a circular dependency, but the config
419
# parser logic is simple, and doesn't rely on any UpdateManager code.
420
from DistUpgrade.DistUpgradeConfigParser import DistUpgradeConfig
421
parser = DistUpgradeConfig('/usr/share/ubuntu-release-upgrader')
422
return parser.getlist('Distro', 'MetaPkgs')
425
def get_ubuntu_flavor_package(cache=None):
426
""" try to guess the flavor metapackage based on the running desktop """
427
# From spec, first if ubuntu-desktop is installed, use that.
428
# Second, grab first installed one from DistUpgrade.cfg.
429
# Lastly, fallback to ubuntu-desktop again.
430
meta_pkgs = ['ubuntu-desktop']
433
meta_pkgs.extend(sorted(_load_meta_pkg_list()))
434
except Exception as e:
435
print('Could not load list of meta packages:', e)
439
for meta_pkg in meta_pkgs:
440
cache_pkg = cache[meta_pkg] if meta_pkg in cache else None
441
if cache_pkg and cache_pkg.is_installed:
443
return 'ubuntu-desktop'
446
def get_ubuntu_flavor_name(cache=None):
447
""" try to guess the flavor name based on the running desktop """
448
pkg = get_ubuntu_flavor_package(cache=cache)
449
lookup = {'ubuntustudio-desktop': 'Ubuntu Studio'}
452
elif pkg.endswith('-desktop'):
453
return capitalize_first_word(pkg.rsplit('-desktop', 1)[0])
454
elif pkg.endswith('-netbook'):
455
return capitalize_first_word(pkg.rsplit('-netbook', 1)[0])
437
460
# Unused by update-manager, but still used by ubuntu-release-upgrader
549
def capitalize_first_word(string):
550
""" this uppercases the first word's first letter
552
if len(string) > 1 and string[0].isalpha() and not string[0].isupper():
553
return string[0].capitalize() + string[1:]
557
def get_package_label(pkg):
558
""" this takes a package synopsis and uppercases the first word's
561
name = GLib.markup_escape_text(getattr(pkg.candidate, "summary", ""))
562
return capitalize_first_word(name)
526
565
if __name__ == "__main__":
527
566
#print(mirror_from_sources_list())
528
567
#print(on_battery())