#!/usr/bin/python3

import os, sys
import gettext
from optparse import OptionParser

gettext.install("pearlsources", "/usr/share/pearllinux/locale")

if os.geteuid() != 0:
    print(_("Error: must run as root"))
    sys.exit(1)

usage = "usage: %prog [options] repository"
parser = OptionParser(usage=usage)
parser.add_option("-y", "--yes", dest="forceYes", action="store_true",
    help="force yes on all confirmation questions", default=False)
parser.add_option("-r", "--remove", dest="remove", action="store_true",
    help="Remove the specified repository", default=False)

(options, args) = parser.parse_args()

if (len(args) == 0):
    print(_("Error: need a repository as argument"))
    sys.exit(1)

# Call PearlSources script with exec instead of system so that the exit status
# is returned to the caller
pearlsources = "/usr/lib/pearllinux/PearlSources/PearlSources.py"

yes_arg="-?"
if options.forceYes:
    yes_arg="-y"

remove_arg="-?"
if options.remove:
    remove_arg="-r"

os.execl(pearlsources, pearlsources, "add-apt-repository", yes_arg, remove_arg,