本文整理汇总了Python中mozprofile.Profile.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.cleanup方法的具体用法?Python Profile.cleanup怎么用?Python Profile.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozprofile.Profile
的用法示例。
在下文中一共展示了Profile.cleanup方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GeckoInstance
# 需要导入模块: from mozprofile import Profile [as 别名]
# 或者: from mozprofile.Profile import cleanup [as 别名]
#.........这里部分代码省略.........
self.required_prefs.update(prefs)
self.app_args = app_args or []
self.runner = None
self.symbols_path = symbols_path
if gecko_log != '-':
if gecko_log is None:
gecko_log = 'gecko.log'
elif os.path.isdir(gecko_log):
fname = 'gecko-%d.log' % time.time()
gecko_log = os.path.join(gecko_log, fname)
gecko_log = os.path.realpath(gecko_log)
if os.access(gecko_log, os.F_OK):
os.remove(gecko_log)
self.gecko_log = gecko_log
self.verbose = verbose
def start(self):
profile_args = {"preferences": deepcopy(self.required_prefs)}
profile_args["preferences"]["marionette.defaultPrefs.port"] = self.marionette_port
if self.prefs:
profile_args["preferences"].update(self.prefs)
if self.verbose:
level = "TRACE" if self.verbose >= 2 else "DEBUG"
profile_args["preferences"]["marionette.logging"] = level
if '-jsdebugger' in self.app_args:
profile_args["preferences"].update({
"devtools.browsertoolbox.panel": "jsdebugger",
"devtools.debugger.remote-enabled": True,
"devtools.chrome.enabled": True,
"devtools.debugger.prompt-connection": False,
"marionette.debugging.clicktostart": True,
})
if self.addons:
profile_args['addons'] = self.addons
if hasattr(self, "profile_path") and self.profile is None:
if not self.profile_path:
if self.workspace:
profile_args['profile'] = tempfile.mkdtemp(
suffix='.mozrunner-{:.0f}'.format(time.time()),
dir=self.workspace)
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
profile_name = '{}-{:.0f}'.format(
os.path.basename(self.profile_path),
time.time()
)
if self.workspace:
profile_args["path_to"] = os.path.join(self.workspace,
profile_name)
self.profile = Profile.clone(**profile_args)
process_args = {
'processOutputLine': [NullOutput()],
}
if self.gecko_log == '-':
process_args['stream'] = sys.stdout
else:
process_args['logfile'] = self.gecko_log
env = os.environ.copy()
# environment variables needed for crashreporting
# https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
env.update({ 'MOZ_CRASHREPORTER': '1',
'MOZ_CRASHREPORTER_NO_REPORT': '1', })
self.runner = Runner(
binary=self.bin,
profile=self.profile,
cmdargs=['-no-remote', '-marionette'] + self.app_args,
env=env,
symbols_path=self.symbols_path,
process_args=process_args)
self.runner.start()
def close(self, restart=False):
if not restart:
self.profile = None
if self.runner:
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None, clean=True):
self.close(restart=True)
if clean:
self.profile.cleanup()
self.profile = None
if prefs:
self.prefs = prefs
else:
self.prefs = None
self.start()
示例2: GeckoInstance
# 需要导入模块: from mozprofile import Profile [as 别名]
# 或者: from mozprofile.Profile import cleanup [as 别名]
#.........这里部分代码省略.........
path = 'gecko.log'
elif os.path.isdir(path):
fname = 'gecko-%d.log' % time.time()
path = os.path.join(path, fname)
path = os.path.realpath(path)
if os.access(path, os.F_OK):
os.remove(path)
self._gecko_log = path
return self._gecko_log
def _update_profile(self):
profile_args = {"preferences": deepcopy(self.required_prefs)}
profile_args["preferences"]["marionette.defaultPrefs.port"] = self.marionette_port
if self.prefs:
profile_args["preferences"].update(self.prefs)
if self.verbose:
level = "TRACE" if self.verbose >= 2 else "DEBUG"
profile_args["preferences"]["marionette.logging"] = level
if '-jsdebugger' in self.app_args:
profile_args["preferences"].update({
"devtools.browsertoolbox.panel": "jsdebugger",
"devtools.debugger.remote-enabled": True,
"devtools.chrome.enabled": True,
"devtools.debugger.prompt-connection": False,
"marionette.debugging.clicktostart": True,
})
if self.addons:
profile_args['addons'] = self.addons
if hasattr(self, "profile_path") and self.profile is None:
if not self.profile_path:
if self.workspace:
profile_args['profile'] = tempfile.mkdtemp(
suffix='.mozrunner-{:.0f}'.format(time.time()),
dir=self.workspace)
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
profile_name = '{}-{:.0f}'.format(
os.path.basename(self.profile_path),
time.time()
)
if self.workspace:
profile_args["path_to"] = os.path.join(self.workspace,
profile_name)
self.profile = Profile.clone(**profile_args)
def start(self):
self._update_profile()
self.runner = self.runner_class(**self._get_runner_args())
self.runner.start()
def _get_runner_args(self):
process_args = {
'processOutputLine': [NullOutput()],
}
if self.gecko_log == '-':
process_args['stream'] = sys.stdout
else:
process_args['logfile'] = self.gecko_log
env = os.environ.copy()
# environment variables needed for crashreporting
# https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
env.update({'MOZ_CRASHREPORTER': '1',
'MOZ_CRASHREPORTER_NO_REPORT': '1'})
return {
'binary': self.binary,
'profile': self.profile,
'cmdargs': ['-no-remote', '-marionette'] + self.app_args,
'env': env,
'symbols_path': self.symbols_path,
'process_args': process_args
}
def close(self, restart=False):
if not restart:
self.profile = None
if self.runner:
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None, clean=True):
self.close(restart=True)
if clean and self.profile:
self.profile.cleanup()
self.profile = None
if prefs:
self.prefs = prefs
else:
self.prefs = None
self.start()
示例3: GeckoInstance
# 需要导入模块: from mozprofile import Profile [as 别名]
# 或者: from mozprofile.Profile import cleanup [as 别名]
#.........这里部分代码省略.........
def __init__(self, host, port, bin, profile=None, addons=None,
app_args=None, symbols_path=None, gecko_log=None, prefs=None):
self.marionette_host = host
self.marionette_port = port
self.bin = bin
# Check if it is a Profile object or a path to profile
self.profile = None
self.addons = addons
if isinstance(profile, Profile):
self.profile = profile
else:
self.profile_path = profile
self.prefs = prefs
self.required_prefs = deepcopy(GeckoInstance.required_prefs)
if prefs:
self.required_prefs.update(prefs)
self.app_args = app_args or []
self.runner = None
self.symbols_path = symbols_path
if gecko_log != '-':
if gecko_log is None:
gecko_log = 'gecko.log'
elif os.path.isdir(gecko_log):
fname = 'gecko-%d.log' % time.time()
gecko_log = os.path.join(gecko_log, fname)
gecko_log = os.path.realpath(gecko_log)
if os.access(gecko_log, os.F_OK):
os.remove(gecko_log)
self.gecko_log = gecko_log
def start(self):
profile_args = {"preferences": deepcopy(self.required_prefs)}
profile_args["preferences"]["marionette.defaultPrefs.port"] = self.marionette_port
if self.prefs:
profile_args["preferences"].update(self.prefs)
if '-jsdebugger' in self.app_args:
profile_args["preferences"].update({
"devtools.browsertoolbox.panel": "jsdebugger",
"devtools.debugger.remote-enabled": True,
"devtools.chrome.enabled": True,
"devtools.debugger.prompt-connection": False,
"marionette.debugging.clicktostart": True,
})
if self.addons:
profile_args['addons'] = self.addons
if hasattr(self, "profile_path") and self.profile is None:
if not self.profile_path:
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
self.profile = Profile.clone(**profile_args)
process_args = {
'processOutputLine': [NullOutput()],
}
if self.gecko_log == '-':
process_args['stream'] = sys.stdout
else:
process_args['logfile'] = self.gecko_log
env = os.environ.copy()
# environment variables needed for crashreporting
# https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
env.update({ 'MOZ_CRASHREPORTER': '1',
'MOZ_CRASHREPORTER_NO_REPORT': '1', })
self.runner = Runner(
binary=self.bin,
profile=self.profile,
cmdargs=['-no-remote', '-marionette'] + self.app_args,
env=env,
symbols_path=self.symbols_path,
process_args=process_args)
self.runner.start()
def close(self, restart=False):
if not restart:
self.profile = None
if self.runner:
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None, clean=True):
self.close(restart=True)
if clean:
self.profile.cleanup()
self.profile = None
if prefs:
self.prefs = prefs
else:
self.prefs = None
self.start()
示例4: GeckoInstance
# 需要导入模块: from mozprofile import Profile [as 别名]
# 或者: from mozprofile.Profile import cleanup [as 别名]
#.........这里部分代码省略.........
self.runner = None
self.symbols_path = symbols_path
self.gecko_log = gecko_log
def start(self):
profile_args = {"preferences": deepcopy(self.required_prefs)}
profile_args["preferences"]["marionette.defaultPrefs.port"] = self.marionette_port
if self.prefs:
profile_args["preferences"].update(self.prefs)
if "-jsdebugger" in self.app_args:
profile_args["preferences"].update(
{
"devtools.browsertoolbox.panel": "jsdebugger",
"devtools.debugger.remote-enabled": True,
"devtools.debugger.chrome-enabled": True,
"devtools.chrome.enabled": True,
"devtools.debugger.prompt-connection": False,
"marionette.debugging.clicktostart": True,
}
)
if hasattr(self, "profile_path") and self.profile is None:
if not self.profile_path:
profile_args["restore"] = False
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
self.profile = Profile.clone(**profile_args)
process_args = {"processOutputLine": [NullOutput()]}
if self.gecko_log == "-":
process_args["stream"] = sys.stdout
else:
if self.gecko_log is None:
self.gecko_log = "gecko.log"
elif os.path.isdir(self.gecko_log):
fname = "gecko-%d.log" % time.time()
self.gecko_log = os.path.join(self.gecko_log, fname)
self.gecko_log = os.path.realpath(self.gecko_log)
if os.access(self.gecko_log, os.F_OK):
if platform.system() is "Windows":
# NOTE: windows has a weird filesystem where it happily 'closes'
# the file, but complains if you try to delete it. You get a
# 'file still in use' error. Sometimes you can wait a bit and
# a retry will succeed.
# If all retries fail, we'll just continue without removing
# the file. In this case, if we are restarting the instance,
# then the new logs just get appended to the old file.
tries = 0
while tries < 10:
try:
os.remove(self.gecko_log)
break
except WindowsError as e:
if e.errno == errno.EACCES:
tries += 1
time.sleep(0.5)
else:
raise e
else:
os.remove(self.gecko_log)
process_args["logfile"] = self.gecko_log
env = os.environ.copy()
# environment variables needed for crashreporting
# https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
env.update({"MOZ_CRASHREPORTER": "1", "MOZ_CRASHREPORTER_NO_REPORT": "1"})
self.runner = Runner(
binary=self.bin,
profile=self.profile,
cmdargs=["-no-remote", "-marionette"] + self.app_args,
env=env,
symbols_path=self.symbols_path,
process_args=process_args,
)
self.runner.start()
def close(self, restart=False):
if not restart:
self.profile = None
if self.runner:
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None, clean=True):
if clean:
self.profile.cleanup()
self.profile = None
self.close(restart=True)
if prefs:
self.prefs = prefs
else:
self.prefs = None
self.start()
示例5: GeckoInstance
# 需要导入模块: from mozprofile import Profile [as 别名]
# 或者: from mozprofile.Profile import cleanup [as 别名]
#.........这里部分代码省略.........
profile_args["preferences"].update(self.prefs)
if self.verbose:
level = "TRACE" if self.verbose >= 2 else "DEBUG"
profile_args["preferences"]["marionette.logging"] = level
if "-jsdebugger" in self.app_args:
profile_args["preferences"].update({
"devtools.browsertoolbox.panel": "jsdebugger",
"devtools.debugger.remote-enabled": True,
"devtools.chrome.enabled": True,
"devtools.debugger.prompt-connection": False,
"marionette.debugging.clicktostart": True,
})
if self.addons:
profile_args["addons"] = self.addons
if hasattr(self, "profile_path") and self.profile is None:
if not self.profile_path:
if self.workspace:
profile_args["profile"] = tempfile.mkdtemp(
suffix=".mozrunner-{:.0f}".format(time.time()),
dir=self.workspace)
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
profile_name = "{}-{:.0f}".format(
os.path.basename(self.profile_path),
time.time()
)
if self.workspace:
profile_args["path_to"] = os.path.join(self.workspace,
profile_name)
self.profile = Profile.clone(**profile_args)
@classmethod
def create(cls, app=None, *args, **kwargs):
try:
if not app:
app_id = mozversion.get_version(binary=kwargs.get('bin'))['application_id']
app = app_ids[app_id]
instance_class = apps[app]
except KeyError:
msg = 'Application "{0}" unknown (should be one of {1})'
raise NotImplementedError(msg.format(app, apps.keys()))
return instance_class(*args, **kwargs)
def start(self):
self._update_profile()
self.runner = self.runner_class(**self._get_runner_args())
self.runner.start()
def _get_runner_args(self):
process_args = {
"processOutputLine": [NullOutput()],
}
if self.gecko_log == "-":
process_args["stream"] = sys.stdout
else:
process_args["logfile"] = self.gecko_log
env = os.environ.copy()
# environment variables needed for crashreporting
# https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
env.update({"MOZ_CRASHREPORTER": "1",
"MOZ_CRASHREPORTER_NO_REPORT": "1",
"MOZ_CRASHREPORTER_SHUTDOWN": "1",
})
return {
"binary": self.binary,
"profile": self.profile,
"cmdargs": ["-no-remote", "-marionette"] + self.app_args,
"env": env,
"symbols_path": self.symbols_path,
"process_args": process_args
}
def close(self, restart=False):
if not restart:
self.profile = None
if self.runner:
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None, clean=True):
self.close(restart=True)
if clean and self.profile:
self.profile.cleanup()
self.profile = None
if prefs:
self.prefs = prefs
else:
self.prefs = None
self.start()
示例6: GeckoInstance
# 需要导入模块: from mozprofile import Profile [as 别名]
# 或者: from mozprofile.Profile import cleanup [as 别名]
#.........这里部分代码省略.........
self.profile_path = profile
self.prefs = prefs
self.required_prefs = deepcopy(GeckoInstance.required_prefs)
if prefs:
self.required_prefs.update(prefs)
self.app_args = app_args or []
self.runner = None
self.symbols_path = symbols_path
if gecko_log != "-":
if gecko_log is None:
gecko_log = "gecko.log"
elif os.path.isdir(gecko_log):
fname = "gecko-%d.log" % time.time()
gecko_log = os.path.join(gecko_log, fname)
gecko_log = os.path.realpath(gecko_log)
if os.access(gecko_log, os.F_OK):
os.remove(gecko_log)
self.gecko_log = gecko_log
self.verbose = verbose
def start(self):
profile_args = {"preferences": deepcopy(self.required_prefs)}
profile_args["preferences"]["marionette.defaultPrefs.port"] = self.marionette_port
if self.prefs:
profile_args["preferences"].update(self.prefs)
if self.verbose:
level = "TRACE" if self.verbose >= 2 else "DEBUG"
profile_args["preferences"]["marionette.logging"] = level
if "-jsdebugger" in self.app_args:
profile_args["preferences"].update(
{
"devtools.browsertoolbox.panel": "jsdebugger",
"devtools.debugger.remote-enabled": True,
"devtools.chrome.enabled": True,
"devtools.debugger.prompt-connection": False,
"marionette.debugging.clicktostart": True,
}
)
if self.addons:
profile_args["addons"] = self.addons
if hasattr(self, "profile_path") and self.profile is None:
if not self.profile_path:
if self.workspace:
profile_args["profile"] = tempfile.mkdtemp(
suffix=".mozrunner-{:.0f}".format(time.time()), dir=self.workspace
)
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
profile_name = "{}-{:.0f}".format(os.path.basename(self.profile_path), time.time())
if self.workspace:
profile_args["path_to"] = os.path.join(self.workspace, profile_name)
self.profile = Profile.clone(**profile_args)
process_args = {"processOutputLine": [NullOutput()]}
if self.gecko_log == "-":
process_args["stream"] = sys.stdout
else:
process_args["logfile"] = self.gecko_log
env = os.environ.copy()
# environment variables needed for crashreporting
# https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
env.update({"MOZ_CRASHREPORTER": "1", "MOZ_CRASHREPORTER_NO_REPORT": "1"})
self.runner = Runner(
binary=self.bin,
profile=self.profile,
cmdargs=["-no-remote", "-marionette"] + self.app_args,
env=env,
symbols_path=self.symbols_path,
process_args=process_args,
)
self.runner.start()
def close(self, restart=False):
if not restart:
self.profile = None
if self.runner:
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None, clean=True):
self.close(restart=True)
if clean:
self.profile.cleanup()
self.profile = None
if prefs:
self.prefs = prefs
else:
self.prefs = None
self.start()