本文整理汇总了Python中plainbox.impl.session.SessionState.persistent_save方法的典型用法代码示例。如果您正苦于以下问题:Python SessionState.persistent_save方法的具体用法?Python SessionState.persistent_save怎么用?Python SessionState.persistent_save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plainbox.impl.session.SessionState
的用法示例。
在下文中一共展示了SessionState.persistent_save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import persistent_save [as 别名]
#.........这里部分代码省略.........
self.session.session_dir,
self.session.jobs_io_log_dir,
command_io_delegate=self,
outcome_callback=None, # SRU runs are never interactive
dry_run=self.ns.dry_run
)
self._run_all_jobs()
if self.config.fallback_file is not Unset:
self._save_results()
self._submit_results()
# FIXME: sensible return value
return 0
def _set_job_selection(self):
desired_job_list = get_matching_job_list(self.job_list, self.whitelist)
problem_list = self.session.update_desired_job_list(desired_job_list)
if problem_list:
logger.warning("There were some problems with the selected jobs")
for problem in problem_list:
logger.warning("- %s", problem)
logger.warning("Problematic jobs will not be considered")
def _save_results(self):
print("Saving results to {0}".format(self.config.fallback_file))
data = self.exporter.get_session_data_subset(self.session)
with open(self.config.fallback_file, "wt", encoding="UTF-8") as stream:
translating_stream = ByteStringStreamTranslator(stream, "UTF-8")
self.exporter.dump(data, translating_stream)
def _submit_results(self):
print("Submitting results to {0} for secure_id {1}".format(
self.config.c3_url, self.config.secure_id))
options_string = "secure_id={0}".format(self.config.secure_id)
# Create the transport object
try:
transport = CertificationTransport(
self.config.c3_url, options_string, self.config)
except InvalidSecureIDError as exc:
print(exc)
return False
# Prepare the data for submission
data = self.exporter.get_session_data_subset(self.session)
with tempfile.NamedTemporaryFile(mode='w+b') as stream:
# Dump the data to the temporary file
self.exporter.dump(data, stream)
# Flush and rewind
stream.flush()
stream.seek(0)
try:
# Send the data, reading from the temporary file
result = transport.send(stream)
if 'url' in result:
print("Successfully sent, submission status at {0}".format(
result['url']))
else:
print("Successfully sent, server response: {0}".format(
result))
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))
except IOError as exc:
print("Problem reading a file: {0}".format(exc))
def _run_all_jobs(self):
again = True
while again:
again = False
for job in self.session.run_list:
# Skip jobs that already have result, this is only needed when
# we run over the list of jobs again, after discovering new
# jobs via the local job output
result = self.session.job_state_map[job.name].result
if result.outcome is not None:
continue
self._run_single_job(job)
self.session.persistent_save()
if job.plugin == "local":
# After each local job runs rebuild the list of matching
# jobs and run everything again
self._set_job_selection()
again = True
break
def _run_single_job(self, job):
print("- {}:".format(job.name), end=' ')
job_state, job_result = run_job_if_possible(
self.session, self.runner, self.config, job)
print("{0}".format(job_result.outcome))
if job_result.comments is not None:
print("comments: {0}".format(job_result.comments))
if job_state.readiness_inhibitor_list:
print("inhibitors:")
for inhibitor in job_state.readiness_inhibitor_list:
print(" * {}".format(inhibitor))
self.session.update_job_result(job, job_result)
示例2: SessionStateLocalStorageTests
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import persistent_save [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'")
#.........这里部分代码省略.........