本文整理汇总了Python中mozprofile.profile.Profile.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.clone方法的具体用法?Python Profile.clone怎么用?Python Profile.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozprofile.profile.Profile
的用法示例。
在下文中一共展示了Profile.clone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cleanup_on_garbage_collected
# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import clone [as 别名]
def test_cleanup_on_garbage_collected(self):
clone = Profile.clone(self.profile.profile)
profile_dir = clone.profile
self.assertTrue(os.path.exists(profile_dir))
del clone
# clone should be deleted
self.assertFalse(os.path.exists(profile_dir))
示例2: _init_profile
# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import clone [as 别名]
def _init_profile(self):
preferences = dict(self.browser_config['preferences'])
if self.test_config.get('preferences'):
test_prefs = dict(
[(i, utils.parse_pref(j))
for i, j in self.test_config['preferences'].items()]
)
preferences.update(test_prefs)
# interpolate webserver value in prefs
webserver = self.browser_config['webserver']
if '://' not in webserver:
webserver = 'http://' + webserver
for name, value in preferences.items():
if type(value) is str:
value = utils.interpolate(value, webserver=webserver)
preferences[name] = value
extensions = self.browser_config['extensions'][:]
if self.test_config.get('extensions'):
extensions.append(self.test_config['extensions'])
profile = Profile.clone(
os.path.normpath(self.test_config['profile_path']),
self.profile_dir,
restore=False)
profile.set_preferences(preferences)
profile.addon_manager.install_addons(extensions)
示例3: test_restore_false
# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import clone [as 别名]
def test_restore_false(self):
# make a clone of this profile with restore=False
clone = Profile.clone(self.profile.profile, restore=False)
clone.cleanup()
# clone should still be around on the filesystem
self.assertTrue(os.path.exists(clone.profile))
示例4: test_restore_true
# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import clone [as 别名]
def test_restore_true(self):
# make a clone of this profile with restore=True
clone = Profile.clone(self.profile.profile, restore=True)
clone.cleanup()
# clone should be deleted
self.assertFalse(os.path.exists(clone.profile))
示例5: test_restore_true
# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import clone [as 别名]
def test_restore_true(self):
counter = [0]
def _feedback(dir, content):
# Called by shutil.copytree on each visited directory.
# Used here to display info.
#
# Returns the items that should be ignored by
# shutil.copytree when copying the tree, so always returns
# an empty list.
counter[0] += 1
return []
# make a clone of this profile with restore=True
clone = Profile.clone(self.profile.profile, restore=True,
ignore=_feedback)
self.addCleanup(mozfile.remove, clone.profile)
clone.cleanup()
# clone should be deleted
self.assertFalse(os.path.exists(clone.profile))
self.assertTrue(counter[0] > 0)
示例6: _init_profile
# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import clone [as 别名]
def _init_profile(self):
preferences = dict(self.browser_config['preferences'])
if self.test_config.get('preferences'):
test_prefs = dict(
[(i, utils.parse_pref(j))
for i, j in self.test_config['preferences'].items()]
)
preferences.update(test_prefs)
# interpolate webserver value in prefs
webserver = self.browser_config['webserver']
if '://' not in webserver:
webserver = 'http://' + webserver
for name, value in preferences.items():
if type(value) is str:
value = utils.interpolate(value, webserver=webserver)
preferences[name] = value
extensions = self.browser_config['extensions'][:]
if self.test_config.get('extensions'):
extensions.append(self.test_config['extensions'])
# downloading a profile instead of using the empty one
if self.test_config['profile'] is not None:
path = heavy.download_profile(self.test_config['profile'])
self.test_config['profile_path'] = path
profile_path = os.path.normpath(self.test_config['profile_path'])
LOG.info("Cloning profile located at %s" % profile_path)
def _feedback(directory, content):
# Called by shutil.copytree on each visited directory.
# Used here to display info.
#
# Returns the items that should be ignored by
# shutil.copytree when copying the tree, so always returns
# an empty list.
sub = directory.split(profile_path)[-1].lstrip("/")
if sub:
LOG.info("=> %s" % sub)
return []
profile = Profile.clone(profile_path,
self.profile_dir,
ignore=_feedback,
restore=False)
profile.set_preferences(preferences)
# installing addons
LOG.info("Installing Add-ons")
profile.addon_manager.install_addons(extensions)
# installing webextensions
webextensions = self.test_config.get('webextensions', None)
if isinstance(webextensions, basestring):
webextensions = [webextensions]
if webextensions is not None:
LOG.info("Installing Webextensions")
for webext in webextensions:
filename = utils.interpolate(webext)
if mozinfo.os == 'win':
filename = filename.replace('/', '\\')
if not filename.endswith('.xpi'):
continue
if not os.path.exists(filename):
continue
profile.addon_manager.install_from_path(filename)