本文整理汇总了Python中mozprofile.Preferences.add方法的典型用法代码示例。如果您正苦于以下问题:Python Preferences.add方法的具体用法?Python Preferences.add怎么用?Python Preferences.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozprofile.Preferences
的用法示例。
在下文中一共展示了Preferences.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_prefs
# 需要导入模块: from mozprofile import Preferences [as 别名]
# 或者: from mozprofile.Preferences import add [as 别名]
def load_prefs(self):
prefs = Preferences()
pref_paths = []
prefs_general = os.path.join(self.prefs_root, 'prefs_general.js')
if os.path.isfile(prefs_general):
# Old preference file used in Firefox 60 and earlier (remove when no longer supported)
pref_paths.append(prefs_general)
profiles = os.path.join(self.prefs_root, 'profiles.json')
if os.path.isfile(profiles):
with open(profiles, 'r') as fh:
for name in json.load(fh)['web-platform-tests']:
pref_paths.append(os.path.join(self.prefs_root, name, 'user.js'))
for path in pref_paths:
if os.path.exists(path):
prefs.add(Preferences.read_prefs(path))
else:
self.logger.warning("Failed to find base prefs file in %s" % path)
# Add any custom preferences
prefs.add(self.extra_prefs, cast=True)
return prefs()
示例2: load_prefs
# 需要导入模块: from mozprofile import Preferences [as 别名]
# 或者: from mozprofile.Preferences import add [as 别名]
def load_prefs(self):
prefs = Preferences()
pref_paths = []
profiles = os.path.join(self.prefs_root, 'profiles.json')
if os.path.isfile(profiles):
with open(profiles, 'r') as fh:
for name in json.load(fh)['web-platform-tests']:
if self.browser_channel in (None, 'nightly'):
pref_paths.append(os.path.join(self.prefs_root, name, 'user.js'))
elif name != 'unittest-features':
pref_paths.append(os.path.join(self.prefs_root, name, 'user.js'))
else:
# Old preference files used before the creation of profiles.json (remove when no longer supported)
legacy_pref_paths = (
os.path.join(self.prefs_root, 'prefs_general.js'), # Used in Firefox 60 and below
os.path.join(self.prefs_root, 'common', 'user.js'), # Used in Firefox 61
)
for path in legacy_pref_paths:
if os.path.isfile(path):
pref_paths.append(path)
for path in pref_paths:
if os.path.exists(path):
prefs.add(Preferences.read_prefs(path))
else:
self.logger.warning("Failed to find base prefs file in %s" % path)
# Add any custom preferences
prefs.add(self.extra_prefs, cast=True)
return prefs()
示例3: load_prefs
# 需要导入模块: from mozprofile import Preferences [as 别名]
# 或者: from mozprofile.Preferences import add [as 别名]
def load_prefs(self):
prefs = Preferences()
prefs_path = os.path.join(self.prefs_root, "prefs_general.js")
if os.path.exists(prefs_path):
prefs.add(Preferences.read_prefs(prefs_path))
else:
self.logger.warning("Failed to find base prefs file in %s" % prefs_path)
# Add any custom preferences
prefs.add(self.extra_prefs, cast=True)
return prefs()
示例4: create_mozprofile
# 需要导入模块: from mozprofile import Preferences [as 别名]
# 或者: from mozprofile.Preferences import add [as 别名]
def create_mozprofile(profile_dir, application=None, test_type=None, env=None):
# Ensure that the base `_temp/profiles/` directory exists before trying to
# create a nested directory.
if not os.path.exists(BASE_PROFILE_DIR):
os.mkdir(BASE_PROFILE_DIR)
if not profile_dir:
full_profile_dir = mkdtemp(
dir=BASE_PROFILE_DIR,
prefix="fftool.",
suffix=""
)
else:
full_profile_dir = os.path.join(BASE_PROFILE_DIR, profile_dir)
if os.path.exists(full_profile_dir):
msg = "WARNING: Profile '{0}' already exists. Merging configs."
Log.header(msg.format(full_profile_dir), 'XL', '-')
prefs = Preferences()
for path in prefs_paths(application, test_type, env):
prefs.add_file(path)
# Add the `fftool.profile.name` pref so we can go to about:config and see
# what our current profile is.
prefs.add([("fftool.profile.name", full_profile_dir)])
profile = Profile(
profile=full_profile_dir, restore=False, preferences=prefs())
Log.header("Launching browser with the following user configs:")
print(profile.summary())
# this is the path to the created profile
return full_profile_dir