34
32
return config.NameMatcher(self, None).get_sections()
35
class ImporterStack(config.Stack):
36
"""Configuration stack for the importer.
38
The ``pkgimport.conf`` file defines the configuration options for the
39
importer itself, especially all the directories that are used at
40
runtime. These options can be overridden in ``locations.conf`` by using a
41
section named after the directory used for deployment.
44
def __init__(self, possible_transports=None):
45
t = transport.get_transport(_root_dir,
46
possible_transports=possible_transports)
47
location_store = config.LocationStore()
48
loc_matcher = config.LocationMatcher(location_store, _root_dir)
49
pkgimport_store = PkgimportStore(t)
50
super(ImporterStack, self).__init__(
52
# locations.conf can override any option, based on the tree
54
loc_matcher.get_sections,
55
# Otherwise we use pkgimport.conf
56
pkgimport_store.get_common_sections,
59
def get(self, name, expand=True):
60
"""Override base class to expand by default."""
61
return super(ImporterStack, self).get(name, expand)
37
64
class PackageStack(config.Stack):
38
"""Configuration stack for a package to be imported."""
65
"""Configuration stack for a package to be imported.
67
Options specific to a package are defined in a section named after the
68
package. Failing that, the no-name section defines the options common to
40
72
def __init__(self, package_name, possible_transports=None):
41
73
t = transport.get_transport(_root_dir,
64
96
config.option_registry.register(config.Option(*args, **kwargs))
67
register_option('pkgimport.max_duration',
99
# 'pi' stands for Package Import and is used as a prefix for all related
102
register_option('pi.install_dir', default=_root_dir,
103
help='Base directory where udd scripts are run from.')
105
# Common to all scripts:
106
register_option('pi.base_dir',
107
default='/srv/package-import.canonical.com/new',
108
help='Base directory for the udd scripts.')
109
register_option('pi.log_dir', default='{pi.base_dir}/logs',
110
help='Base directory for the log files.')
111
register_option('pi.locks_dir', default='{pi.base_dir}/locks',
112
help='Base directory for the lock files.')
113
register_option('pi.distributions', default='debian,ubuntu',
114
from_unicode=config.list_from_store,
115
help='''Which distributions to operate on.
117
Affect the behaviour of add-import-jobs and list-packages.
119
register_option('pi.retry_all_failed_jobs', default='False',
120
from_unicode=config.bool_from_store,
121
help='''Whether or not to retry all failed jobs.
123
All failed imports are retried when set. Otherwise only the import jobs that
124
were currently running the supervisor died are retried.
128
# Databases (common across multiple components):
129
register_option('pi.sqlite_file', default = '{pi.base_dir}/meta.db',
130
help='Main database for the package importer.')
131
register_option('pi.sqlite_package_file', default = '{pi.base_dir}/packages.db',
132
help='Packages database for the package importer.')
133
register_option('pi.sqlite_history_file', default = '{pi.base_dir}/history.db',
134
help='History database for the package importer.')
137
# Paths common across multiple components:
138
register_option('pi.package_locks_dir', default = '{pi.locks_dir}/packages',
139
help='Directory for package exclusive lock files.')
140
register_option('pi.script_locks_dir', default = '{pi.locks_dir}/scripts',
141
help='Directory for script exclusive lock files.')
142
register_option('pi.www_dir', default = '{pi.base_dir}/www',
143
help='Directory for publishing web pages.')
144
# The explanations file contains tracebacks - these are highly sensitive to
145
# changes in the code, so are kept alongside the code.
146
register_option('pi.explanations_file', default='{pi.install_dir}/explanations',
147
help='Explanations for import failures.')
150
# Used by mass_import:
151
register_option('pi.import_command',
152
default='{pi.install_dir}/bin/import-package {package}',
153
help='''Command used to import a package.
155
{package} is provided when the command is expanded and contains the package
158
register_option('pi.driver.log_dir', default='{pi.log_dir}/driver',
159
help='Directory for the import driver log files.')
160
register_option('pi.driver.log.debug', default='{pi.driver.log_dir}/debug_log',
161
help='Import driver debug log file.')
162
register_option('pi.driver.log.progress',
163
default='{pi.driver.log_dir}/progress_log',
164
help='Import package driver progress log file.')
165
register_option('pi.stop_file', default='{pi.base_dir}/STOP_PLEASE',
166
help="A touch'ed file to stop the importer gracefully.")
167
register_option('pi.max_threads_file', default='{pi.base_dir}/max_threads',
168
help='A file containing the maximum number'
169
' of parallel imports.')
172
# Used by import_package.py:
173
register_option('pi.packages.log_dir', default='{pi.log_dir}/packages',
174
help='Base directory for the log files.')
175
register_option('pi.lists_dir', default='{pi.base_dir}/lists',
176
help='Directory for distribution description mirrors.')
177
register_option('pi.download_cache_dir', default='{pi.base_dir}/download-cache',
178
help='Directory for caching downloaded source packages.')
179
register_option('pi.localbranches_dir', default='{pi.base_dir}/localbranches',
180
help='Directory for caching local branches when debugging.')
181
register_option('pi.updates_dir', default='{pi.base_dir}/updates',
182
help='Working directory to prepare packaging branches.')
183
register_option('pi.debian_diffs_dir', default='{pi.www_dir}/diffs',
184
help='Diffs versus debian versions.')
185
register_option('pi.ubuntu_merges_dir', default='{pi.www_dir}/merges',
186
help='Merges against Ubuntu versions.')
189
# Used by categorize_failures.py:
190
register_option('pi.web_status_dir', default = '{pi.www_dir}/status',
191
help='Directory for publishing importer status.')
194
# FIXME: Keeping a local credentials file doesn't feel right, when we have a
195
# newer launchpadlib, we should try to offload this to relying on its APIs.
197
register_option('pi.lp_creds_file', default='{pi.base_dir}/lp_creds.txt',
198
help='Creadentials file to access launchpad.')
201
# Package specific options
202
register_option('pi.max_duration',
68
203
from_unicode=config.int_from_store,
70
205
help='Number of seconds before an import is killed.')
71
register_option('pkgimport.kill.grace_period',
206
register_option('pi.kill.grace_period',
72
207
from_unicode=config.int_from_store,
74
209
help='Number of seconds before killing an import'
75
210
' switch from SIGINT to SIGKILL.')
78
def pkgimportconfig_file_name():
79
new_path = paths.static_file_path('config/pkgimport.conf')
80
old_path = paths.static_file_path('pkgimport.conf')
81
if os.path.exists(new_path):
87
# FIXME: We don't inherit from LockableConfig because we don't want to create a
88
# 'lock' dir alonside the scripts (we should not require write access there and
89
# we don't need to modify options in the configuration file) -- vila 2011-03-22
90
class PkgimportConfig(config.IniBasedConfig):
92
def __init__(self, file_name=None):
94
file_name = pkgimportconfig_file_name()
95
super(PkgimportConfig, self).__init__(file_name=file_name)
101
return self.get_user_option(name)
104
def compatible_get(self, name, default_value=None):
105
value = self.get_user_option(name)
107
value = default_value
111
class ConfigStack(object):
112
"""A stack of configurations where an option can be defined"""
114
def __init__(self, config_list):
116
for c in config_list:
117
if hasattr(c, 'get_user_option') and not hasattr(c, 'get'):
118
c.get = types.MethodType(compatible_get, c, c.__class__)
119
if not hasattr(c, 'get'):
120
raise AssertionError("%r does not provide a 'get' method"
127
if value is not None:
132
class Iconfig(ConfigStack):
133
"""An import packager configuration taking ``locations.conf`` into account.
135
This allows one to override the values in ``pkgimport.conf`` in
136
``locations.conf`` for specified sections.
139
def __init__(self, location=None):
141
location = paths.root_dir
142
super(Iconfig, self).__init__(
143
[config.LocationConfig(location), PkgimportConfig()])
211
register_option('udd.branch_hostname', default='bazaar.launchpad.net',
212
help='Branch hostname.')
213
register_option('udd.branch_owner', default='ubuntu-branches',
214
help='Branch owner as a Launchpad or unix username.')