liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
 
class ShillTemporaryProfile(object):
    """Context enclosing the use of a temporary shill profile.  It takes
    a shill manager dbus object and profile name, and makes sure that
    this profile is pushed atop the topmost default profile for the duration
    of this object lifetime."""
    def __init__(self, manager, profile_name='test'):
        self._manager = manager
        self._profile_name = profile_name
 
 
    def __enter__(self):
        self._manager.PopAllUserProfiles()
        try:
            self._manager.RemoveProfile(self._profile_name)
        except:
            pass
        self._manager.CreateProfile(self._profile_name)
        self._manager.PushProfile(self._profile_name)
        return self
 
 
    def __exit__(self, exception, value, traceback):
        try:
            self._manager.PopProfile(self._profile_name)
            self._manager.RemoveProfile(self._profile_name)
        except:
            pass