1
#!/usr/bin/env python2.4
8
import subprocess as sp
14
14
from gettext import gettext as _
15
from UpdateManager.Common.SimpleGladeApp import SimpleGladeApp
16
from SoftwareProperties.dialog_apt_key import apt_key
17
from SoftwareProperties.aptsources import SourceEntry
18
from SoftwareProperties.aptsources import SourcesList
15
from UpdateManager.SimpleGladeApp import SimpleGladeApp
16
from softwareproperties.gtk.DialogAptKey import DialogAddKey as apt_key
17
from aptsources.sourceslist import SourceEntry, SourcesList
20
19
from gapti.SoftwarePackageWindow import SoftwarePackageWindow
31
30
# Continue processing on the main loop.
32
31
gobject.timeout_add(0, self.main)
35
34
"""Invoked on main loop."""
41
40
"""Does actual work."""
43
42
# Program requires three files. First is the keys file to import.
44
43
# Second is a flat list of sources.list lines to be appended. Third is
45
44
# a simple list of packages seperated by whitespace.
47
46
if (len(sys.argv) != 4):
48
47
utils.dialog_error(None, 'GApti Error', 'Exactly three arguments must be passed to gapti-root.')
51
50
keys_file = sys.argv[1]
52
51
archives_file = sys.argv[2]
53
52
packages_file = sys.argv[3]
55
54
if (not self.add_keys(keys_file)):
58
57
if (not self.add_archives(archives_file)):
61
60
if (not self.update_cache()):
64
63
if (not self.select_packages(packages_file)):
69
68
def add_keys(self, filename):
70
69
"""Imports the specified filename with apt-key."""
78
77
def add_archives(self, archives_file):
79
78
"""Appends the specified archives to the apt sources."""
81
80
# Load the existing sources file.
82
81
apt_dir = '/etc/apt/'
83
82
apt_file = 'sources.list'
86
85
apt_pkg.Config.Set('Dir::Etc::sourcelist', apt_file)
87
86
old_sources = SourcesList()
88
87
old_sources.refresh()
90
89
# Load the sources file containing entries to be added.
91
90
new_sources = utils.GAptISourcesList()
92
91
new_sources.load(archives_file)
94
93
# Add each new to the old.
95
94
for source in new_sources.list:
96
95
old_sources.add(source.type, source.uri, source.dist, source.comps, pos=len(old_sources.list))
97
96
for source in old_sources.list:
98
97
source.file = apt_path
100
99
old_sources.save()
104
103
def update_cache(self):
105
104
cmd = ['/usr/sbin/synaptic',
106
105
'--hide-main-window', '--non-interactive',
107
106
'--update-at-startup' ]
108
p = subprocess.Popen(cmd)
109
108
if (p.wait() != 0):
114
113
def select_packages(self, packages_file):
116
115
lines = open(packages_file, 'r').readlines()
117
116
for line in lines:
118
117
pkg = line.strip().split(' ')[0]
121
120
self.package_window = SoftwarePackageWindow('%s/gapti.glade' % self.datadir)
122
121
self.package_window.set_packages(pkgs)
123
122
self.package_window.show()
125
124
self.package_window.help_button.connect('clicked', self.help_button_clicked)
126
125
self.package_window.cancel_button.connect('clicked', self.cancel_button_clicked)
127
126
self.package_window.install_button.connect('clicked', self.install_button_clicked)
131
130
def help_button_clicked(self, user_data):
134
133
def cancel_button_clicked(self, user_data):
137
136
def install_button_clicked(self, user_data):
138
137
packages = self.package_window.get_package_selections()
139
138
pkg_tmp = tempfile.NamedTemporaryFile()
140
139
for package in packages:
141
print '%s install' % package
140
print('%s install' % package)
142
141
pkg_tmp.write('%s install\n' % package)
145
144
self.install(pkg_tmp.name)
150
149
'--progress-str', 'Please wait, this can take some time.',
151
150
'--finish-str', 'Installation is complete.',
152
151
'--set-selections-file', packages_file]
154
p = subprocess.Popen(cmd)
158
157
if __name__ == '__main__':
159
158
gapti = GAptIRoot()