1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/env python3
# software-properties - graphical abstraction of the sources.list
#
# Copyright (c) 2007 Canonical Ltd.
#
# Author: Jonathan Riddell <jriddell@ubuntu.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
import gettext
import os
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import aptsources
from aptsources.sourceslist import SourcesList
#sys.path.append("@prefix@/share/update-manager/python")
from softwareproperties.qt.SoftwarePropertiesQt import SoftwarePropertiesQt
import sip
class OptionParsed:
debug = False
massive_debug = False
no_update = False
enable_component = ""
#--------------- main ------------------
if __name__ == '__main__':
try:
sip.setdestroyonexit(False)
except AttributeError:
pass
_ = gettext.gettext
app = QApplication(sys.argv)
app.setWindowIcon(QIcon.fromTheme("applications-other"))
#FIXME: Workaround for LP: 1315866
# This happens due to the fact that when a Python dict is garbage
# collected the order in which the individual items in the dict are
# garbage collected is unpredictable, causing the dtor's to be called
# after python exits. In order to work around the issue, upstream
# suggested that projects disable the automatic destruction of C++
# instances and C structures
# Ref: http://www.riverbankcomputing.com/pipermail/pyqt/2014-March/033929.html
sip.setdestroyonexit(False)
parser = QCommandLineParser()
parser.addHelpOption()
parser.addVersionOption()
debugOption = QCommandLineOption("debug",
_("Print some debug information to the command line"));
parser.addOption(debugOption);
massiveDebugOption = QCommandLineOption("massive-debug",
_("Print a lot of debug information to the command line"));
parser.addOption(massiveDebugOption);
noUpdateOption = QCommandLineOption("dont-update",
_("No update on repository change (useful if called from an external program)"));
parser.addOption(noUpdateOption);
componentOption = QCommandLineOption("enable-component",
_("Enable the specified component of the distro's repositories"),
"name");
parser.addOption(componentOption);
openTabOption = QCommandLineOption("open-tab",
_("Open specific tab number on startup"),
"open_tab");
parser.addOption(openTabOption);
ppaOption = QCommandLineOption("enable-ppa",
_("Enable PPA with the given name"),
"name");
parser.addOption(ppaOption);
keyServerOption = QCommandLineOption("keyserver",
_("Legacy option, unused"),
"url");
parser.addOption(keyServerOption);
winidOption = QCommandLineOption("attach", _("Win ID to act as a dialogue for"),
"winid");
parser.addOption(winidOption);
dataDirOption = QCommandLineOption("data-dir", _("data directory for UI files"),
"data_dir", "/usr/share/software-properties/");
parser.addOption(dataDirOption);
parser.process(app)
# Check for root permissions
if os.geteuid() != 0:
text = "Please run this software with administrative rights. To do so, run this program with lxqt-sudo or pkexec."
title = "Need administrative powers"
msgbox = QMessageBox.critical(None, title, text)
sys.exit(1)
localesApp="software-properties"
localesDir="/usr/share/locale"
gettext.bindtextdomain(localesApp, localesDir)
gettext.textdomain(localesApp)
afile = ""
options = OptionParsed #FIXME set debug, massive_debug
if len(parser.positionalArguments()) >= 1:
afile = parser.positionalArguments()[0]
afile = str(afile)
options.debug = parser.isSet(debugOption)
options.debug = parser.isSet(massiveDebugOption)
options.no_update = parser.isSet(noUpdateOption)
options.open_tab = parser.value(openTabOption)
attachWinID = None
if parser.isSet(winidOption):
attachWinID = parser.value(winidOption)
# datadir has a default value, so always read it
data_dir = parser.value(dataDirOption)
if parser.isSet(ppaOption):
app = SoftwarePropertiesQt(datadir=data_dir, options=options, file=afile)
options.enable_ppa = parser.value(ppaOption)
app.add_source_from_line("ppa:%s" % options.enable_ppa)
app.sourceslist.save()
elif parser.isSet(componentOption) == True:
sourceslist = SourcesList()
options.enable_component = parser.value(componentOption)
distro = aptsources.distro.get_distro()
distro.get_sources(sourceslist)
distro.enable_component(options.enable_component)
sourceslist.save()
print("Enabled the %s component" % options.enable_component)
else:
app = SoftwarePropertiesQt(datadir=data_dir, options=options, file=afile, attachWinID=attachWinID)
app.run()
sys.exit(app.modified_sourceslist)
|