~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to bin/ubiquity

  • Committer: Colin Watson
  • Date: 2012-07-16 14:29:13 UTC
  • Revision ID: cjwatson@canonical.com-20120716142913-hh1qmfjejxa9dfyb
Make all Python code pass pep8(1), and add a test to enforce this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from ubiquity import im_switch
34
34
from ubiquity import osextras
35
35
 
 
36
 
36
37
VERSION = '@VERSION@'
37
38
TARGET = '/target'
38
39
LOCKFILE = '/var/lock/ubiquity'
39
40
lock = None
40
41
 
 
42
 
41
43
def force_utf8_locale():
42
44
    """We must have a UTF-8 locale.  Try to get one."""
43
45
    if locale.getpreferredencoding() != "UTF-8":
51
53
                  "without one.", file=sys.stderr)
52
54
            sys.exit(1)
53
55
 
 
56
 
54
57
def distribution():
55
58
    """Returns the name of the running distribution."""
56
 
 
57
59
    proc = subprocess.Popen(
58
60
        ['lsb_release', '-is'], stdout=subprocess.PIPE,
59
61
        universal_newlines=True)
60
62
    return proc.communicate()[0].strip()
61
63
 
 
64
 
62
65
def disable_autologin():
63
66
    import traceback
64
67
 
72
75
            except OSError:
73
76
                traceback.print_exc()
74
77
 
 
78
 
75
79
def open_terminal():
76
80
    """Set up the terminal to run ubiquity's debconf frontend."""
77
 
 
78
81
    # Set up a framebuffer and start bterm if debian-installer/framebuffer
79
 
    # says to do so. See
80
 
    # rootskel/src/lib/debian-installer-startup.d/S40framebuffer-module-linux-x86.
 
82
    # says to do so. See, in rootskel:
 
83
    #   src/lib/debian-installer-startup.d/S40framebuffer-module-linux-x86
81
84
    # TODO: more careful architecture handling
82
85
 
83
86
    import debconf
177
180
                bterm_args.extend(sys.argv)
178
181
                os.execvp('bterm', bterm_args)
179
182
 
 
183
 
180
184
def start_debconf():
181
185
    """debconf_ui needs to run within a debconf frontend."""
182
 
 
183
186
    if 'DEBIAN_HAS_FRONTEND' in os.environ:
184
187
        # debconf already started, so just clean up the configuration file
185
188
        # if any (debconf has already read it by now).
221
224
    # TODO: need to set owner somehow for the cdebconf case
222
225
 
223
226
    import debconf
224
 
    debconf.runFrontEnd() # re-execs this program
 
227
    debconf.runFrontEnd()  # re-execs this program
 
228
 
225
229
 
226
230
def install(frontend=None, query=False):
227
 
    '''install(frontend=None) -> none
 
231
    """Get the type of frontend to use and load the module for that.
228
232
 
229
 
    Get the type of frontend to use and load the module for that.
230
 
    If frontend is None, defaults to the first of
231
 
    gtk_ui, kde_ui, and debconf_ui that exists.
232
 
    '''
 
233
    If frontend is None, defaults to the first of gtk_ui, kde_ui, and
 
234
    debconf_ui that exists.
 
235
    """
233
236
    if frontend is None:
234
237
        frontends = ['gtk_ui', 'kde_ui', 'debconf_ui']
235
238
    else:
280
283
 
281
284
@misc.raise_privileges
282
285
def apply_keyboard():
283
 
    '''Set the keyboard layout to the default layout for the language selected.
 
286
    """Set the keyboard layout to the default layout for the language selected.
 
287
 
284
288
    If a user wants a different layout, they can be reasonably expected to
285
 
    change it in System -> Preferences -> Keyboard.'''
 
289
    change it in System -> Preferences -> Keyboard.
 
290
    """
286
291
 
287
292
    # Mostly taken from ubi-console-setup.
288
293
 
330
335
                 '--action=change')
331
336
    misc.execute('udevadm', 'settle')
332
337
 
 
338
 
333
339
def copy_debconf():
334
340
    """Copy a few important questions into the installed system."""
335
341
    if not TARGET:
364
370
                     '--config=Name:targetdb', '--config=Driver:File',
365
371
                     '--config=Mode:0644', '--config=Filename:%s' % targetdb)
366
372
 
 
373
 
367
374
def unmount_target():
368
375
    if not TARGET:
369
376
        return
378
385
    for path in paths:
379
386
        misc.execute_root('umount', path)
380
387
 
 
388
 
381
389
def prepend_path(directory):
382
390
    if 'PATH' in os.environ and os.environ['PATH'] != '':
383
391
        os.environ['PATH'] = '%s:%s' % (directory, os.environ['PATH'])
384
392
    else:
385
393
        os.environ['PATH'] = directory
386
394
 
 
395
 
387
396
def release_lock():
388
397
    global lock
389
398
    osextras.unlink_force(LOCKFILE)
391
400
        lock.close()
392
401
        lock = None
393
402
 
 
403
 
394
404
def acquire_lock():
395
405
    global lock
396
406
    lock = open(LOCKFILE, 'w')
427
437
                  "running.")
428
438
            sys.exit(1)
429
439
 
 
440
 
430
441
def run_oem_hooks():
431
442
    """Run hook scripts from /usr/lib/oem-config/post-install."""
432
 
 
433
443
    hookdir = '/usr/lib/oem-config/post-install'
434
444
 
435
445
    if os.path.isdir(hookdir):
445
455
                # Errors are ignored at present, although this may change.
446
456
                subprocess.call([hook], env=child_env)
447
457
 
 
458
 
448
459
def main(oem_config):
449
460
    force_utf8_locale()
450
461
 
604
615
        run_oem_hooks()
605
616
    im_switch.kill_im()
606
617
 
 
618
 
607
619
if __name__ == '__main__':
608
620
    # Are we running as ubiquity or oem-config?
609
621
    oem_config = False