3
# Ubuntu Tweak - PyGTK based desktop configure tool
5
# Copyright (C) 2007-2008 TualatriX <tualatrix@gmail.com>
7
# Ubuntu Tweak is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# Ubuntu Tweak is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with Ubuntu Tweak; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
3
# Copyright (C) 2007-2010 TualatriX <tualatrix@gmail.com>
5
# The class AptAuth is modified from softwareproperty. Author: Michael Vogt <mvo@debian.org>
6
# The original file is: softwareproperties/AptAuth.py
8
# Copyright (c) 2004 Canonical
23
12
sys.setdefaultencoding('utf8')
28
19
import dbus.service
29
20
import dbus.mainloop.glib
34
27
from subprocess import PIPE
35
28
from aptsources.sourceslist import SourceEntry, SourcesList
36
29
from ubuntutweak.backends import PolicyKitService
30
from ubuntutweak.common.systeminfo import module_check
40
#This class is modified from softwareproperty. Author: Michael Vogt <mvo@debian.org>
34
log = logging.getLogger('Daemon')
36
PPA_KEY = '''-----BEGIN PGP PUBLIC KEY BLOCK-----
39
mI0ESXTUHwEEAMtdNPmcgQcoPN3JcUcRrmdm1chJSmX6gj28OamOgE3Nxp3XgkDdg/vLFPv6
40
Tk8zIMxQnvuSpuG1YGp3x8atcKlQAlEHncAo27Vlio6pk8jG+qipDBKq7X7FyXE6X9Peg/k7
41
t7eXMLwH6ZJFN6IEmvPRTsiiQEd/dXRRuIRhPHirABEBAAG0G0xhdW5jaHBhZCBQUEEgZm9y
42
IFR1YWxhdHJpWIi2BBMBAgAgBQJJdNQfAhsDBgsJCAcDAgQVAggDBBYCAwECHgECF4AACgkQ
43
avDhlAYkoiC8mAQAmaxr4Kw/R2WZKde7MfbTPy7O9YoL/NQeThYGwxX6ICVr0IZUj9nxFQ/v
44
tmhZ59p53bpdR8jpPXjdDwjZIIlxTf72Fky6Ri3/zsC4YRD6idS4c4L50dTy74W6IabCt8GQ
45
LtJy5YASlEp5OGwRNptRSFxVE59LuOPRo2kvLIAa0Dc=
47
-----END PGP PUBLIC KEY BLOCK-----'''
42
50
def __init__(self):
43
51
self.gpg = ["/usr/bin/gpg"]
92
100
list = SourcesList()
101
# cache = apt.Cache()
102
PPA_URL = 'ppa.launchpad.net'
103
stable_url = 'http://ppa.launchpad.net/tualatrix/ppa/ubuntu'
94
def __init__ (self, bus):
107
def __init__ (self, bus, mainloop):
95
108
bus_name = dbus.service.BusName(INTERFACE, bus=bus)
96
109
PolicyKitService.__init__(self, bus_name, PATH)
110
self.mainloop = mainloop
112
def __setup_non_block_io(self, io):
114
file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL)
115
fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY)
117
@dbus.service.method(INTERFACE,
118
in_signature='sb', out_signature='b',
119
sender_keyword='sender')
120
def set_source_enable(self, url, enable, sender=None):
121
self._check_permission(sender)
124
for source in self.list:
125
if url in source.str() and source.type == 'deb':
126
source.disabled = not enable
130
for source in self.list:
131
if url in source.str() and source.type == 'deb':
132
return not source.disabled
98
134
@dbus.service.method(INTERFACE,
99
135
in_signature='ssssb', out_signature='s',
158
194
@dbus.service.method(INTERFACE,
195
in_signature='', out_signature='')
196
def disable_ppa(self):
200
for source in self.list:
201
if self.PPA_URL in source.uri and not source.disabled:
202
self.ppa_list.append(source.uri)
203
source.set_enabled(False)
207
@dbus.service.method(INTERFACE,
208
in_signature='', out_signature='')
209
def enable_ppa(self):
212
for source in self.list:
214
if self.PPA_URL in url and url in self.ppa_list:
215
source.set_enabled(True)
219
@dbus.service.method(INTERFACE,
220
in_signature='sv', out_signature='')
221
def upgrade_sources(self, check_string, source_dict):
224
for source in self.list:
225
if source.uri in source_dict:
226
source.dist = source_dict[source.uri]
227
source.comment = source.comment.split(check_string)[0]
228
source.set_enabled(True)
232
@dbus.service.method(INTERFACE,
233
in_signature='', out_signature='')
234
def enable_stable_source(self):
237
for source in self.list:
238
if self.stable_url in source.str() and source.type == 'deb' and not source.disabled:
241
distro = module_check.get_codename()
244
self.set_separated_entry(self.stable_url, distro, 'main',
245
'Ubuntu Tweak Stable Source', True,
246
'ubuntu-tweak-stable')
247
self.add_apt_key_from_content(PPA_KEY)
249
@dbus.service.method(INTERFACE,
250
in_signature='', out_signature='b')
251
def get_stable_source_enabled(self):
254
for source in self.list:
255
if self.stable_url in source.str() and source.type == 'deb' and not source.disabled:
260
@dbus.service.method(INTERFACE,
159
261
in_signature='', out_signature='s')
160
262
def get_list_state(self):
161
263
if self.liststate:
171
273
os.system('apt-get clean')
277
#TODO enable it in the future for UTURL
278
# @dbus.service.method(INTERFACE,
279
# in_signature='s', out_signature='b')
280
# def get_package_status(self, package):
282
# pkg = self.cache[package]
283
# return pkg.isInstalled
284
# except Exception, e:
175
289
@dbus.service.method(INTERFACE,
176
290
in_signature='s', out_signature='s',
177
291
sender_keyword='sender')
218
332
@dbus.service.method(INTERFACE,
219
in_signature='s', out_signature='s',
220
sender_keyword='sender')
221
def clean_config(self, pkg, sender=None):
222
self._check_permission(sender)
223
return str(os.system('sudo dpkg --purge %s' % pkg))
225
@dbus.service.method(INTERFACE,
226
in_signature='s', out_signature='',
227
sender_keyword='sender')
228
def add_apt_key(self, filename, sender=None):
229
self._check_permission(sender)
231
apt_key.add(filename)
333
in_signature='as', out_signature='',
334
sender_keyword='sender')
335
def clean_configs(self, pkgs, sender=None):
336
self._check_permission(sender)
337
cmd = ['sudo', 'dpkg', '--purge']
339
self.p = subprocess.Popen(cmd, stdout=PIPE)
340
self.__setup_non_block_io(self.p.stdout)
342
@dbus.service.method(INTERFACE,
343
in_signature='as', out_signature='',
344
sender_keyword='sender')
345
def install_select_pkgs(self, pkgs, sender=None):
346
self._check_permission(sender)
347
cmd = ['sudo', 'apt-get', '-y', '--force-yes', 'install']
349
log.debug("The install command is %s" % ' '.join(cmd))
350
self.p = subprocess.Popen(cmd, stdout=PIPE)
351
self.__setup_non_block_io(self.p.stdout)
353
@dbus.service.method(INTERFACE,
354
in_signature='', out_signature='v')
355
def get_cmd_pipe(self):
357
terminaled = self.p.poll()
358
if terminaled == None:
360
return self.p.stdout.readline(), str(terminaled)
364
strings, returncode = ''.join(self.p.stdout.readlines()), str(terminaled)
366
return strings, returncode
233
370
@dbus.service.method(INTERFACE,
234
371
in_signature='s', out_signature='',
269
406
@dbus.service.method(INTERFACE,
407
in_signature='s', out_signature='s',
408
sender_keyword='sender')
409
def exec_command(self, command, sender=None):
410
self._check_permission(sender)
411
cmd = os.popen(command)
412
return cmd.read().strip()
414
@dbus.service.method(INTERFACE,
415
in_signature='s', out_signature='s')
416
def get_as_tempfile(self, path):
417
f = tempfile.NamedTemporaryFile()
420
os.popen('cp %s %s' % (path, new_path))
423
@dbus.service.method(INTERFACE,
424
in_signature='ss', out_signature='s')
425
def get_user_gconf(self, user, key):
426
command = 'sudo -u %s gconftool-2 --get %s' % (user, key)
427
cmd = os.popen(command)
428
return cmd.read().strip()
430
@dbus.service.method(INTERFACE,
431
in_signature='sssss', out_signature='s',
432
sender_keyword='sender')
433
def set_user_gconf(self, user, key, value, type, list_type='', sender=None):
434
self._check_permission(sender)
435
command = 'sudo -u %s gconftool-2 --type %s' % (user, type)
437
command = '%s --set %s %s' % (command, key, value)
439
command = '%s --type %s --list-type %s --set %s %s' % (command,
442
cmd = os.popen(command)
443
return cmd.read().strip()
445
@dbus.service.method(INTERFACE,
446
in_signature='s', out_signature='s')
447
def get_system_gconf(self, key):
448
command = 'gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --get %s' % key
449
cmd = os.popen(command)
450
return cmd.read().strip()
452
@dbus.service.method(INTERFACE,
453
in_signature='ssss', out_signature='s',
454
sender_keyword='sender')
455
def set_system_gconf(self, key, value, type, list_type='', sender=None):
456
self._check_permission(sender)
458
command = 'gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type %s --set %s %s' % (type, key, value)
460
command = 'gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type %s --list-type %s --set %s %s' % (type, list_type, key, value)
461
cmd = os.popen(command)
462
return cmd.read().strip()
464
@dbus.service.method(INTERFACE,
270
465
in_signature='', out_signature='')
274
469
if __name__ == '__main__':
275
470
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
276
Daemon(dbus.SystemBus())
278
471
mainloop = gobject.MainLoop()
472
Daemon(dbus.SystemBus(), mainloop)