forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
162 lines (132 loc) · 6.63 KB
/
Copy pathweb.py
File metadata and controls
162 lines (132 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import copy
import logging
import shutil
from gettext import gettext as _
from pulp.common.config import read_json_config
from pulp.plugins.distributor import Distributor
from pulp_python.common import constants
from pulp_python.plugins.distributors import configuration
from pulp_python.plugins.distributors.steps import PythonPublisher
PLUGIN_DEFAULT_CONFIG = {
constants.CONFIG_KEY_PUBLISH_DIRECTORY: constants.CONFIG_VALUE_PUBLISH_DIRECTORY
}
_logger = logging.getLogger(__name__)
def entry_point():
"""
Entry point that pulp platform uses to load the distributor
:return: distributor class and its config
:rtype: Distributor, dict
"""
plugin_config = copy.deepcopy(PLUGIN_DEFAULT_CONFIG)
edited_config = read_json_config(constants.DISTRIBUTOR_CONFIG_FILE_NAME)
plugin_config.update(edited_config)
return PythonDistributor, plugin_config
class PythonDistributor(Distributor):
"""
This distributor is for use with the pip client.
"""
@classmethod
def metadata(cls):
"""
Used by Pulp to classify the capabilities of this distributor. The
following keys must be present in the returned dictionary:
* id - Programmatic way to refer to this distributor. Must be unique
across all distributors. Only letters and underscores are valid.
* display_name - User-friendly identification of the distributor.
* types - List of all content type IDs that may be published using this
distributor.
:return: keys and values listed above
:rtype: dict
"""
return {
'id': constants.DISTRIBUTOR_TYPE_ID,
'display_name': _('Python Python Distributor'),
'types': [constants.PACKAGE_TYPE_ID]
}
def __init__(self):
"""
Initialize the PythonDistributor.
"""
super(PythonDistributor, self).__init__()
self._publisher = None
self.canceled = False
def publish_repo(self, repo, publish_conduit, config):
"""
Publishes the given repository.
While this call may be implemented using multiple threads, its execution
from the Pulp server's standpoint should be synchronous. This call should
not return until the publish is complete.
It is not expected that this call be atomic. Should an error occur, it
is not the responsibility of the distributor to rollback any changes
that have been made.
:param repo: metadata describing the repository
:type repo: pulp.plugins.model.Repository
:param publish_conduit: provides access to relevant Pulp functionality
:type publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit
:param config: plugin configuration
:type config: pulp.plugins.config.PluginConfiguration
:return: report describing the publish run
:rtype: pulp.plugins.model.PublishReport
"""
_logger.debug('Publishing Python repository: %s' % repo.id)
self._publisher = PythonPublisher(repo, publish_conduit, config)
return self._publisher.process_lifecycle()
def cancel_publish_repo(self):
"""
Call cancellation control hook.
"""
_logger.debug('Canceling Python repository publish')
self.canceled = True
if self._publisher is not None:
self._publisher.cancel()
def distributor_removed(self, repo, config):
"""
Called when a distributor of this type is removed from a repository.
This hook allows the distributor to clean up any files that may have
been created during the actual publishing.
The distributor may use the contents of the working directory in cleanup.
It is not required that the contents of this directory be deleted by
the distributor; Pulp will ensure it is wiped following this call.
If this call raises an exception, the distributor will still be removed
from the repository and the working directory contents will still be
wiped by Pulp.
:param repo: metadata describing the repository
:type repo: pulp.plugins.model.Repository
:param config: plugin configuration
:type config: pulp.plugins.config.PluginCallConfiguration
"""
# remove the directories that might have been created for this repo/distributor
dir_list = [repo.working_dir,
configuration.get_master_publish_dir(repo, config),
configuration.get_web_publish_dir(repo, config)]
for repo_dir in dir_list:
shutil.rmtree(repo_dir, ignore_errors=True)
def validate_config(self, repo, config, config_conduit):
"""
Allows the distributor to check the contents of a potential configuration
for the given repository. This call is made both for the addition of
this distributor to a new repository as well as updating the configuration
for this distributor on a previously configured repository. The implementation
should use the given repository data to ensure that updating the
configuration does not put the repository into an inconsistent state.
The return is a tuple of the result of the validation (True for success,
False for failure) and a message. The message may be None and is unused
in the success case. For a failed validation, the message will be
communicated to the caller so the plugin should take i18n into
consideration when generating the message.
The related_repos parameter contains a list of other repositories that
have a configured distributor of this type. The distributor configurations
is found in each repository in the "plugin_configs" field.
:param repo: metadata describing the repository to which the
configuration applies
:type repo: pulp.plugins.model.Repository
:param config: plugin configuration instance; the proposed repo
configuration is found within
:type config: pulp.plugins.config.PluginCallConfiguration
:param config_conduit: Configuration Conduit;
:type config_conduit: pulp.plugins.conduits.repo_config.RepoConfigConduit
:return: tuple of (bool, str) to describe the result
:rtype: tuple
:raises: PulpCodedValidationException if any validations failed
"""
return configuration.validate_config(config)