~gapti-dev/gapti/trunk

« back to all changes in this revision

Viewing changes to src/gapti/root.py

  • Committer: Savvas Radevic
  • Date: 2009-03-16 16:24:38 UTC
  • Revision ID: vicedar@gmail.com-20090316162438-8qxk3jm7alvpk06n
* Bug-fix release.
* python 2.6 transition (LP: #340901)
  + debian/control: Build-Depends: python-all-dev, python-support
  + gapti-root: Fixed UpdateManager.SimpleGladeApp
  + Edited files directly, shebangs: #!/usr/bin/python
  + Modified files directly using: 2to3-2.6 -w *
  + Replaced commands.getoutput with subprocess.Popen().communicate()
  + Replaced lines with spaces (\s+) with empty lines
* debian/control:
  + Standards-Version: 3.8.0
  + debhelper (>= 5)
* debian/rules: Removed sed command that changed shebangs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2.4
 
1
#!/usr/bin/python
2
2
 
3
3
import pygtk
4
4
pygtk.require('2.0')
5
5
import gobject
6
6
import gtk
7
7
import sys
8
 
import subprocess
 
8
import subprocess as sp
9
9
import apt_pkg
10
10
import tempfile
11
11
 
12
12
import utils
13
13
 
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
19
18
 
20
19
from gapti.SoftwarePackageWindow import SoftwarePackageWindow
21
20
 
30
29
 
31
30
        # Continue processing on the main loop.
32
31
        gobject.timeout_add(0, self.main)
33
 
        
 
32
 
34
33
    def main(self):
35
34
        """Invoked on main loop."""
36
35
        if not self.run():
37
36
            gtk.main_quit()
38
37
        return False
39
 
        
 
38
 
40
39
    def run(self):
41
40
        """Does actual work."""
42
 
        
 
41
 
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.
46
 
        
 
45
 
47
46
        if (len(sys.argv) != 4):
48
47
            utils.dialog_error(None, 'GApti Error', 'Exactly three arguments must be passed to gapti-root.')
49
48
            return
50
 
        
 
49
 
51
50
        keys_file = sys.argv[1]
52
51
        archives_file = sys.argv[2]
53
52
        packages_file = sys.argv[3]
54
 
        
 
53
 
55
54
        if (not self.add_keys(keys_file)):
56
55
            return False
57
 
            
 
56
 
58
57
        if (not self.add_archives(archives_file)):
59
58
            return False
60
 
        
 
59
 
61
60
        if (not self.update_cache()):
62
61
            return False
63
 
        
 
62
 
64
63
        if (not self.select_packages(packages_file)):
65
64
            return False
66
 
        
 
65
 
67
66
        return True
68
 
        
 
67
 
69
68
    def add_keys(self, filename):
70
69
        """Imports the specified filename with apt-key."""
71
70
        ak = apt_key()
74
73
            return False
75
74
        else:
76
75
            return True
77
 
            
 
76
 
78
77
    def add_archives(self, archives_file):
79
78
        """Appends the specified archives to the apt sources."""
80
 
        
 
79
 
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()
89
 
        
 
88
 
90
89
        # Load the sources file containing entries to be added.
91
90
        new_sources = utils.GAptISourcesList()
92
91
        new_sources.load(archives_file)
93
 
        
 
92
 
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
99
 
            
 
98
 
100
99
        old_sources.save()
101
 
        
 
100
 
102
101
        return True
103
 
    
 
102
 
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)
 
107
        p = sp.Popen(cmd)
109
108
        if (p.wait() != 0):
110
109
            return False
111
 
        
 
110
 
112
111
        return True
113
 
    
 
112
 
114
113
    def select_packages(self, packages_file):
115
114
        pkgs = []
116
115
        lines = open(packages_file, 'r').readlines()
117
116
        for line in lines:
118
117
            pkg = line.strip().split(' ')[0]
119
118
            pkgs.append(pkg)
120
 
            
 
119
 
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()
124
 
        
 
123
 
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)
128
 
        
 
127
 
129
128
        return True
130
 
    
 
129
 
131
130
    def help_button_clicked(self, user_data):
132
131
        return
133
 
    
 
132
 
134
133
    def cancel_button_clicked(self, user_data):
135
134
        return
136
 
    
 
135
 
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)
143
 
            
 
142
 
144
143
        pkg_tmp.flush()
145
144
        self.install(pkg_tmp.name)
146
145
        pkg_tmp.close()
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]
153
 
        print cmd
154
 
        p = subprocess.Popen(cmd)
 
152
        print(cmd)
 
153
        p = sp.Popen(cmd)
155
154
        p.wait()
156
155
        gtk.main_quit()
157
 
            
 
156
 
158
157
if __name__ == '__main__':
159
158
    gapti = GAptIRoot()
160
159
    gtk.main()