~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/autopilot/unity/emulators/__init__.py

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
# Copyright 2012 Canonical
3
 
# Author: Thomi Richards
4
 
#
5
 
# This program is free software: you can redistribute it and/or modify it
6
 
# under the terms of the GNU General Public License version 3, as published
7
 
# by the Free Software Foundation.
8
 
#
9
 
 
10
 
"""A collection of Unity-specific emulators."""
11
 
 
12
 
from time import sleep
13
 
 
14
 
from autopilot.introspection.dbus import DBusIntrospectionObject
15
 
 
16
 
 
17
 
class UnityIntrospectionObject(DBusIntrospectionObject):
18
 
 
19
 
    DBUS_SERVICE = "com.canonical.Unity"
20
 
    DBUS_OBJECT = "/com/canonical/Unity/Debug"
21
 
 
22
 
 
23
 
def ensure_unity_is_running(timeout=300):
24
 
    """Poll the unity debug interface, and return when it's ready for use.
25
 
 
26
 
    The default timeout is 300 seconds (5 minutes) to account for the case where
27
 
    Unity has crashed and is taking a while to get restarted (on a slow VM for
28
 
    example).
29
 
 
30
 
    If, after the timeout period, unity is still not up, this function raises a
31
 
    RuntimeError exception.
32
 
 
33
 
    """
34
 
    sleep_period=10
35
 
    for i in range(0, timeout, sleep_period):
36
 
        try:
37
 
            UnityIntrospectionObject.get_state_by_path("/")
38
 
            return True
39
 
        except:
40
 
            sleep(sleep_period)
41
 
    raise RuntimeError("Unity debug interface is down after %d seconds of polling." % (timeout))