aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-12-26 20:15:18 +0100
committerGuido Günther <agx@sigxcpu.org>2016-12-26 20:15:18 +0100
commit58271d630fef2b235f4b8971f96bbd166eccca59 (patch)
treec9a5385bb06a16a4e34b1590aedb7838b1253514
parentd90e6be44fd6678830a0766b7e545cbb9c13ed1e (diff)
import-dsc: determine download automatically
No need to parse --download of URL is given or it's not a dsc file
-rw-r--r--docs/manpages/gbp-import-dsc.sgml55
-rw-r--r--gbp/scripts/import_dsc.py58
-rw-r--r--tests/component/deb/test_import_dsc.py19
3 files changed, 93 insertions, 39 deletions
diff --git a/docs/manpages/gbp-import-dsc.sgml b/docs/manpages/gbp-import-dsc.sgml
index 747957d6..2b3bcb63 100644
--- a/docs/manpages/gbp-import-dsc.sgml
+++ b/docs/manpages/gbp-import-dsc.sgml
@@ -25,7 +25,6 @@
<arg><option>--author-is-committer</option></arg>
<arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg>
<arg><option>--debian-tag=</option><replaceable>tag-format</replaceable></arg>
- <arg><option>--download</option></arg>
<arg><option>--filter=</option><replaceable>pattern</replaceable></arg>
<arg><option>--keyid=</option><replaceable>gpg-keyid</replaceable></arg>
<arg><option>--[no-]create-missing-branches</option></arg>
@@ -42,11 +41,9 @@
<cmdsynopsis>
&gbp-import-dsc;
<arg><option>options</option></arg>
- <arg choice="req"><option>--download</option></arg>
<arg><option>--[no-]allow-unauthenticated</option></arg>
<group choice="plain">
<arg><replaceable>URL</replaceable></arg>
- <arg><replaceable>source-package</replaceable></arg>
</group>
<arg choice="opt"><replaceable>target</replaceable></arg>
</cmdsynopsis>
@@ -54,17 +51,26 @@
<refsect1>
<title>DESCRIPTION</title>
<para>
- &gbp-import-dsc; imports a &debian; source package into a &git; repository,
- notes the package version in the commit logs, and commits the change. All
- information, including package name, version, &debian; diffs, and upstream
- source, is automatically detected from the source package.
+ &gbp-import-dsc; imports a &debian; source package into a &git; repository,
+ notes the package version in the commit logs, and commits the change. All
+ information, including package name, version, &debian; modifications and upstream
+ source, is automatically detected from the source package. After
+ import the repository can be used with the other &gbp; tools.
</para>
<para>
- If the command is run from within an existing repository, it will import
- into this; if not, a new repository named as the Debian source package is
+ If the command is run from within an existing &git; repository, it will import
+ into it; if not, a new repository named as the Debian source package is
created. You can override the location of the new repository by specifying
the optional <replaceable>target</replaceable> argument.
</para>
+ <para>
+ When given a <replaceable>URL</replaceable> &gbp-import-dsc;
+ will download the source package prior to importing it. &dget;
+ is used for all schemes except for the special
+ scheme <replaceable>apt://</replaceable> which uses &apt-get;
+ (and therefore needs <replaceable>deb-src</replaceable>
+ entries in your <filename>/etc/apt/sources.list</filename>).
+ </para>
</refsect1>
<refsect1>
<title>OPTIONS</title>
@@ -159,24 +165,13 @@
</listitem>
</varlistentry>
<varlistentry>
- <term><option>--download</option>
- </term>
- <listitem>
- <para>
- Download the source package instead of looking for it in the local
- file system. The argument can either be a
- <replaceable>source-package</replaceable> name or a
- <replaceable>URL</replaceable>. The former uses &apt-get; to download
- the source while the later uses &dget;.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
<term><option>--allow-unauthenticated</option>
</term>
<listitem>
<para>
- Whether to skip signature verification on downloads.
+ Whether to skip signature verification on
+ downloads. Passed on verbatim to &dget; and &apt-get;
+ respectively. Use with care.
</para>
</listitem>
</varlistentry>
@@ -257,14 +252,20 @@
Download and import a source package from a URL:
</para>
<screen>
- &gbp-import-dsc; --download http://http.debian.net/debian/pool/main/h/hello/hello_2.10-1.dsc
+ &gbp-import-dsc; http://http.debian.net/debian/pool/main/h/hello/hello_2.10-1.dsc
</screen>
<para>
Download and import a source package via <command>apt-get
source</command> from unstable:
</para>
<screen>
- &gbp-import-dsc; --download hello/sid
+ &gbp-import-dsc; apt://hello/sid
+ </screen>
+ <para>
+ Import a source package in the local file system:
+ </para>
+ <screen>
+ &gbp-import-dsc; ../hello_2.10-1.dsc
</screen>
</refsect1>
<refsect1>
@@ -280,6 +281,10 @@
<manvolnum>1</manvolnum>
</citerefentry>,
<citerefentry>
+ <refentrytitle>sources.list</refentrytitle>
+ <manvolnum>5</manvolnum>
+ </citerefentry>,
+ <citerefentry>
<refentrytitle>dget</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>,
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py
index e5e68279..a6ec09ba 100644
--- a/gbp/scripts/import_dsc.py
+++ b/gbp/scripts/import_dsc.py
@@ -236,8 +236,6 @@ def build_parser(name):
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
parser.add_config_file_option(option_name="color-scheme",
dest="color_scheme")
- parser.add_option("--download", action="store_true", dest="download", default=False,
- help="download source package")
branch_group.add_config_file_option(option_name="debian-branch",
dest="debian_branch")
branch_group.add_config_file_option(option_name="upstream-branch",
@@ -275,6 +273,8 @@ def build_parser(name):
choices=['DEBIAN', 'GIT'])
parser.add_config_file_option(option_name="repo-email", dest="repo_email",
choices=['DEBIAN', 'GIT'])
+ parser.add_option("--download", dest='download', action="store_true",
+ default=False, help="Ignored. Accepted for compatibility.")
return parser
@@ -285,29 +285,63 @@ def parse_args(argv):
(options, args) = parser.parse_args(argv[1:])
gbp.log.setup(options.color, options.verbose, options.color_scheme)
+
+ if options.download:
+ gbp.log.warn("Passing --download explicitly is deprecated.")
+
return options, args
+def is_download(pkg):
+ """
+ >>> is_download("http://foo.example.com/apackage.dsc")
+ (True, 'http://foo.example.com/apackage.dsc')
+ >>> is_download("apt://apackage/sid")
+ (True, 'apackage/sid')
+ >>> is_download("apt_1.0_amd64.dsc")
+ (False, 'apt_1.0_amd64.dsc')
+ >>> is_download("file:///foo/apackage.dsc")
+ (False, '/foo/apackage.dsc')
+ """
+ if pkg.startswith('file://'):
+ return (False, pkg[len('file://'):])
+ if pkg.startswith('apt://'):
+ return (True, pkg[len('apt://'):])
+ elif re.match("[a-z]{1,5}://", pkg):
+ return (True, pkg)
+ return (False, pkg)
+
+
+def parse_all(argv):
+ options, args = parse_args(argv)
+ if not options:
+ return None, None, None
+
+ if len(args) == 1:
+ pkg = args[0]
+ target = None
+ elif len(args) == 2:
+ pkg = args[0]
+ target = args[1]
+ else:
+ gbp.log.err("Need to give exactly one package to import. Try --help.")
+ return None, None, None
+
+ (options.download, pkg) = is_download(pkg) or options.download
+ return options, pkg, target
+
+
def main(argv):
dirs = dict(top=os.path.abspath(os.curdir))
needs_repo = False
ret = 0
skipped = False
- options, args = parse_args(argv)
+ options, pkg, target = parse_all(argv)
if not options:
return ExitCodes.parse_error
try:
- if len(args) == 1:
- pkg = args[0]
- target = None
- elif len(args) == 2:
- pkg = args[0]
- target = args[1]
- else:
- gbp.log.err("Need to give exactly one package to import. Try --help.")
- raise GbpError
try:
repo = DebianGitRepository('.')
is_empty = repo.is_empty()
diff --git a/tests/component/deb/test_import_dsc.py b/tests/component/deb/test_import_dsc.py
index 7496d0a6..947c2baf 100644
--- a/tests/component/deb/test_import_dsc.py
+++ b/tests/component/deb/test_import_dsc.py
@@ -19,8 +19,9 @@
import os
from tests.component import (ComponentTestBase,
- ComponentTestGitRepository)
-from tests.component.deb import DEB_TEST_DATA_DIR
+ ComponentTestGitRepository,
+ skipUnless)
+from tests.component.deb import DEB_TEST_DATA_DIR, DEB_TEST_DOWNLOAD_URL
from nose.tools import ok_, eq_
@@ -56,6 +57,20 @@ class TestImportDsc(ComponentTestBase):
self._check_repo_state(repo, 'master', ['master'])
assert len(repo.get_commits()) == 3
+ @skipUnless(os.getenv("GBP_NETWORK_TESTS"), "network tests disabled")
+ def test_download(self):
+ def _dsc(version):
+ return os.path.join(DEB_TEST_DOWNLOAD_URL,
+ 'dsc-native',
+ 'git-buildpackage_%s.dsc' % version)
+ dsc = _dsc('0.4.14')
+ assert import_dsc(['arg0',
+ '--allow-unauthenticated',
+ dsc]) == 0
+ repo = ComponentTestGitRepository('git-buildpackage')
+ self._check_repo_state(repo, 'master', ['master'])
+ assert len(repo.get_commits()) == 1
+
def test_create_branches(self):
"""Test if creating missing branches works"""
def _dsc(version):