本文整理汇总了Python中pulp_puppet.common.sync_progress.SyncProgressReport.build_final_report方法的典型用法代码示例。如果您正苦于以下问题:Python SyncProgressReport.build_final_report方法的具体用法?Python SyncProgressReport.build_final_report怎么用?Python SyncProgressReport.build_final_report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp_puppet.common.sync_progress.SyncProgressReport
的用法示例。
在下文中一共展示了SyncProgressReport.build_final_report方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SynchronizeWithPuppetForge
# 需要导入模块: from pulp_puppet.common.sync_progress import SyncProgressReport [as 别名]
# 或者: from pulp_puppet.common.sync_progress.SyncProgressReport import build_final_report [as 别名]
class SynchronizeWithPuppetForge(object):
"""
Used to perform a single sync of a puppet repository. This class will
maintain state relevant to the run and should not be reused across runs.
"""
def __init__(self, repo, sync_conduit, config):
self.repo = repo
self.sync_conduit = sync_conduit
self.config = config
self.progress_report = SyncProgressReport(sync_conduit)
self.downloader = None
# Since SynchronizeWithPuppetForge creats a Nectar downloader for each unit, we cannot
# rely on telling the current downloader to cancel. Therefore, we need another state tracker
# to check in the download units loop.
self._canceled = False
def __call__(self):
"""
Performs the sync operation according to the configured state of the
instance. The report to be sent back to Pulp is returned from this
call. This call will make calls into the conduit's progress update
as appropriate.
This call executes serially. No threads are created by this call. It
will not return until either a step fails or the entire sync is
completed.
:return: the report object to return to Pulp from the sync call
:rtype: SyncProgressReport
"""
_logger.info('Beginning sync for repository <%s>' % self.repo.id)
# quit now if there is no feed URL defined
if not self.config.get(constants.CONFIG_FEED):
self.progress_report.metadata_state = STATE_FAILED
self.progress_report.metadata_error_message = _(
'Cannot perform repository sync on a repository with no feed')
self.progress_report.update_progress()
return self.progress_report.build_final_report()
try:
metadata = self._parse_metadata()
if not metadata:
report = self.progress_report.build_final_report()
return report
self._import_modules(metadata)
finally:
# One final progress update before finishing
self.progress_report.update_progress()
return self.progress_report
def cancel(self):
"""
Cancel an in-progress sync, if there is one.
"""
self._canceled = True
if self.downloader is None:
return
self.downloader.cancel()
def _parse_metadata(self):
"""
Takes the necessary actions (according to the run configuration) to
retrieve and parse the repository's metadata. This call will return
either the successfully parsed metadata or None if it could not
be retrieved or parsed. The progress report will be updated with the
appropriate description of what went wrong in the event of an error,
so the caller should interpet a None return as an error occuring and
not continue the sync.
:return: object representation of the metadata
:rtype: RepositoryMetadata
"""
_logger.info('Beginning metadata retrieval for repository <%s>' % self.repo.id)
self.progress_report.metadata_state = STATE_RUNNING
self.progress_report.update_progress()
start_time = datetime.now()
# Retrieve the metadata from the source
try:
downloader = self._create_downloader()
self.downloader = downloader
metadata_json_docs = downloader.retrieve_metadata(self.progress_report)
except Exception, e:
if self._canceled:
_logger.warn('Exception occurred on canceled metadata download: %s' % e)
self.progress_report.metadata_state = STATE_CANCELED
return None
_logger.exception('Exception while retrieving metadata for repository <%s>' % self.repo.id)
self.progress_report.metadata_state = STATE_FAILED
self.progress_report.metadata_error_message = _('Error downloading metadata')
self.progress_report.metadata_exception = e
self.progress_report.metadata_traceback = sys.exc_info()[2]
#.........这里部分代码省略.........
示例2: SynchronizeWithPuppetForge
# 需要导入模块: from pulp_puppet.common.sync_progress import SyncProgressReport [as 别名]
# 或者: from pulp_puppet.common.sync_progress.SyncProgressReport import build_final_report [as 别名]
class SynchronizeWithPuppetForge(object):
"""
Used to perform a single sync of a puppet repository. This class will
maintain state relevant to the run and should not be reused across runs.
"""
def __init__(self, repo, sync_conduit, config):
self.repo = repo
self.sync_conduit = sync_conduit
self.config = config
self.progress_report = SyncProgressReport(sync_conduit)
self.downloader = None
# Since SynchronizeWithPuppetForge creates a Nectar downloader for each unit, we cannot
# rely on telling the current downloader to cancel. Therefore, we need another state
# tracker to check in the download units loop.
self._canceled = False
def __call__(self):
"""
Sync according to the configured state of the instance and return a report.
This function will make update progress as appropriate.
This function executes serially, and does not create any threads. It will not return until
either a step fails or the entire sync is complete.
:return: the report object to return to Pulp from the sync call
:rtype: SyncProgressReport
"""
msg = _('Beginning sync for repository <%(repo_id)s>')
msg_dict = {'repo_id': self.repo.id}
_logger.info(msg, msg_dict)
# quit now if there is no feed URL defined
if not self.config.get(constants.CONFIG_FEED):
self.progress_report.metadata_state = STATE_FAILED
msg = _('Cannot perform repository sync on a repository with no feed')
self.progress_report.metadata_error_message = msg
self.progress_report.update_progress()
return self.progress_report.build_final_report()
try:
metadata = self._parse_metadata()
if not metadata:
report = self.progress_report.build_final_report()
return report
self._import_modules(metadata)
finally:
# One final progress update before finishing
self.progress_report.update_progress()
return self.progress_report
def cancel(self):
"""
Cancel an in-progress sync, if there is one.
"""
self._canceled = True
if self.downloader is None:
return
self.downloader.cancel()
def _parse_metadata(self):
"""
Takes the necessary actions (according to the run configuration) to
retrieve and parse the repository's metadata. This call will return
either the successfully parsed metadata or None if it could not
be retrieved or parsed. The progress report will be updated with the
appropriate description of what went wrong in the event of an error,
so the caller should interpret a None return as an error occurring and
not continue the sync.
:return: object representation of the metadata
:rtype: RepositoryMetadata
"""
msg = _('Beginning metadata retrieval for repository <%(repo_id)s>')
msg_dict = {'repo_id': self.repo.id}
_logger.info(msg, msg_dict)
self.progress_report.metadata_state = STATE_RUNNING
self.progress_report.update_progress()
start_time = datetime.now()
# Retrieve the metadata from the source
try:
downloader = self._create_downloader()
self.downloader = downloader
metadata_json_docs = downloader.retrieve_metadata(self.progress_report)
except Exception as e:
if self._canceled:
msg = _('Exception occurred on canceled metadata download: %(exc)s')
msg_dict = {'exc': e}
_logger.warn(msg, msg_dict)
self.progress_report.metadata_state = STATE_CANCELED
return None
msg = _('Exception while retrieving metadata for repository <%(repo_id)s>')
#.........这里部分代码省略.........
示例3: PuppetModuleSyncRun
# 需要导入模块: from pulp_puppet.common.sync_progress import SyncProgressReport [as 别名]
# 或者: from pulp_puppet.common.sync_progress.SyncProgressReport import build_final_report [as 别名]
class PuppetModuleSyncRun(object):
"""
Used to perform a single sync of a puppet repository. This class will
maintain state relevant to the run and should not be reused across runs.
"""
def __init__(self, repo, sync_conduit, config, is_cancelled_call):
self.repo = repo
self.sync_conduit = sync_conduit
self.config = config
self.is_cancelled_call = is_cancelled_call
self.progress_report = SyncProgressReport(sync_conduit)
def perform_sync(self):
"""
Performs the sync operation according to the configured state of the
instance. The report to be sent back to Pulp is returned from this
call. This call will make calls into the conduit's progress update
as appropriate.
This call executes serially. No threads are created by this call. It
will not return until either a step fails or the entire sync is
completed.
:return: the report object to return to Pulp from the sync call
:rtype: pulp.plugins.model.SyncReport
"""
_LOG.info('Beginning sync for repository <%s>' % self.repo.id)
try:
metadata = self._parse_metadata()
if not metadata:
report = self.progress_report.build_final_report()
return report
self._import_modules(metadata)
finally:
# One final progress update before finishing
self.progress_report.update_progress()
report = self.progress_report.build_final_report()
return report
def _parse_metadata(self):
"""
Takes the necessary actions (according to the run configuration) to
retrieve and parse the repository's metadata. This call will return
either the successfully parsed metadata or None if it could not
be retrieved or parsed. The progress report will be updated with the
appropriate description of what went wrong in the event of an error,
so the caller should interpet a None return as an error occuring and
not continue the sync.
:return: object representation of the metadata
:rtype: RepositoryMetadata
"""
_LOG.info('Beginning metadata retrieval for repository <%s>' % self.repo.id)
self.progress_report.metadata_state = STATE_RUNNING
self.progress_report.update_progress()
start_time = datetime.now()
# Retrieve the metadata from the source
try:
downloader = self._create_downloader()
metadata_json_docs = downloader.retrieve_metadata(self.progress_report)
except Exception, e:
_LOG.exception('Exception while retrieving metadata for repository <%s>' % self.repo.id)
self.progress_report.metadata_state = STATE_FAILED
self.progress_report.metadata_error_message = _('Error downloading metadata')
self.progress_report.metadata_exception = e
self.progress_report.metadata_traceback = sys.exc_info()[2]
end_time = datetime.now()
duration = end_time - start_time
self.progress_report.metadata_execution_time = duration.seconds
self.progress_report.update_progress()
return None
# Parse the retrieved metadata documents
try:
metadata = RepositoryMetadata()
for doc in metadata_json_docs:
metadata.update_from_json(doc)
except Exception, e:
_LOG.exception('Exception parsing metadata for repository <%s>' % self.repo.id)
self.progress_report.metadata_state = STATE_FAILED
self.progress_report.metadata_error_message = _('Error parsing repository modules metadata document')
self.progress_report.metadata_exception = e
self.progress_report.metadata_traceback = sys.exc_info()[2]
end_time = datetime.now()
duration = end_time - start_time
self.progress_report.metadata_execution_time = duration.seconds
self.progress_report.update_progress()
#.........这里部分代码省略.........