~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to scripts/plugininstall.py

  • Committer: Colin Watson
  • Date: 2012-11-22 16:27:21 UTC
  • Revision ID: cjwatson@canonical.com-20121122162721-q1ykdeiuxy1dq38w
Huge pile of minor changes to make ubiquity compatible with pep8 1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
263
263
        try:
264
264
            self.apt_clone_restore()
265
265
        except:
266
 
            syslog.syslog(syslog.LOG_WARNING,
 
266
            syslog.syslog(
 
267
                syslog.LOG_WARNING,
267
268
                'Could not restore packages from the previous install:')
268
269
            for line in traceback.format_exc().split('\n'):
269
270
                syslog.syslog(syslog.LOG_WARNING, line)
272
273
        try:
273
274
            self.copy_network_config()
274
275
        except:
275
 
            syslog.syslog(syslog.LOG_WARNING,
 
276
            syslog.syslog(
 
277
                syslog.LOG_WARNING,
276
278
                'Could not copy the network configuration:')
277
279
            for line in traceback.format_exc().split('\n'):
278
280
                syslog.syslog(syslog.LOG_WARNING, line)
281
283
        try:
282
284
            self.copy_bluetooth_config()
283
285
        except:
284
 
            syslog.syslog(syslog.LOG_WARNING,
 
286
            syslog.syslog(
 
287
                syslog.LOG_WARNING,
285
288
                'Could not copy the bluetooth configuration:')
286
289
            for line in traceback.format_exc().split('\n'):
287
290
                syslog.syslog(syslog.LOG_WARNING, line)
290
293
        try:
291
294
            self.recache_apparmor()
292
295
        except:
293
 
            syslog.syslog(syslog.LOG_WARNING,
294
 
                'Could not create an Apparmor cache:')
 
296
            syslog.syslog(
 
297
                syslog.LOG_WARNING, 'Could not create an Apparmor cache:')
295
298
            for line in traceback.format_exc().split('\n'):
296
299
                syslog.syslog(syslog.LOG_WARNING, line)
297
300
        try:
298
301
            self.copy_wallpaper_cache()
299
302
        except:
300
 
            syslog.syslog(syslog.LOG_WARNING,
301
 
                'Could not copy wallpaper cache:')
 
303
            syslog.syslog(
 
304
                syslog.LOG_WARNING, 'Could not copy wallpaper cache:')
302
305
            for line in traceback.format_exc().split('\n'):
303
306
                syslog.syslog(syslog.LOG_WARNING, line)
304
307
        self.copy_dcd()
341
344
 
342
345
        # Python standard library.
343
346
        re_minimal = re.compile('^python\d+\.\d+-minimal$')
344
 
        python_installed = sorted(
345
 
            [pkg[:-8] for pkg in cache.keys()
346
 
                      if re_minimal.match(pkg) and cache[pkg].is_installed])
 
347
        python_installed = sorted([
 
348
            pkg[:-8] for pkg in cache.keys()
 
349
            if re_minimal.match(pkg) and cache[pkg].is_installed])
347
350
        for python in python_installed:
348
351
            re_file = re.compile('^/usr/lib/%s/.*\.py$' % python)
349
 
            files = [f for f in cache['%s-minimal' % python].installed_files
350
 
                       if re_file.match(f) and
351
 
                          not os.path.exists(self.target_file('%sc' % f[1:]))]
 
352
            files = [
 
353
                f for f in cache['%s-minimal' % python].installed_files
 
354
                if (re_file.match(f) and
 
355
                    not os.path.exists(self.target_file('%sc' % f[1:])))]
352
356
            install_misc.chrex(self.target, python,
353
357
                               '/usr/lib/%s/py_compile.py' % python, *files)
354
 
            files = [f for f in cache[python].installed_files
355
 
                       if re_file.match(f) and
356
 
                          not os.path.exists(self.target_file('%sc' % f[1:]))]
 
358
            files = [
 
359
                f for f in cache[python].installed_files
 
360
                if (re_file.match(f) and
 
361
                    not os.path.exists(self.target_file('%sc' % f[1:])))]
357
362
            install_misc.chrex(self.target, python,
358
363
                               '/usr/lib/%s/py_compile.py' % python, *files)
359
364
 
503
508
            sock = socket.socket(socket.SOCK_DGRAM)
504
509
            interfaces = install_misc.get_all_interfaces()
505
510
            for i in range(len(interfaces)):
506
 
                if_names[interfaces[i]] = struct.unpack('H6s',
507
 
                    fcntl.ioctl(sock.fileno(), SIOCGIFHWADDR,
508
 
                                struct.pack('256s',
509
 
                                            interfaces[i].encode()))[16:24])
 
511
                if_names[interfaces[i]] = struct.unpack(
 
512
                    'H6s', fcntl.ioctl(
 
513
                        sock.fileno(), SIOCGIFHWADDR,
 
514
                        struct.pack('256s', interfaces[i].encode()))[16:24])
510
515
            sock.close()
511
516
 
512
517
            with open(self.target_file('etc/iftab'), 'w') as iftab:
557
562
        try:
558
563
            language_plugin = [
559
564
                plugin for plugin in self.plugins
560
 
                if plugin_manager.get_mod_string(plugin, "NAME") ==
561
 
                    "language"][0]
 
565
                if (plugin_manager.get_mod_string(plugin, "NAME") ==
 
566
                    "language")][0]
562
567
        except IndexError:
563
568
            return
564
569
        self.run_plugin(language_plugin)
584
589
 
585
590
        try:
586
591
            if self.db.get('base-installer/install-recommends') == 'false':
587
 
                with open(self.target_file(
588
 
                    'etc/apt/apt.conf.d/00InstallRecommends'),
589
 
                    'w') as apt_conf_ir:
 
592
                tf = self.target_file('etc/apt/apt.conf.d/00InstallRecommends')
 
593
                with open(tf, 'w') as apt_conf_ir:
590
594
                    print('APT::Install-Recommends "false";', file=apt_conf_ir)
591
595
        except debconf.DebconfError:
592
596
            pass
593
597
 
594
598
        # Make apt trust CDs. This is not on by default (we think).
595
599
        # This will be left in place on the installed system.
596
 
        with open(self.target_file(
597
 
            'etc/apt/apt.conf.d/00trustcdrom'), 'w') as apt_conf_tc:
 
600
        tf = self.target_file('etc/apt/apt.conf.d/00trustcdrom')
 
601
        with open(tf, 'w') as apt_conf_tc:
598
602
            print('APT::Authentication::TrustCDROM "true";', file=apt_conf_tc)
599
603
 
600
604
        # Avoid clock skew causing gpg verification issues.
601
605
        # This file will be left in place until the end of the install.
602
 
        with open(self.target_file(
603
 
            'etc/apt/apt.conf.d/00IgnoreTimeConflict'), 'w') as apt_conf_itc:
 
606
        tf = self.target_file('etc/apt/apt.conf.d/00IgnoreTimeConflict')
 
607
        with open(tf, 'w') as apt_conf_itc:
604
608
            print('Acquire::gpgv::Options { "--ignore-time-conflict"; };',
605
609
                  file=apt_conf_itc)
606
610
 
607
611
        try:
608
612
            if self.db.get('debian-installer/allow_unauthenticated') == 'true':
609
 
                with open(self.target_file(
610
 
                    'etc/apt/apt.conf.d/00AllowUnauthenticated'),
611
 
                    'w') as apt_conf_au:
 
613
                tf = self.target_file(
 
614
                    'etc/apt/apt.conf.d/00AllowUnauthenticated')
 
615
                with open(tf, 'w') as apt_conf_au:
612
616
                    print('APT::Get::AllowUnauthenticated "true";',
613
617
                          file=apt_conf_au)
614
618
                    print('Aptitude::CmdLine::Ignore-Trust-Violations "true";',
628
632
 
629
633
        # Make apt-cdrom and apt not unmount/mount CD-ROMs.
630
634
        # This file will be left in place until the end of the install.
631
 
        with open(self.target_file(
632
 
            'etc/apt/apt.conf.d/00NoMountCDROM'), 'w') as apt_conf_nmc:
 
635
        tf = self.target_file('etc/apt/apt.conf.d/00NoMountCDROM')
 
636
        with open(tf, 'w') as apt_conf_nmc:
633
637
            print(textwrap.dedent("""\
634
638
                APT::CDROM::NoMount "true";
635
639
                Acquire::cdrom {
892
896
            else:
893
897
                configdir = None
894
898
            if configdir is not None:
895
 
                with open(os.path.join(
896
 
                    configdir, 'resume'), 'w') as configfile:
 
899
                resume_path = os.path.join(configdir, 'resume')
 
900
                with open(resume_path, 'w') as configfile:
897
901
                    print("RESUME=%s" % resume, file=configfile)
898
902
 
899
903
        osextras.unlink_force(self.target_file('etc/popularity-contest.conf'))
1005
1009
                source = (
1006
1010
                    '/usr/share/locale-langpack/%s/LC_MESSAGES/grub.mo' % lang)
1007
1011
                if (os.path.exists(source) and
1008
 
                    os.path.isdir('/boot/grub/locale')):
 
1012
                        os.path.isdir('/boot/grub/locale')):
1009
1013
                    shutil.copy(source, '/boot/grub/locale/%s.mo' % lang)
1010
1014
                    break
1011
1015
            return
1233
1237
        # We only ever install these packages from the CD.
1234
1238
        sources_list = self.target_file('etc/apt/sources.list')
1235
1239
        os.rename(sources_list, "%s.apt-setup" % sources_list)
1236
 
        with open("%s.apt-setup" % sources_list) as old_sources, \
1237
 
             open(sources_list, 'w') as new_sources:
1238
 
            found_cdrom = False
1239
 
            for line in old_sources:
1240
 
                if 'cdrom:' in line:
1241
 
                    print(line, end="", file=new_sources)
1242
 
                    found_cdrom = True
 
1240
        with open("%s.apt-setup" % sources_list) as old_sources:
 
1241
            with open(sources_list, 'w') as new_sources:
 
1242
                found_cdrom = False
 
1243
                for line in old_sources:
 
1244
                    if 'cdrom:' in line:
 
1245
                        print(line, end="", file=new_sources)
 
1246
                        found_cdrom = True
1243
1247
        if not found_cdrom:
1244
1248
            os.rename("%s.apt-setup" % sources_list, sources_list)
1245
1249
 
1260
1264
 
1261
1265
                    apps_dir = 'usr/share/applications'
1262
1266
                    for desktop_file in (
1263
 
                        apps_dir + '/oem-config-prepare-gtk.desktop',
1264
 
                        apps_dir + '/kde4/oem-config-prepare-kde.desktop'):
 
1267
                            apps_dir + '/oem-config-prepare-gtk.desktop',
 
1268
                            apps_dir + '/kde4/oem-config-prepare-kde.desktop'):
1265
1269
                        if os.path.exists(self.target_file(desktop_file)):
1266
1270
                            desktop_base = os.path.basename(desktop_file)
1267
1271
                            install_misc.chrex(
1286
1290
                installable_lang = self.db.get(
1287
1291
                    'ubiquity/only-show-installable-languages')
1288
1292
                if installable_lang:
1289
 
                    install_misc.set_debconf(self.target,
 
1293
                    install_misc.set_debconf(
 
1294
                        self.target,
1290
1295
                        'ubiquity/only-show-installable-languages',
1291
1296
                        installable_lang, self.db)
1292
1297
        except debconf.DebconfError:
1471
1476
            cache = self.restricted_cache
1472
1477
            for pkg in cache.keys():
1473
1478
                if (cache[pkg].is_installed and
1474
 
                    cache[pkg].section.startswith('restricted/')):
 
1479
                        cache[pkg].section.startswith('restricted/')):
1475
1480
                    difference.add(pkg)
1476
1481
            del cache
1477
1482
 
1516
1521
        try:
1517
1522
            for bind in binds:
1518
1523
                misc.execute('mount', '--bind', bind, self.target + bind)
1519
 
            subprocess.check_call(['apt-clone', 'restore-new-distro',
1520
 
                working, codename, '--destination', self.target],
1521
 
                preexec_fn=install_misc.debconf_disconnect)
 
1524
            restore_cmd = [
 
1525
                'apt-clone', 'restore-new-distro',
 
1526
                working, codename, '--destination', self.target]
 
1527
            subprocess.check_call(
 
1528
                restore_cmd, preexec_fn=install_misc.debconf_disconnect)
1522
1529
        finally:
1523
1530
            install_misc.chroot_cleanup(self.target)
1524
1531
            for bind in binds:
1615
1622
        target_user_cache_dir = self.target_file('home', target_user, '.cache')
1616
1623
        target_user_wallpaper_cache_dir = os.path.join(target_user_cache_dir,
1617
1624
                                                       'wallpaper')
1618
 
        if not os.path.isdir(target_user_wallpaper_cache_dir) and \
1619
 
               os.path.isfile('/usr/lib/gnome-settings-daemon/'
1620
 
                              'gnome-update-wallpaper-cache'):
 
1625
        if (not os.path.isdir(target_user_wallpaper_cache_dir) and
 
1626
            os.path.isfile('/usr/lib/gnome-settings-daemon/'
 
1627
                           'gnome-update-wallpaper-cache')):
1621
1628
            # installer mode (else, g-s-d created it)
1622
1629
            if not os.path.isdir(casper_user_wallpaper_cache_dir):
1623
1630
                subprocess.call(['sudo', '-u', casper_user, '-i', 'DISPLAY=:0',
1694
1701
        try:
1695
1702
            if self.db.get('oem-config/enable') == 'true':
1696
1703
                oem_id = self.db.get('oem-config/id')
1697
 
                with open(
1698
 
                    self.target_file('var/log/installer/oem-id'),
1699
 
                    'w') as oem_id_file:
 
1704
                tf = self.target_file('var/log/installer/oem-id')
 
1705
                with open(tf, 'w') as oem_id_file:
1700
1706
                    print(oem_id, file=oem_id_file)
1701
1707
        except (debconf.DebconfError, IOError):
1702
1708
            pass