~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to scripts/plugininstall.py

  • Committer: Colin Watson
  • Date: 2012-05-03 12:26:22 UTC
  • Revision ID: cjwatson@canonical.com-20120503122622-1pqng262csumnswx
As a general rule, open subprocesses with universal_newlines=True when
expecting to read text from them.  This has no effect on Python 2
(aside from \r\n conversion and the like, which is mostly a no-op for
us), but causes Python 3 to read str rather than bytes.  The
exceptions at the moment are debconf-communicator subprocesses, where
debconf expects to read binary data and deal with encoding itself, and
debconf-copydb subprocesses, which return mixed-encoding data that
needs to be handled specially.

Show diffs side-by-side

added added

removed removed

Lines of Context:
273
273
    def configure_face(self):
274
274
        PHOTO_PATH = '/var/lib/ubiquity/webcam_photo.png'
275
275
        target_user = self.db.get('passwd/username')
276
 
        uid = subprocess.Popen(['chroot', self.target, 'sudo', '-u',
277
 
            target_user, '--', 'id', '-u'], stdout=subprocess.PIPE)
 
276
        uid = subprocess.Popen(
 
277
            ['chroot', self.target, 'sudo', '-u', target_user, '--',
 
278
             'id', '-u'], stdout=subprocess.PIPE, universal_newlines=True)
278
279
        uid = uid.communicate()[0].strip('\n')
279
 
        gid = subprocess.Popen(['chroot', self.target, 'sudo', '-u',
280
 
            target_user, '--', 'id', '-g'], stdout=subprocess.PIPE)
 
280
        gid = subprocess.Popen(
 
281
            ['chroot', self.target, 'sudo', '-u', target_user, '--',
 
282
             'id', '-g'], stdout=subprocess.PIPE, universal_newlines=True)
281
283
        gid = gid.communicate()[0].strip('\n')
282
284
        try:
283
285
            uid = int(uid)
321
323
        # Modules provided by the core Debian Python packages.
322
324
        default = subprocess.Popen(
323
325
            ['chroot', self.target, 'pyversions', '-d'],
324
 
            stdout=subprocess.PIPE).communicate()[0].rstrip('\n')
 
326
            stdout=subprocess.PIPE,
 
327
            universal_newlines=True).communicate()[0].rstrip('\n')
325
328
        if default:
326
329
            install_misc.chrex(self.target, default, '-m', 'compileall',
327
330
                               '/usr/share/python/')
341
344
            if osextras.find_on_path_root(self.target, 'pyversions'):
342
345
                supported = subprocess.Popen(
343
346
                    ['chroot', self.target, 'pyversions', '-s'],
344
 
                    stdout=subprocess.PIPE).communicate()[0].rstrip('\n')
 
347
                    stdout=subprocess.PIPE,
 
348
                    universal_newlines=True).communicate()[0].rstrip('\n')
345
349
                for python in supported.split():
346
350
                    try:
347
351
                        cachedpython = cache['%s-minimal' % python]
362
366
            if osextras.find_on_path_root(self.target, 'py3versions'):
363
367
                supported = subprocess.Popen(
364
368
                    ['chroot', self.target, 'py3versions', '-s'],
365
 
                    stdout=subprocess.PIPE).communicate()[0].rstrip('\n')
 
369
                    stdout=subprocess.PIPE,
 
370
                    universal_newlines=True).communicate()[0].rstrip('\n')
366
371
                for python in supported.split():
367
372
                    try:
368
373
                        cachedpython = cache['%s-minimal' % python]
856
861
            try:
857
862
                resume_uuid = subprocess.Popen(
858
863
                    ['block-attr', '--uuid', resume],
859
 
                    stdout=subprocess.PIPE).communicate()[0].rstrip('\n')
 
864
                    stdout=subprocess.PIPE,
 
865
                    universal_newlines=True).communicate()[0].rstrip('\n')
860
866
            except OSError:
861
867
                pass
862
868
            if resume_uuid:
1226
1232
                inst_composite = ['chroot', self.target, 'jockey-text',
1227
1233
                                  '-C', '--no-dbus', '-k', self.kernel_version]
1228
1234
                p = subprocess.Popen(inst_composite, stdin=subprocess.PIPE,
1229
 
                                     stdout=sys.stderr, env=env)
 
1235
                                     stdout=sys.stderr, env=env,
 
1236
                                     universal_newlines=True)
1230
1237
                p.communicate('y\n')
1231
1238
            except OSError:
1232
1239
                syslog.syslog(syslog.LOG_WARNING,
1630
1637
                                 '/usr/lib/gnome-settings-daemon/'
1631
1638
                                 'gnome-update-wallpaper-cache'])
1632
1639
            # copy to targeted user
1633
 
            uid = subprocess.Popen(['chroot', self.target, 'sudo', '-u',
1634
 
                target_user, '--', 'id', '-u'],
1635
 
                stdout=subprocess.PIPE).communicate()[0].strip('\n')
1636
 
            gid = subprocess.Popen(['chroot', self.target, 'sudo', '-u',
1637
 
                target_user, '--', 'id', '-g'],
1638
 
                stdout=subprocess.PIPE).communicate()[0].strip('\n')
 
1640
            uid = subprocess.Popen(
 
1641
                ['chroot', self.target, 'sudo', '-u', target_user, '--',
 
1642
                 'id', '-u'],
 
1643
                stdout=subprocess.PIPE,
 
1644
                universal_newlines=True).communicate()[0].strip('\n')
 
1645
            gid = subprocess.Popen(
 
1646
                ['chroot', self.target, 'sudo', '-u', target_user, '--',
 
1647
                 'id', '-g'],
 
1648
                stdout=subprocess.PIPE,
 
1649
                universal_newlines=True).communicate()[0].strip('\n')
1639
1650
            uid = int(uid)
1640
1651
            gid = int(gid)
1641
1652
            self.copy_tree(casper_user_wallpaper_cache_dir,