~elementary-os/ubuntu-package-imports/software-properties-bionic

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