本文整理汇总了Python中addons.AddonManager.clean方法的典型用法代码示例。如果您正苦于以下问题:Python AddonManager.clean方法的具体用法?Python AddonManager.clean怎么用?Python AddonManager.clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.AddonManager
的用法示例。
在下文中一共展示了AddonManager.clean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Profile
# 需要导入模块: from addons import AddonManager [as 别名]
# 或者: from addons.AddonManager import clean [as 别名]
class Profile(object):
"""Handles all operations regarding profile.
Creating new profiles, installing add-ons, setting preferences and
handling cleanup.
"""
def __init__(
self,
profile=None,
addons=None,
addon_manifests=None,
apps=None,
preferences=None,
locations=None,
proxy=None,
restore=True,
):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons (see http://bit.ly/17jQ7i6)
:param apps: Dictionary or class of webapps to install
:param preferences: Dictionary or class of preferences
:param locations: ServerLocations object
:param proxy: Setup a proxy
:param restore: Flag for removing all custom settings during cleanup
"""
self._addons = addons
self._addon_manifests = addon_manifests
self._apps = apps
self._locations = locations
self._proxy = proxy
# Prepare additional preferences
if preferences:
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences if len(i) != 2]
else:
preferences = []
self._preferences = preferences
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
else:
self.profile = tempfile.mkdtemp(suffix=".mozrunner")
self.restore = restore
# Initialize all class members
self._internal_init()
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = "%s %s" % (str(time.time()), uuid.uuid4())
self.delimeters = ("#MozRunner Prefs Start %s" % nonce, "#MozRunner Prefs End %s" % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, "preferences"):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, "prefs.js")
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
# handle webapps
self.webapps = WebappCollection(profile=self.profile, apps=self._apps)
self.webapps.update_manifests()
def __del__(self):
self.cleanup()
### cleanup
def cleanup(self):
"""Cleanup operations for the profile."""
if self.restore:
#.........这里部分代码省略.........
示例2: Profile
# 需要导入模块: from addons import AddonManager [as 别名]
# 或者: from addons.AddonManager import clean [as 别名]
class Profile(object):
"""Handles all operations regarding profile.
Creating new profiles, installing add-ons, setting preferences and
handling cleanup.
The files associated with the profile will be removed automatically after
the object is garbage collected: ::
profile = Profile()
print profile.profile # this is the path to the created profile
del profile
# the profile path has been removed from disk
:meth:`cleanup` is called under the hood to remove the profile files. You
can ensure this method is called (even in the case of exception) by using
the profile as a context manager: ::
with Profile() as profile:
# do things with the profile
pass
# profile.cleanup() has been called here
"""
def __init__(self, profile=None, addons=None, addon_manifests=None,
preferences=None, locations=None, proxy=None, restore=True):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons (see http://bit.ly/17jQ7i6)
:param preferences: Dictionary or class of preferences
:param locations: ServerLocations object
:param proxy: Setup a proxy
:param restore: Flag for removing all custom settings during cleanup
"""
self._addons = addons
self._addon_manifests = addon_manifests
self._locations = locations
self._proxy = proxy
# Prepare additional preferences
if preferences:
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences if len(i) != 2]
else:
preferences = []
self._preferences = preferences
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
else:
self.profile = tempfile.mkdtemp(suffix='.mozrunner')
self.restore = restore
# Initialize all class members
self._internal_init()
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,
'#MozRunner Prefs End %s' % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, 'preferences'):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.cleanup()
#.........这里部分代码省略.........
示例3: Profile
# 需要导入模块: from addons import AddonManager [as 别名]
# 或者: from addons.AddonManager import clean [as 别名]
class Profile(object):
"""Handles all operations regarding profile.
Creating new profiles, installing add-ons, setting preferences and
handling cleanup.
"""
def __init__(self, profile=None, addons=None, addon_manifests=None, apps=None,
preferences=None, locations=None, proxy=None, restore=True):
"""
:param profile: Path to the profile
:param addons: String of one or list of addons to install
:param addon_manifests: Manifest for addons (see http://bit.ly/17jQ7i6)
:param apps: Dictionary or class of webapps to install
:param preferences: Dictionary or class of preferences
:param locations: ServerLocations object
:param proxy: Setup a proxy
:param restore: Flag for removing all custom settings during cleanup
"""
self._addons = addons
self._addon_manifests = addon_manifests
self._apps = apps
self._locations = locations
self._proxy = proxy
# Prepare additional preferences
if preferences:
if isinstance(preferences, dict):
# unordered
preferences = preferences.items()
# sanity check
assert not [i for i in preferences if len(i) != 2]
else:
preferences = []
self._preferences = preferences
# Handle profile creation
self.create_new = not profile
if profile:
# Ensure we have a full path to the profile
self.profile = os.path.abspath(os.path.expanduser(profile))
else:
self.profile = tempfile.mkdtemp(suffix='.mozrunner')
self.restore = restore
# Initialize all class members
self._internal_init()
def _internal_init(self):
"""Internal: Initialize all class members to their default value"""
if not os.path.exists(self.profile):
os.makedirs(self.profile)
# Preferences files written to
self.written_prefs = set()
# Our magic markers
nonce = '%s %s' % (str(time.time()), uuid.uuid4())
self.delimeters = ('#MozRunner Prefs Start %s' % nonce,
'#MozRunner Prefs End %s' % nonce)
# If sub-classes want to set default preferences
if hasattr(self.__class__, 'preferences'):
self.set_preferences(self.__class__.preferences)
# Set additional preferences
self.set_preferences(self._preferences)
self.permissions = Permissions(self.profile, self._locations)
prefs_js, user_js = self.permissions.network_prefs(self._proxy)
self.set_preferences(prefs_js, 'prefs.js')
self.set_preferences(user_js)
# handle add-on installation
self.addon_manager = AddonManager(self.profile, restore=self.restore)
self.addon_manager.install_addons(self._addons, self._addon_manifests)
# handle webapps
self.webapps = WebappCollection(profile=self.profile, apps=self._apps)
self.webapps.update_manifests()
def __del__(self):
self.cleanup()
### cleanup
def cleanup(self):
"""Cleanup operations for the profile."""
if self.restore:
# If copies of those class instances exist ensure we correctly
# reset them all (see bug 934484)
self.addon_manager.clean()
self.clean_preferences()
self.permissions.clean_db()
self.webapps.clean()
# If it's a temporary profile we have to remove it
#.........这里部分代码省略.........