build: Do not hardcode package formats in cli code
Now, it is possible to see a list of supported formats with "-F help".
This commit is contained in:
+17
-12
@@ -45,8 +45,6 @@ class Build(command.Command):
|
||||
|
||||
name = ("build", "bi")
|
||||
|
||||
package_formats = ("1.0", "1.1")
|
||||
|
||||
def options(self):
|
||||
self.add_steps_options()
|
||||
group = optparse.OptionGroup(self.parser, _("build options"))
|
||||
@@ -97,9 +95,9 @@ class Build(command.Command):
|
||||
|
||||
group.add_option("-F", "--package-format",
|
||||
action="store",
|
||||
default="1.1",
|
||||
help=_("PiSi binary package formats: "
|
||||
"'1.0', '1.1' (default)"))
|
||||
help=_("Create the binary package using the given "
|
||||
"format. Use '-F help' to see a list of "
|
||||
"supported formats."))
|
||||
|
||||
group.add_option("--use-quilt",
|
||||
action="store_true",
|
||||
@@ -164,19 +162,26 @@ class Build(command.Command):
|
||||
self.parser.add_option_group(group)
|
||||
|
||||
def run(self):
|
||||
if not self.options.quiet:
|
||||
self.options.debug = True
|
||||
|
||||
if self.options.package_format == "help":
|
||||
self.init(False, False)
|
||||
ctx.ui.info(_("Supported package formats:"))
|
||||
build = pisi.operations.build
|
||||
for format in build.Builder.package_formats:
|
||||
if format == build.Builder.default_package_format:
|
||||
ctx.ui.info(_(" %s (default)") % format)
|
||||
else:
|
||||
ctx.ui.info(" %s" % format)
|
||||
return
|
||||
|
||||
if not self.args:
|
||||
self.help()
|
||||
return
|
||||
|
||||
if not self.options.quiet:
|
||||
self.options.debug = True
|
||||
|
||||
self.init()
|
||||
|
||||
if ctx.get_option('package_format') not in Build.package_formats:
|
||||
raise pisi.Error(_("Package format must be one of %s ")
|
||||
% pisi.util.strlist(Build.package_formats))
|
||||
|
||||
if ctx.get_option('output_dir'):
|
||||
ctx.ui.info(_('Output directory: %s')
|
||||
% ctx.config.options.output_dir)
|
||||
|
||||
@@ -166,6 +166,9 @@ class Builder:
|
||||
"""Provides the package build and creation routines"""
|
||||
#FIXME: this class and every other class must use URLs as paths!
|
||||
|
||||
package_formats = ("1.0", "1.1")
|
||||
default_package_format = "1.1"
|
||||
|
||||
@staticmethod
|
||||
def from_name(name):
|
||||
repodb = pisi.db.repodb.RepoDB()
|
||||
@@ -215,6 +218,13 @@ class Builder:
|
||||
self.check_versioning(self.spec.getSourceVersion(),
|
||||
self.spec.getSourceRelease())
|
||||
|
||||
# Check package format
|
||||
self.target_package_format = ctx.get_option("package_format") \
|
||||
or Builder.default_package_format
|
||||
if self.target_package_format not in Builder.package_formats:
|
||||
raise Error(_("Invalid package format: %s")
|
||||
% self.target_package_format)
|
||||
|
||||
self.read_translations(self.specdir)
|
||||
|
||||
self.sourceArchives = pisi.sourcearchive.SourceArchives(
|
||||
@@ -780,7 +790,7 @@ class Builder:
|
||||
metadata.package.distribution = ctx.config.values.general.distribution
|
||||
metadata.package.distributionRelease = ctx.config.values.general.distribution_release
|
||||
metadata.package.architecture = ctx.config.values.general.architecture
|
||||
metadata.package.packageFormat = ctx.get_option('package_format')
|
||||
metadata.package.packageFormat = self.target_package_format
|
||||
|
||||
size = 0
|
||||
for fileinfo in self.files.list:
|
||||
@@ -1105,7 +1115,7 @@ class Builder:
|
||||
# performance of lzma.
|
||||
files.list.sort(key=lambda x: x.path)
|
||||
|
||||
if ctx.get_option('package_format') == "1.0":
|
||||
if self.target_package_format == "1.0":
|
||||
for finfo in files.list:
|
||||
orgname = arcname = util.join_path("install", finfo.path)
|
||||
if package.debug_package:
|
||||
|
||||
Reference in New Issue
Block a user