本文整理汇总了Python中plainbox.impl.session.SessionState.resume方法的典型用法代码示例。如果您正苦于以下问题:Python SessionState.resume方法的具体用法?Python SessionState.resume怎么用?Python SessionState.resume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plainbox.impl.session.SessionState
的用法示例。
在下文中一共展示了SessionState.resume方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_jobs
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import resume [as 别名]
def _run_jobs(self, ns, job_list, exporter, transport=None):
# Compute the run list, this can give us notification about problems in
# the selected jobs. Currently we just display each problem
matching_job_list = self._get_matching_job_list(ns, job_list)
print("[ Analyzing Jobs ]".center(80, '='))
# Create a session that handles most of the stuff needed to run jobs
try:
session = SessionState(job_list)
except DependencyDuplicateError as exc:
# Handle possible DependencyDuplicateError that can happen if
# someone is using plainbox for job development.
print("The job database you are currently using is broken")
print("At least two jobs contend for the name {0}".format(
exc.job.name))
print("First job defined in: {0}".format(exc.job.origin))
print("Second job defined in: {0}".format(
exc.duplicate_job.origin))
raise SystemExit(exc)
with session.open():
if session.previous_session_file():
if self.ask_for_resume():
session.resume()
else:
session.clean()
self._update_desired_job_list(session, matching_job_list)
if (sys.stdin.isatty() and sys.stdout.isatty() and not
ns.not_interactive):
outcome_callback = self.ask_for_outcome
else:
outcome_callback = None
runner = JobRunner(
session.session_dir,
session.jobs_io_log_dir,
outcome_callback=outcome_callback,
dry_run=ns.dry_run
)
self._run_jobs_with_session(ns, session, runner)
# Get a stream with exported session data.
exported_stream = io.BytesIO()
data_subset = exporter.get_session_data_subset(session)
exporter.dump(data_subset, exported_stream)
exported_stream.seek(0) # Need to rewind the file, puagh
# Write the stream to file if requested
self._save_results(ns.output_file, exported_stream)
# Invoke the transport?
if transport:
exported_stream.seek(0)
try:
transport.send(exported_stream.read())
except InvalidSchema as exc:
print("Invalid destination URL: {0}".format(exc))
except ConnectionError as exc:
print(("Unable to connect "
"to destination URL: {0}").format(exc))
except HTTPError as exc:
print(("Server returned an error when "
"receiving or processing: {0}").format(exc))
# FIXME: sensible return value
return 0
示例2: SessionStateLocalStorageTests
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import resume [as 别名]
class SessionStateLocalStorageTests(TestCase):
def setUp(self):
# session data are kept in XDG_CACHE_HOME/plainbox/.session
# To avoid resuming a real session, we have to select a temporary
# location instead
self._sandbox = tempfile.mkdtemp()
self._env = os.environ
os.environ['XDG_CACHE_HOME'] = self._sandbox
def job_state(self, name):
# A helper function to avoid overly long expressions
return self.session.job_state_map[name]
def test_persistent_save(self):
self.job_A = make_job("A")
self.job_list = [self.job_A]
self.session = SessionState(self.job_list)
result_A = JobResult({
'job': self.job_A,
'outcome': JobResult.OUTCOME_PASS,
'comments': 'All good',
'return_code': 0,
'io_log': ((0, 'stdout', "Success !\n"),)
})
session_json_text = """{
"_job_state_map": {
"A": {
"_job": {
"data": {
"name": "A",
"plugin": "dummy",
"requires": null,
"depends": null
},
"_class_id": "JOB_DEFINITION"
},
"_result": {
"data": {
"job": {
"data": {
"name": "A",
"plugin": "dummy",
"requires": null,
"depends": null
},
"_class_id": "JOB_DEFINITION"
},
"outcome": "pass",
"return_code": 0,
"comments": "All good",
"io_log": [
[
0,
"stdout",
"Success !\\n"
]
]
},
"_class_id": "JOB_RESULT"
},
"_class_id": "JOB_STATE"
}
},
"_desired_job_list": [
{
"data": {
"name": "A",
"plugin": "dummy",
"requires": null,
"depends": null
},
"_class_id": "JOB_DEFINITION"
}
],
"_class_id": "SESSION_STATE"
}"""
self.session.open()
self.session.update_desired_job_list([self.job_A])
self.session.update_job_result(self.job_A, result_A)
self.session.persistent_save()
session_file = self.session.previous_session_file()
self.session.close()
self.assertIsNotNone(session_file)
with open(session_file) as f:
raw_json = json.load(f)
self.maxDiff = None
self.assertEqual(raw_json, json.loads(session_json_text))
def test_resume_session(self):
# All of the tests below are using one session. The session has four
# jobs, Job A depends on a resource provided by job R which has no
# dependencies at all. Both Job X and Y depend on job A.
#
# A -(resource dependency)-> R
#
# X -(direct dependency) -> A
#
# Y -(direct dependency) -> A
self.job_A = make_job("A", requires="R.attr == 'value'")
#.........这里部分代码省略.........