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