#!/usr/bin/python
import os
from subprocess import *
if __name__ == "__main__":
    # Get list of valid locales from locale -a
    try:
        p1 = Popen(['locale', '-a'], stdout=PIPE)
        p2 = Popen(['grep', '-v', 'POSIX'], stdin=p1.stdout, stdout=PIPE)
        lines = Popen(['grep', '-v', '^C$'], stdin=p2.stdout,
                      stdout=PIPE).communicate()[0]
    except OSError:
        print "ERROR"
        os.exit(0)
    langs = [lang[:-1].split('.')[0] for lang in lines.split(None)]
    for lang in langs:
        print lang
    print
    try:
        lines = Popen(['update-alternatives', '--list', 'x-session-manager'],
                      stdin=p2.stdout, stdout=PIPE).communicate()[0]
    except OSError:
        print "ERROR"
        os.exit(0)
    for line in lines.split(None):
        print line
