#NEWLINE# @ do #NEWLINE# def publish_docs( flocker_version , doc_version , environment , routing_config ) : #NEWLINE# #INDENT# "\n    Publish the Flocker documentation. The documentation for each version of\n    Flocker is uploaded to a development bucket on S3 by the build server and\n    this copies the documentation for a particular ``flocker_version`` and\n    publishes it as ``doc_version``. Attempting to publish documentation to a\n    staging environment as a documentation version publishes it as the version\n    being updated.\n\n    :param bytes flocker_version: The version of Flocker to publish the\n        documentation for.\n    :param bytes doc_version: The version to publish the documentation as.\n    :param Environments environment: The environment to publish the\n        documentation to.\n    :param dict routing_config: The loaded routing configuration (see\n        ``parse_routing_rules`` for details).\n    :raises NotARelease: Raised if trying to publish to a version that isn't a\n        release.\n    :raises NotTagged: Raised if publishing to production and the version being\n        published version isn't tagged.\n    " #NEWLINE# if ( not ( is_release ( doc_version ) or is_weekly_release ( doc_version ) or is_pre_release ( doc_version ) ) ) : #NEWLINE# #INDENT# raise NotARelease ( ) #NEWLINE# #UNINDENT# if ( environment == Environments . PRODUCTION ) : #NEWLINE# #INDENT# if ( get_doc_version ( flocker_version ) != doc_version ) : #NEWLINE# #INDENT# raise NotTagged ( ) #NEWLINE# #UNINDENT# #UNINDENT# configuration = DOCUMENTATION_CONFIGURATIONS [ environment ] #NEWLINE# dev_prefix = ( 'release/flocker-%s/' % ( flocker_version , ) ) #NEWLINE# version_prefix = ( 'en/%s/' % ( get_doc_version ( doc_version ) , ) ) #NEWLINE# is_dev = ( not is_release ( doc_version ) ) #NEWLINE# if is_dev : #NEWLINE# #INDENT# stable_prefix = 'en/devel/' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stable_prefix = 'en/latest/' #NEWLINE# #UNINDENT# new_version_keys = ( yield Effect ( ListS3Keys ( bucket = configuration . dev_bucket , prefix = dev_prefix ) ) ) #NEWLINE# existing_version_keys = ( yield Effect ( ListS3Keys ( bucket = configuration . documentation_bucket , prefix = version_prefix ) ) ) #NEWLINE# existing_latest_keys = ( yield Effect ( ListS3Keys ( bucket = configuration . documentation_bucket , prefix = stable_prefix ) ) ) #NEWLINE# ( yield Effect ( CopyS3Keys ( source_bucket = configuration . dev_bucket , source_prefix = dev_prefix , destination_bucket = configuration . documentation_bucket , destination_prefix = version_prefix , keys = new_version_keys ) ) ) #NEWLINE# ( yield Effect ( CopyS3Keys ( source_bucket = configuration . dev_bucket , source_prefix = dev_prefix , destination_bucket = configuration . documentation_bucket , destination_prefix = stable_prefix , keys = new_version_keys ) ) ) #NEWLINE# ( yield Effect ( DeleteS3Keys ( bucket = configuration . documentation_bucket , prefix = version_prefix , keys = ( existing_version_keys - new_version_keys ) ) ) ) #NEWLINE# ( yield Effect ( DeleteS3Keys ( bucket = configuration . documentation_bucket , prefix = stable_prefix , keys = ( existing_latest_keys - new_version_keys ) ) ) ) #NEWLINE# if ( ( environment is Environments . STAGING ) or ( ( environment is Environments . PRODUCTION ) and ( not is_dev ) ) ) : #NEWLINE# #INDENT# ( yield Effect ( UpdateS3ErrorPage ( bucket = configuration . documentation_bucket , target_prefix = version_prefix ) ) ) #NEWLINE# #UNINDENT# changed_keys = ( new_version_keys | existing_version_keys ) #NEWLINE# changed_keys |= { key_name [ : ( - len ( 'index.html' ) ) ] for key_name in changed_keys if key_name . endswith ( '/index.html' ) } #NEWLINE# changed_keys |= { '' } #NEWLINE# changed_paths = { ( prefix + key_name ) for key_name in changed_keys for prefix in [ stable_prefix , version_prefix ] } #NEWLINE# ( yield Effect ( UpdateS3RoutingRules ( bucket = configuration . documentation_bucket , routing_rules = parse_routing_rules ( routing_config , configuration . cloudfront_cname ) ) ) ) #NEWLINE# ( yield Effect ( CreateCloudFrontInvalidation ( cname = configuration . cloudfront_cname , paths = changed_paths ) ) )