diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-12-26 20:15:17 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-12-26 20:15:17 +0100 |
commit | d90e6be44fd6678830a0766b7e545cbb9c13ed1e (patch) | |
tree | ad2a4f8c6c4131c589e1795f7b2af744931d08a4 | |
parent | bad1f2370ba311bbe5981b204d4fa244b1d9a514 (diff) |
import-orig: determine download automatically
-rw-r--r-- | docs/common.ent | 1 | ||||
-rw-r--r-- | docs/manpages/gbp-import-orig.sgml | 71 | ||||
-rw-r--r-- | gbp/scripts/import_orig.py | 36 | ||||
-rw-r--r-- | tests/component/__init__.py | 4 | ||||
-rw-r--r-- | tests/component/deb/__init__.py | 1 | ||||
-rw-r--r-- | tests/component/deb/test_import_orig.py | 21 |
6 files changed, 92 insertions, 42 deletions
diff --git a/docs/common.ent b/docs/common.ent index 0d118074..45cbce08 100644 --- a/docs/common.ent +++ b/docs/common.ent @@ -37,6 +37,7 @@ <!ENTITY rpmbuild "<command>rpmbuild</command>"> <!ENTITY gbp-builder-mock "<command>gbp-builder-mock</command>"> <!ENTITY wget "<command>wget</command>"> + <!ENTITY uscan "<command>uscan</command>"> <!ENTITY debian "<productname>Debian</productname>"> <!ENTITY git "<productname>Git</productname>"> diff --git a/docs/manpages/gbp-import-orig.sgml b/docs/manpages/gbp-import-orig.sgml index 1e86a94d..b8cd51c9 100644 --- a/docs/manpages/gbp-import-orig.sgml +++ b/docs/manpages/gbp-import-orig.sgml @@ -38,9 +38,9 @@ <arg><option>--postimport=cmd</option></arg> <arg><option>--[no-]interactive</option></arg> <arg><option>--[no-]rollback</option></arg> - <arg><option>--download</option></arg> <group choice="plain"> - <arg choice="plain"><replaceable>upstream-source</replaceable></arg> + <arg choice="plain"><replaceable>filename</replaceable></arg> + <arg choice="plain"><replaceable>url</replaceable></arg> <arg><option>--uscan</option></arg> </group> </cmdsynopsis> @@ -48,15 +48,41 @@ <refsect1> <title>DESCRIPTION</title> <para> - &gbp-import-orig; imports <replaceable>upstream-source</replaceable> into - the &git; repository. <replaceable>upstream-source</replaceable> can either - be a gzip, bzip2, lzma or xz compressed tar archive, a zip archive, or an - already unpacked source tree. If it is already of the form - <replaceable>package-name_version.orig.tar.gz</replaceable>, the version - information is read from the tarball's filename, otherwise it can be given - on the command line via <option>--upstream-version</option>. If the source - package name or version can't be determined, &gbp-import-orig; will prompt - for it unless <option>--no-interactive</option> is given. + &gbp-import-orig; imports upstream sources into a &git; + repository. It can import from three sources: + </para> + <orderedlist> + <listitem> + <para> + <replaceable>filename</replaceable>: A file in the local + file system. Gzip, bzip2, lzma and xz compressed tar + archives, zip archives and already unpacked source trees are + supported. + </para> + </listitem> + <listitem> + <para> + <replaceable>url</replaceable>: The tarball is downloaded + from a <replaceable>http</replaceable> + or <replaceable>https</replaceable> <replaceable>url</replaceable>. + This needs the python-request package installed. + </para> + </listitem> + <listitem> + <para> + <option>--uscan</option>: The latest upstream version is fetched + via &uscan; relying on <filename>debian/watch</filename>. + </para> + </listitem> + </orderedlist> + <para> + If the tarballs name is already of the form + <replaceable>package-name_version.orig.tar.gz</replaceable>, the + version information is determined from the tarball's filename, + otherwise it can be given on the command line + via <option>--upstream-version</option>. If the source package + name or version can't be determined, &gbp-import-orig; will + prompt for it unless <option>--no-interactive</option> is given. </para> <para> The sources are placed on the upstream branch (default: @@ -302,16 +328,7 @@ <term><option>--uscan</option></term> <listitem> <para> - Use uscan to fetch new upstream version. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>--uscan</option></term> - <listitem> - <para> - Download the tarball from the given HTTP URL. This needs - python-request installed. + Use &uscan; to fetch new upstream version. </para> </listitem> </varlistentry> @@ -343,7 +360,13 @@ &gbp-import-orig; --uscan </screen> <para> - After downloading an upstream tarball by hand, import it + Fetch tarball from an URL + </para> + <screen> + &gbp-import-orig; https://debian.example.com/sid/upstream-tarball-0.1.tar.gz + </screen> + <para> + Import a local tarball </para> <screen> &gbp-import-orig; ../upstream-tarball-0.1.tar.gz @@ -360,6 +383,10 @@ <xref linkend="man.gbp.import.dscs"/>, <xref linkend="man.gbp.dch"/>, <xref linkend="man.gbp.conf"/>, + <citerefentry> + <refentrytitle>uscan</refentrytitle> + <manvolnum>1</manvolnum> + </citerefentry>, &man.seealso.common; </para> </refsect1> diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 47c56d92..8f3cf27f 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -18,6 +18,7 @@ """Import a new upstream version into a Git repository""" import os +import re import sys import tempfile import gbp.command_wrappers as gbpc @@ -461,22 +462,13 @@ def build_parser(name): parser.add_option("--uscan", dest='uscan', action="store_true", default=False, help="use uscan(1) to download the new tarball.") parser.add_option("--download", dest='download', action="store_true", - default=False, help="Download from URL via http(s).") + default=False, help="Ignored. Accepted for compatibility.") return parser def parse_args(argv): """Parse the command line arguments @return: options and arguments - - # Silence error output - >>> _gbp_log_error_bak = gbp.log.error - >>> gbp.log.error = lambda x: None - >>> parse_args(['arg0', '--download', '--uscan']) - (None, None) - >>> parse_args(['arg0', '--download', 'first', 'second']) - (None, None) - >>> gbp.log.error = _gbp_log_error_bak """ parser = build_parser(argv[0]) @@ -489,17 +481,27 @@ def parse_args(argv): if options.no_dch: gbp.log.warn("'--no-dch' passed. This is now the default, please remove this option.") - if options.uscan and options.download: - gbp.log.error("Either uscan or --download can be used, not both.") - return None, None - - if options.download and len(args) != 1: - gbp.log.error("Need exactly one URL to download not %s" % args) - return None, None + if options.download: + gbp.log.warn("Passing --download explicitly is deprecated.") + options.download = is_download(args) return options, args +def is_download(args): + """ + >>> is_download(["http://foo.example.com"]) + True + >>> is_download([]) + False + >>> is_download(["foo-1.1.orig.tar.gz"]) + False + """ + if args and re.match("https?://", args[0]): + return True + return False + + def main(argv): ret = 0 tmpdir = '' diff --git a/tests/component/__init__.py b/tests/component/__init__.py index 58508030..013550e4 100644 --- a/tests/component/__init__.py +++ b/tests/component/__init__.py @@ -25,6 +25,7 @@ import os import shutil import tempfile import unittest +from unittest import skipUnless from nose import SkipTest from nose.tools import eq_, ok_ # pylint: disable=E0611 from .. testutils import GbpLogTester @@ -32,6 +33,9 @@ from .. testutils import GbpLogTester from gbp.git import GitRepository, GitRepositoryError +__all__ = ['ComponentTestGitRepository', 'ComponentTestBase', 'GbpLogTester', 'skipUnless'] + + class ComponentTestGitRepository(GitRepository): """Git repository class for component tests""" def submodule_status(self): diff --git a/tests/component/deb/__init__.py b/tests/component/deb/__init__.py index 030a4823..65486e89 100644 --- a/tests/component/deb/__init__.py +++ b/tests/component/deb/__init__.py @@ -23,6 +23,7 @@ from tests.component import ComponentTestGitRepository DEB_TEST_SUBMODULE = os.path.join('tests', 'component', 'deb', 'data') DEB_TEST_DATA_DIR = os.path.abspath(DEB_TEST_SUBMODULE) +DEB_TEST_DOWNLOAD_URL = 'https://git.sigxcpu.org/cgit/gbp/deb-testdata/plain/' def setup(): diff --git a/tests/component/deb/test_import_orig.py b/tests/component/deb/test_import_orig.py index c4e1bad6..d4329fe9 100644 --- a/tests/component/deb/test_import_orig.py +++ b/tests/component/deb/test_import_orig.py @@ -21,8 +21,9 @@ import os from mock import patch, DEFAULT 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 gbp.scripts.import_dsc import main as import_dsc from gbp.scripts.import_orig import main as import_orig @@ -43,7 +44,6 @@ def raise_if_tag_match(match): class TestImportOrig(ComponentTestBase): """Test importing of new upstream versions""" - pkg = "hello-debhelper" def_branches = ['master', 'upstream', 'pristine-tar'] @@ -52,6 +52,11 @@ class TestImportOrig(ComponentTestBase): dir, '%s_%s.orig.tar.gz' % (self.pkg, version)) + def _download_url(self, version, dir='dsc-3.0'): + return os.path.join(DEB_TEST_DOWNLOAD_URL, + dir, + '%s_%s.orig.tar.gz' % (self.pkg, version)) + def _dsc(self, version, dir='dsc-3.0'): return os.path.join(DEB_TEST_DATA_DIR, dir, @@ -66,6 +71,16 @@ class TestImportOrig(ComponentTestBase): self._check_repo_state(repo, 'master', self.def_branches, tags=['upstream/2.6']) + @skipUnless(os.getenv("GBP_NETWORK_TESTS"), "network tests disabled") + def test_download(self): + """Test that importing via download works""" + repo = GitRepository.create(self.pkg) + os.chdir(self.pkg) + orig = self._download_url('2.6') + ok_(import_orig(['arg0', '--no-interactive', '--pristine-tar', orig]) == 0) + self._check_repo_state(repo, 'master', self.def_branches, + tags=['upstream/2.6']) + def test_update(self): """ Test that importing a new version works |