aboutsummaryrefslogtreecommitdiff
path: root/gbp/scripts
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-07-04 20:03:26 +0200
committerGuido Günther <agx@sigxcpu.org>2016-07-04 21:02:54 +0200
commitf545010462b9a313fe3bf160bca9e44c3ea77b55 (patch)
tree31c7f3a7d469b113c60b71d0f4d15bc459ea7c4c /gbp/scripts
parentf2ad919cb98b3e1b1a537e2a43ece88961006b29 (diff)
Give more instructions when config is unparseable
and make return codes and messages consistent. This allows us to move some test code from the component tests to the unit tests which is always nice. Closes: #733640
Diffstat (limited to 'gbp/scripts')
-rwxr-xr-xgbp/scripts/buildpackage.py5
-rw-r--r--gbp/scripts/buildpackage_rpm.py6
-rwxr-xr-xgbp/scripts/clone.py7
-rw-r--r--gbp/scripts/common/__init__.py7
-rwxr-xr-xgbp/scripts/config.py6
-rw-r--r--gbp/scripts/create_remote_repo.py15
-rw-r--r--gbp/scripts/dch.py11
-rw-r--r--gbp/scripts/import_dsc.py7
-rw-r--r--gbp/scripts/import_orig.py6
-rwxr-xr-xgbp/scripts/import_srpm.py6
-rwxr-xr-xgbp/scripts/pq.py6
-rwxr-xr-xgbp/scripts/pq_rpm.py9
-rwxr-xr-xgbp/scripts/pull.py6
-rw-r--r--gbp/scripts/rpm_ch.py8
14 files changed, 62 insertions, 43 deletions
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index dab45e8..a792a04 100755
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -41,6 +41,7 @@ from gbp.scripts.common.buildpackage import (index_name, wc_name,
git_archive_submodules,
git_archive_single, dump_tree,
write_wc, drop_index)
+from gbp.scripts.common import ExitCodes
from gbp.pkg import compressor_opts, compressor_aliases, parse_archive_filename
#{ upstream tarball preparation
@@ -496,7 +497,7 @@ def md(a, b):
def build_parser(name, prefix=None):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name), prefix=prefix)
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -636,7 +637,7 @@ def main(argv):
options, gbp_args, dpkg_args = parse_args(argv, prefix)
if not options:
- return 1
+ return ExitCodes.parse_error
try:
repo = DebianGitRepository(os.path.curdir)
diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py
index 6f52a82..8c131f3 100644
--- a/gbp/scripts/buildpackage_rpm.py
+++ b/gbp/scripts/buildpackage_rpm.py
@@ -18,7 +18,6 @@
#
"""Build an RPM package out of a Git repository"""
-from six.moves import configparser
import os
import shutil
import sys
@@ -34,6 +33,7 @@ from gbp.pkg import compressor_opts
from gbp.rpm.git import GitRepositoryError, RpmGitRepository
from gbp.rpm.policy import RpmPkgPolicy
from gbp.tmpfile import init_tmpdir, del_tmpdir, tempfile
+from gbp.scripts.common import ExitCodes
from gbp.scripts.common.buildpackage import (index_name, wc_name,
git_archive_submodules,
git_archive_single, dump_tree,
@@ -317,7 +317,7 @@ def build_parser(name, prefix=None, git_treeish=None):
try:
parser = GbpOptionParserRpm(command=os.path.basename(name),
prefix=prefix)
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -479,7 +479,7 @@ def main(argv):
options, gbp_args, builder_args = parse_args(argv, prefix)
if not options:
- return 1
+ return ExitCodes.parse_error
try:
repo = RpmGitRepository(os.path.curdir)
diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index af32211..b2717fa 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -26,6 +26,7 @@ from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.deb.git import DebianGitRepository
from gbp.git import (GitRepository, GitRepositoryError)
from gbp.errors import GbpError
+from gbp.scripts.common import ExitCodes
import gbp.log
@@ -33,7 +34,7 @@ def build_parser(name):
try:
parser = GbpOptionParser(command=os.path.basename(name), prefix='',
usage='%prog [options] repository - clone a remote repository')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -58,7 +59,7 @@ def build_parser(name):
return parser
-def parse_args (argv):
+def parse_args(argv):
parser = build_parser(argv[0])
if not parser:
return None, None
@@ -73,7 +74,7 @@ def main(argv):
(options, args) = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
if len(args) < 2:
gbp.log.err("Need a repository to clone.")
diff --git a/gbp/scripts/common/__init__.py b/gbp/scripts/common/__init__.py
index a24bb62..59b3ca8 100644
--- a/gbp/scripts/common/__init__.py
+++ b/gbp/scripts/common/__init__.py
@@ -15,3 +15,10 @@
# along with this program; if not, please see
# <http://www.gnu.org/licenses/>
"""Parts shared between the deb and rpm commands"""
+
+
+class ExitCodes(object):
+ ok = 0,
+ failed = 1 # Allow other errors
+ no_value = 2 # Value does not exist (gbp config only)
+ parse_error = 3 # Failed to parse configuration file
diff --git a/gbp/scripts/config.py b/gbp/scripts/config.py
index 04dd9c4..006c7aa 100755
--- a/gbp/scripts/config.py
+++ b/gbp/scripts/config.py
@@ -21,7 +21,9 @@ from six.moves import configparser
import sys
import os, os.path
from gbp.config import GbpOptionParser
+from gbp.errors import GbpError
from gbp.scripts.supercommand import import_command
+from gbp.scripts.common import ExitCodes
import gbp.log
@@ -29,7 +31,7 @@ def build_parser(name):
try:
parser = GbpOptionParser(command=os.path.basename(name), prefix='',
usage='%prog [options] command[.optionname] - display configuration settings')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -119,7 +121,7 @@ def main(argv):
(options, args) = parse_args(argv)
if options is None:
- return retval
+ return ExitCodes.parse_error
gbp.log.setup(options.color, options.verbose, options.color_scheme)
diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py
index db60959..ffc32ea 100644
--- a/gbp/scripts/create_remote_repo.py
+++ b/gbp/scripts/create_remote_repo.py
@@ -20,7 +20,6 @@
from __future__ import print_function
-from six.moves import configparser
import sys
import os, os.path
from six.moves import urllib
@@ -36,8 +35,11 @@ from gbp.config import (GbpOptionParserDebian, GbpOptionGroup)
from gbp.errors import GbpError
from gbp.git import GitRepositoryError
from gbp.deb.git import DebianGitRepository
+from gbp.scripts.common import ExitCodes
+
import gbp.log
+
def print_config(remote, branches):
"""
Print out the git config to push to the newly created repo.
@@ -237,7 +239,7 @@ def build_parser(name, sections=[]):
usage='%prog [options] - '
'create a remote repository',
sections=sections)
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -308,11 +310,10 @@ def main(argv):
changelog = 'debian/changelog'
cmd = []
- try:
- options, args = parse_args(argv)
- except Exception as e:
- print("%s" % e, file=sys.stderr)
- return 1
+ options, args = parse_args(argv)
+
+ if not options:
+ return ExitCodes.parse_error
gbp.log.setup(options.color, options.verbose, options.color_scheme)
try:
diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index f0b4928..5bc2b62 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -19,7 +19,6 @@
from __future__ import print_function
-from six.moves import configparser
import os.path
import re
import sys
@@ -33,6 +32,7 @@ from gbp.deb import compare_versions
from gbp.deb.source import DebianSource, DebianSourceError
from gbp.deb.git import GitRepositoryError, DebianGitRepository
from gbp.deb.changelog import ChangeLog, NoChangeLogError
+from gbp.scripts.common import ExitCodes
user_customizations = {}
snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*")
@@ -300,7 +300,7 @@ def build_parser(name):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name),
usage='%prog [options] paths')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -389,7 +389,7 @@ def build_parser(name):
def parse_args(argv):
parser = build_parser(argv[0])
if not parser:
- return None, None
+ return [None] * 4
(options, args) = parser.parse_args(argv[1:])
gbp.log.setup(options.color, options.verbose, options.color_scheme)
@@ -397,6 +397,7 @@ def parse_args(argv):
editor_cmd = process_editor_option(options)
return options, args, dch_options, editor_cmd
+
def main(argv):
ret = 0
changelog = 'debian/changelog'
@@ -405,9 +406,11 @@ def main(argv):
version_change = {}
branch = None
-
options, args, dch_options, editor_cmd = parse_args(argv)
+ if not options:
+ return ExitCodes.parse_error
+
try:
try:
repo = DebianGitRepository('.')
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py
index f7c8a97..78a30ee 100644
--- a/gbp/scripts/import_dsc.py
+++ b/gbp/scripts/import_dsc.py
@@ -16,7 +16,6 @@
# <http://www.gnu.org/licenses/>
"""Import a Debian source package into a Git repository"""
-from six.moves import configparser
import sys
import re
import os
@@ -35,8 +34,10 @@ from gbp.git.modifier import GitModifier
from gbp.config import (GbpOptionParserDebian, GbpOptionGroup,
no_upstream_branch_msg)
from gbp.errors import GbpError
+from gbp.scripts.common import ExitCodes
import gbp.log
+
class SkipImport(Exception):
pass
@@ -210,7 +211,7 @@ def build_parser(name):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
usage='%prog [options] /path/to/package.dsc')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -285,7 +286,7 @@ def main(argv):
options, args = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
try:
if len(args) != 1:
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index 82c2f42..d8a4f3a 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -17,7 +17,6 @@
#
"""Import a new upstream version into a Git repository"""
-from six.moves import configparser
import os
import sys
import tempfile
@@ -32,6 +31,7 @@ from gbp.errors import GbpError
from gbp.pkg import parse_archive_filename
from gbp.format import format_str
import gbp.log
+from gbp.scripts.common import ExitCodes
from gbp.scripts.common.import_orig import (orig_needs_repack, cleanup_tmp_tree,
ask_package_name, ask_package_version,
repack_source, is_link_target, download_orig)
@@ -368,7 +368,7 @@ def build_parser(name):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -479,7 +479,7 @@ def main(argv):
(options, args) = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
try:
try:
diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py
index 3e42f47..5771d30 100755
--- a/gbp/scripts/import_srpm.py
+++ b/gbp/scripts/import_srpm.py
@@ -17,7 +17,6 @@
# <http://www.gnu.org/licenses/>
"""Import an RPM source package into a Git repository"""
-from six.moves import configparser
import sys
import re
import os
@@ -37,6 +36,7 @@ from gbp.git.modifier import GitModifier
from gbp.config import (GbpOptionParserRpm, GbpOptionGroup,
no_upstream_branch_msg)
from gbp.errors import GbpError
+from gbp.scripts.common import ExitCodes
import gbp.log
from gbp.pkg import parse_archive_filename
@@ -123,7 +123,7 @@ def build_parser(name):
prefix='',
usage='%prog [options] /path/to/package'
'.src.rpm')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -205,6 +205,8 @@ def main(argv):
skipped = False
options, args = parse_args(argv)
+ if not options:
+ return ExitCodes.parse_error
if len(args) != 1:
gbp.log.err("Need to give exactly one package to import. Try --help.")
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 1d20ef9..9d93341 100755
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -17,7 +17,6 @@
#
"""Manage Debian patches on a patch queue branch"""
-from six.moves import configparser
import errno
import os
import shutil
@@ -35,6 +34,7 @@ from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base,
switch_to_pq_branch, apply_single_patch,
apply_and_commit_patch, switch_pq,
drop_pq, get_maintainer_from_control)
+from gbp.scripts.common import ExitCodes
from gbp.dch import extract_bts_cmds
PATCH_DIR = "debian/patches/"
@@ -334,7 +334,7 @@ def build_parser(name):
" drop drop (delete) the patch queue associated to the current branch.\n"
" apply apply a patch\n"
" switch switch to patch-queue branch and vice versa")
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -369,7 +369,7 @@ def main(argv):
(options, args) = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
gbp.log.setup(options.color, options.verbose, options.color_scheme)
diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py
index b38427e..6e7b4ef 100755
--- a/gbp/scripts/pq_rpm.py
+++ b/gbp/scripts/pq_rpm.py
@@ -18,7 +18,6 @@
#
"""manage patches in a patch queue"""
-from six.moves import configparser
import bz2
import errno
import gzip
@@ -37,10 +36,12 @@ from gbp.patch_series import PatchSeries, Patch
from gbp.pkg import parse_archive_filename
from gbp.rpm import (SpecFile, NoSpecError, guess_spec, guess_spec_repo,
spec_from_repo)
+from gbp.scripts.common import ExitCodes
from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base,
parse_gbp_commands, format_patch, format_diff,
switch_to_pq_branch, apply_single_patch, apply_and_commit_patch,
drop_pq, switch_pq)
+
from gbp.scripts.common.buildpackage import dump_tree
@@ -360,8 +361,8 @@ drop Drop (delete) the patch queue /devel branch associated to
apply Apply a patch
switch Switch to patch-queue branch and vice versa.""")
- except configparser.ParsingError as err:
- gbp.log.err('Invalid config file: %s' % err)
+ except GbpError as err:
+ gbp.log.err(err)
return None
parser.add_boolean_config_file_option(option_name="patch-numbers",
@@ -398,7 +399,7 @@ def main(argv):
(options, args) = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
gbp.log.setup(options.color, options.verbose, options.color_scheme)
diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py
index f019608..23ea4ce 100755
--- a/gbp/scripts/pull.py
+++ b/gbp/scripts/pull.py
@@ -19,7 +19,6 @@
#
"""Pull remote changes and fast forward debian, upstream and pristine-tar branch"""
-from six.moves import configparser
import sys
import os
import os.path
@@ -28,6 +27,7 @@ from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.errors import GbpError
from gbp.git import GitRepositoryError
from gbp.deb.git import DebianGitRepository
+from gbp.scripts.common import ExitCodes
import gbp.log
@@ -75,7 +75,7 @@ def build_parser(name):
try:
parser = GbpOptionParser(command=os.path.basename(name), prefix='',
usage='%prog [options] - safely update a repository from remote')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -112,7 +112,7 @@ def main(argv):
(options, args) = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
gbp.log.setup(options.color, options.verbose, options.color_scheme)
diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py
index 3c5ea8d..d1ca2b5 100644
--- a/gbp/scripts/rpm_ch.py
+++ b/gbp/scripts/rpm_ch.py
@@ -18,7 +18,6 @@
#
"""Generate RPM changelog entries from git commit messages"""
-import ConfigParser
from datetime import datetime
import os.path
import pwd
@@ -35,6 +34,7 @@ from gbp.rpm import (guess_spec, NoSpecError, SpecFile, split_version_str,
from gbp.rpm.changelog import Changelog, ChangelogParser, ChangelogError
from gbp.rpm.git import GitRepositoryError, RpmGitRepository
from gbp.rpm.policy import RpmPkgPolicy
+from gbp.scripts.common import ExitCodes
from gbp.tmpfile import init_tmpdir, del_tmpdir
@@ -309,8 +309,8 @@ def build_parser(name):
try:
parser = GbpOptionParserRpm(command=os.path.basename(name),
prefix='', usage='%prog [options] paths')
- except ConfigParser.ParsingError as err:
- gbp.log.error('invalid config file: %s' % err)
+ except GbpError as err:
+ gbp.log.error(err)
return None
range_grp = GbpOptionGroup(parser, "commit range options",
@@ -398,7 +398,7 @@ def main(argv):
"""Script main function"""
options, args = parse_args(argv)
if not options:
- return 1
+ return ExitCodes.parse_error
try:
init_tmpdir(options.tmp_dir, prefix='rpm-ch_')