mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 12:12:47 +00:00
Merge pull request #333 from evgeni/get_project_name
make get_project_name more resilient
This commit is contained in:
commit
3bb01ebb56
2 changed files with 26 additions and 6 deletions
|
@ -810,11 +810,14 @@ def get_project_name(tag=None, scl=None):
|
|||
current working directory. Error out if neither is present.
|
||||
"""
|
||||
if tag is not None:
|
||||
p = re.compile('(.*?)-(\d.*)')
|
||||
m = p.match(tag)
|
||||
if not m:
|
||||
error_out("Unable to determine project name in tag: %s" % tag)
|
||||
return m.group(1)
|
||||
try:
|
||||
(package, _version, _release) = tag.rsplit('-', 2)
|
||||
except ValueError:
|
||||
try:
|
||||
(package, _version) = tag.rsplit('-', 1)
|
||||
except ValueError:
|
||||
error_out("Unable to determine project name in tag: %s" % tag)
|
||||
return package
|
||||
else:
|
||||
file_path = find_spec_like_file()
|
||||
if not os.path.exists(file_path):
|
||||
|
|
|
@ -17,7 +17,7 @@ from tito.common import (replace_version, find_spec_like_file, increase_version,
|
|||
search_for, compare_version, run_command_print, find_wrote_in_rpmbuild_output,
|
||||
render_cheetah, increase_zstream, reset_release, find_file_with_extension,
|
||||
normalize_class_name, extract_sha1, BugzillaExtractor, DEFAULT_BUILD_DIR, munge_specfile,
|
||||
munge_setup_macro,
|
||||
munge_setup_macro, get_project_name,
|
||||
_out)
|
||||
|
||||
from tito.compat import StringIO
|
||||
|
@ -222,6 +222,23 @@ class CommonTests(unittest.TestCase):
|
|||
# RHEL 6 doesn't have self.assertRegexpMatches unfortunately
|
||||
self.assertTrue(re.match('.+Hello world.+\n', stream.getvalue()))
|
||||
|
||||
def test_get_project_name(self):
|
||||
TAGS = [
|
||||
('package-1.0-1', 'package'),
|
||||
('package-1.0', 'package'),
|
||||
('long-package-name-that-should-not-be-an-issue-0.1-1', 'long-package-name-that-should-not-be-an-issue'),
|
||||
('package-with-weird-version-0.1-0.1.beta1', 'package-with-weird-version'),
|
||||
('grub2-efi-ia32-1.0-1', 'grub2-efi-ia32'),
|
||||
('iwl5150-firmware-1.0-1', 'iwl5150-firmware'),
|
||||
('389-ds-base-1.0-1', '389-ds-base'),
|
||||
('avr-gcc-c++-1.0-1', 'avr-gcc-c++'),
|
||||
('java-1.8.0-openjdk-1.8.0.232.b09-0', 'java-1.8.0-openjdk'),
|
||||
('jsr-305-0-0.25.20130910svn', 'jsr-305')
|
||||
]
|
||||
|
||||
for (tag, package) in TAGS:
|
||||
self.assertEquals(package, get_project_name(tag, None))
|
||||
|
||||
|
||||
class CheetahRenderTest(unittest.TestCase):
|
||||
@patch("os.unlink")
|
||||
|
|
Loading…
Add table
Reference in a new issue