Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
OBS:Server:Unstable
obs-service-set_version
_service:obs_scm:obs-service-set_version-0.6.4....
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:obs-service-set_version-0.6.4.obscpio of Package obs-service-set_version
07070100000000000041ED00000000000000000000000366438AD500000000000000000000000000000000000000000000002600000000obs-service-set_version-0.6.4/.github07070100000001000041ED00000000000000000000000266438AD500000000000000000000000000000000000000000000003000000000obs-service-set_version-0.6.4/.github/workflows07070100000002000081A400000000000000000000000166438AD500000404000000000000000000000000000000000000003900000000obs-service-set_version-0.6.4/.github/workflows/main.yml# This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: Testing on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: ["3.10", "3.11", "3.12"] env: EMAIL: "nobody@example.com" steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install required deb packages run: sudo apt-get install zypper devscripts - name: Install python dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Test with pytest run: | make test PYTHON=python 07070100000003000081A400000000000000000000000166438AD500000033000000000000000000000000000000000000002900000000obs-service-set_version-0.6.4/.gitignore*.pyc *.pyo *.sw? set_versionc tests/test_newline/ 07070100000004000081A400000000000000000000000166438AD500004644000000000000000000000000000000000000002600000000obs-service-set_version-0.6.4/COPYING GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. 07070100000005000081A400000000000000000000000166438AD5000001E8000000000000000000000000000000000000002700000000obs-service-set_version-0.6.4/Makefileprefix = /usr PYTHON ?= python3 servicedir = ${prefix}/lib/obs/service all: install: install -d $(DESTDIR)$(servicedir) install -m 0755 set_version $(DESTDIR)$(servicedir) install -m 0644 set_version.service $(DESTDIR)$(servicedir) test: flake8 set_version tests/ echo "Using python ${PYTHON}" ${PYTHON} --version ${PYTHON} -m unittest discover tests/ clean: find -name "*.pyc" -exec rm {} \; find -name '*.pyo' -exec rm {} \; rm -rf set_versionc .PHONY: all install test 07070100000006000081A400000000000000000000000166438AD50000070D000000000000000000000000000000000000002800000000obs-service-set_version-0.6.4/README.md# set_version (OBS source service) [![Build Status](https://travis-ci.org/openSUSE/obs-service-set_version.svg?branch=master)](https://travis-ci.org/openSUSE/obs-service-set_version) This is an [Open Build Service](http://openbuildservice.org/) source service. It updates an RPM spec or Debian changelog according to the existing files. This is the git repository for [openSUSE:Tools/obs-service-set_version](https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-set_version). The authoritative source is https://github.com/openSUSE/obs-service-set_version The service can be used in combination with other services like [download_files](https://github.com/openSUSE/obs-service-download_files), [tar_scm](https://github.com/openSUSE/obs-service-tar_scm), [recompress](https://github.com/openSUSE/obs-service-recompress) or [extract_file](https://github.com/openSUSE/obs-service-extract_file) e.g. within the [GIT integration](https://en.opensuse.org/openSUSE:Build_Service_Concept_SourceService#Example_2:_GIT_integration) workflow. ## Dependencies Install the following deps: zypper in python-packaging ## Test suite To run the full testsuite, some dependencies are needed: zypper in devscripts dpkg python-flake8 If the dependencies are not installed, some tests are skipped. `zypper` itself is also needed for the tests with python packages and PEP440 compatible versions. To run the full testsuite, execute: python -m unittest discover tests/ If ```zypper``` and/or ```dpkg``` are installed, theses tests take some time, but you can specify a filename pattern, which test files should be run. python -m unittest discover -p test_b*.py tests/ Don't forget to run also flake8 set_version tests/ or simply use make test to run all linters and tests 07070100000007000041ED00000000000000000000000366438AD500000000000000000000000000000000000000000000002500000000obs-service-set_version-0.6.4/debian07070100000008000081A400000000000000000000000166438AD500000210000000000000000000000000000000000000002F00000000obs-service-set_version-0.6.4/debian/changelogobs-service-set-version (0.4.2) unstable; urgency=low * the extension needs to be \. * test with defined() at ./set_version line 118. * Fix processing of --file parameter * Add support for setting the version in debian.changelog * Sort local file list based on modification time (newest first) -- Jan Blunck <jblunck@infradead.org> Wed, 10 Sep 2014 18:20:20 +0200 obs-service-set-version (0.4.1) unstable; urgency=low * Initial release -- Daniel Gollub <dgollub@brocade.com> Thu, 03 Jul 2014 09:04:52 +0200 07070100000009000081A400000000000000000000000166438AD500000002000000000000000000000000000000000000002C00000000obs-service-set_version-0.6.4/debian/compat8 0707010000000A000081A400000000000000000000000166438AD500000274000000000000000000000000000000000000002D00000000obs-service-set_version-0.6.4/debian/controlSource: obs-service-set-version Section: devel Priority: extra Maintainer: Daniel Gollub <dgollub@brocade.com> Build-Depends: debhelper (>= 8.0.0), python3, flake8 | python3-flake8, python3-ddt, python3-packaging Standards-Version: 3.9.3 Homepage: https://github.com/openSUSE/obs-service-set_version Package: obs-service-set-version Architecture: all Depends: ${misc:Depends}, sed, python3 Description: An OBS source service: Update spec file version This is a source service for openSUSE Build Service. Very simply script to update the version in .spec or .dsc files according to a given version or to the existing files. 0707010000000B000081A400000000000000000000000166438AD50000045F000000000000000000000000000000000000002F00000000obs-service-set_version-0.6.4/debian/copyrightFormat: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: obs-service-set_version Source: https://github.com/openSUSE/obs-service-set_version Files: * Copyright: 2010 Adrian Schröter <adrian@suse.de> License: GPL-2.0+ Files: debian/* Copyright: 2014 Daniel Gollub <dgollub@brocade.com> License: GPL-2.0+ License: GPL-2.0+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/> . On Debian systems, the complete text of the GNU General Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 0707010000000C000081ED00000000000000000000000166438AD5000000CF000000000000000000000000000000000000002B00000000obs-service-set_version-0.6.4/debian/rules#!/usr/bin/make -f # -*- makefile -*- # export DH_VERBOSE=1 export PYTHON=python3 %: dh $@ override_dh_auto_build: dh_auto_build $@ sed -i -e '1 s,^#!/usr/bin/python$$,#!/usr/bin/python3,' set_version 0707010000000D000041ED00000000000000000000000266438AD500000000000000000000000000000000000000000000002C00000000obs-service-set_version-0.6.4/debian/source0707010000000E000081A400000000000000000000000166438AD50000000D000000000000000000000000000000000000003300000000obs-service-set_version-0.6.4/debian/source/format3.0 (native) 0707010000000F000041ED00000000000000000000000266438AD500000000000000000000000000000000000000000000002300000000obs-service-set_version-0.6.4/dist07070100000010000081A400000000000000000000000166438AD50000096B000000000000000000000000000000000000004000000000obs-service-set_version-0.6.4/dist/obs-service-set_version.spec# # spec file for package obs-service-set_version # # Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via https://bugs.opensuse.org/ # %if 0%{?suse_version} >= 1500 || 0%{?fedora_version} >= 29 || 0%{?centos_version} >= 800 %bcond_without python3 %else %bcond_with python3 %endif %if %{with python3} %define use_python python3 %else %define use_python python %endif %define service set_version Name: obs-service-%{service} Version: 0.5.12 Release: 0 Summary: An OBS source service: Update spec file version License: GPL-2.0-or-later Group: Development/Tools/Building URL: https://github.com/openSUSE/obs-service-%{service} Source: %{name}-%{version}.tar.gz BuildRequires: python3-ddt BuildRequires: python3-flake8 BuildRequires: python3-packaging %if 0%{?suse_version} %if 0%{?suse_version} > 1315 Recommends: python3-packaging Requires: python3-base %else Recommends: python-packaging %endif %endif Requires: sed BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch %description This is a source service for openSUSE Build Service. Very simply script to update the version in .spec or .dsc files according to a given version or to the existing files. %prep %setup -q %build %if 0%{?suse_version} > 1315 sed -i -e "1 s,#!/usr/bin/python$,#!/usr/bin/python3," set_version %endif %check make test PYTHON=python3 %install mkdir -p %{buildroot}%{_prefix}/lib/obs/service install -m 0755 set_version %{buildroot}%{_prefix}/lib/obs/service install -m 0644 set_version.service %{buildroot}%{_prefix}/lib/obs/service perl -p -i -e 's{#!.*python.*}{#!%{_bindir}/%{use_python}}' %{buildroot}%{_prefix}/lib/obs/service/set_version %files %defattr(-,root,root) %dir %{_prefix}/lib/obs %{_prefix}/lib/obs/service %changelog 07070100000011000081A400000000000000000000000166438AD500000004000000000000000000000000000000000000002F00000000obs-service-set_version-0.6.4/requirements.txtddt 07070100000012000081ED00000000000000000000000166438AD500004DFC000000000000000000000000000000000000002A00000000obs-service-set_version-0.6.4/set_version#!/usr/bin/python3 # -*- coding: utf-8 -*- # A simple script to update version number in spec, dsc or arch linux files # # (C) 2010 by Adrian Schröter <adrian@suse.de> # (C) 2015 by Thomas Bechtold <tbechtold@suse.com> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # See http://www.gnu.org/licenses/gpl-2.0.html for full license text. from __future__ import print_function import argparse from contextlib import suppress import errno import glob import os import re import shutil import sys import tarfile import zipfile import codecs import logging try: from packaging.version import InvalidVersion, Version, parse except ImportError: HAS_PACKAGING = False import warnings warnings.warn("install 'packaging' to improve python package versions", RuntimeWarning) else: HAS_PACKAGING = True if HAS_PACKAGING: with suppress(ImportError): from packaging.version import LegacyVersion if os.environ.get('DEBUG_SET_VERSION') == "1": logging.getLogger().setLevel(logging.DEBUG) outdir = None suffixes = ('.obscpio', '.tar', '.tar.gz', '.tgz', '.tar.bz2', '.tbz2', '.tar.xz', '.tar.zst', '.zip') suffixes_re = "|".join(map(lambda x: re.escape(x), suffixes)) def _get_local_files(): """ sorted local file list by modification time (newest first)""" files = glob.glob('*') files.sort(key=lambda x: os.stat(os.path.join(os.getcwd(), x)).st_mtime, reverse=True) return files class VersionDetector(object): def __init__(self, regex=None, file_list=(), basename='', versionfile=None): self.regex = regex self.file_list = file_list self.basename = basename self.versionfile = versionfile def autodetect(self): logging.debug("Starting version autodetect") logging.debug("-- Starting version detection via specified file") version = self._get_version_via_versionfile() if not version: logging.debug("--- Could not find version via specified file") logging.debug("-- Starting version detection via obsinfo") version = self._get_version_via_obsinfo() if not version: logging.debug("--- Could not find version via obsinfo") logging.debug("-- Starting version detection via archive dirname") version = self._get_version_via_archive_dirname() if not version: logging.debug("--- Could not find version via archive dirname") logging.debug("-- Starting version detection via filename") version = self._get_version_via_filename() if not version: logging.debug("--- Could not find version via filename") logging.debug("-- Starting version detection via debian changelog") version = self.get_version_via_debian_changelog("debian.changelog") if not version: logging.debug("--- Could not find version via debian changelog") return version def _get_version_via_filename(self): """ detect version based on file names""" logging.debug("detecting version via files") for f in self.file_list: logging.debug(" - checking file %s", f) if self.regex: logging.debug(" - using regex: %r", self.regex) regex = self.regex else: regex = r"^%s.*[-_]([\d].*)(?:%s)$" % ( re.escape(self.basename), suffixes_re) m = re.match(regex, f) if m: return m.group(1) # Nothing found return None def _get_version_via_versionfile(self): """ detect version based on custom file contents""" logging.debug("detecting version via custom file") if not self.versionfile: logging.debug("Custom file name not set") return None logging.debug(" - checking file '%s'", self.versionfile) if self.regex: regex = self.regex else: regex = r"^[Vv]ersion:\s+([\d].*)(?:)\s?$" logging.debug(" - using regex: %r", regex) if not os.path.exists(self.versionfile): logging.debug(" - file: %s does not exist", self.versionfile) raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), self.versionfile) with codecs.open(self.versionfile, 'r', 'utf8') as fp: for line in fp: m = re.match(regex, line) if m: return m.group(1) return None def __get_version(self, str_list): if self.regex: regex = self.regex else: regex = r"%s.*[-_]([\d][^\/]*).*" % self.basename for s in str_list: m = re.match(regex, s) if m: return m.group(1) # Nothing found return None def _get_version_via_archive_dirname(self): """ detect version based tar'd directory name""" for f in filter(lambda x: x.endswith(suffixes), self.file_list): logging.debug("Checking path: '%s'.", f) if not os.path.isfile(f): logging.debug("Skipping path: '%s' is not a regular file.", f) continue # handle tarfiles if tarfile.is_tarfile(f): with tarfile.open(f) as tf: v = self.__get_version(tf.getnames()) if v: return v # handle zipfiles if zipfile.is_zipfile(f): try: with zipfile.ZipFile(f, 'r') as zf: v = self.__get_version(zf.namelist()) if v: return v # is_zipfile has often false positives and module is # crashing on processing except OSError: pass except IOError: pass # Nothing found return None def _get_version_via_obsinfo(self): for fname in filter(lambda x: x.startswith(self.basename) and x.endswith(".obsinfo"), self.file_list): if os.path.exists(fname): with codecs.open(fname, 'r', 'utf8') as fp: for line in fp: if line.startswith("version: "): string = line[9:] string = string.rstrip() return string # Nothing found return None @staticmethod def get_version_via_debian_changelog(filename): # from http://anonscm.debian.org/cgit/pkg-python-debian/\ # python-debian.git/tree/lib/debian/changelog.py topline = re.compile(r'^(\w%(name_chars)s*) \(([^\(\) \t]+)\)' r'((\s+%(name_chars)s+)+)\;' % {'name_chars': '[-+0-9a-z.]'}, re.IGNORECASE) if os.path.exists(filename): with codecs.open(filename, 'r', 'utf8') as f: firstline = f.readline() topmatch = topline.match(firstline) if topmatch: return topmatch.group(2) # Nothing found return None @staticmethod def _get_version_via_debian_dsc(filename): version = re.compile(r'^Version:([ \t\f\v]*)[^%\n\r]*', re.IGNORECASE) if os.path.exists(filename): with codecs.open(filename, 'r', 'utf8') as f: for line in f: versionmatch = version.match(line) if versionmatch: return versionmatch.group(0) # Nothing found return None class RevisionDetector(object): def __init__(self): pass def autodetect(self): return self._get_revision_from_osc_files() @staticmethod def _get_revision_from_osc_files(): from xml.etree import ElementTree _filesname = os.path.join('.osc', '_files') _filesXML = ElementTree.parse(_filesname) return _filesXML.getroot().attrib['rev'] class PackageTypeDetector(object): # pylint: disable=too-few-public-methods @staticmethod def _get_package_type(files): pt_found = False for f in filter(lambda x: x.endswith(suffixes), files): pt_found = PackageTypeDetector._is_python(f) if pt_found: return "python" # no package type found return None @staticmethod def _is_python(f): names = [] if not os.path.isfile(f): logging.debug("Skipping path: '%s' is not a regular file.", f) return False if tarfile.is_tarfile(f): with tarfile.open(f) as tf: names = tf.getnames() if zipfile.is_zipfile(f): try: with zipfile.ZipFile(f, 'r') as zf: names = zf.namelist() except OSError: # is_zipfile has often false positives and module is # crashing on processing pass for n in map(lambda x: os.path.normpath(x), names): if n.endswith("egg-info/PKG-INFO"): return True return False def _replace_define(filename, def_name, def_value, add_if_missing=True): # first, modify a copy of filename and then move it with codecs.open(filename, 'r+', 'utf8') as f: contents = f.read() f.seek(0) contents_new, subs = re.subn( r'^%define {def_name}(\s*)[^%].*'.format( def_name=def_name), r'%define {def_name}\g<1>{def_value}'.format( def_name=def_name, def_value=def_value), contents, flags=re.MULTILINE) if subs == 0 and add_if_missing: # seems there was no define. add new one before 'Name:' contents_new, subs = re.subn( r'^(Name:.*)$', r'%define {def_name} {def_value}\n\n\g<1>'.format( def_name=def_name, def_value=def_value), contents, flags=re.MULTILINE) f.truncate() f.write(contents_new) def _replace_spec_setup(filename, version_define): # first, modify a copy of filename and then move it with codecs.open(filename, 'r+', 'utf8') as f: contents = f.read() f.seek(0) # %setup without "-n" uses implicit "-n" as "%{name}-%{version}" contents_new, subs = re.subn( r'^%setup\s*((?:-q)?)?\s*$', r'%setup \1 -n %{{name}}-%{{{version_define}}}'.format( version_define=version_define), contents, flags=re.MULTILINE) if subs == 0: # keep inline macros for rpm contents_new, subs = re.subn( r'^%setup(.*)%{version}(.*)$', r'%setup\g<1>%{{{version_define}}}\g<2>'.format( version_define=version_define), contents, flags=re.MULTILINE) if subs > 0: f.truncate() f.write(contents_new) def _replace_tag(filename, tag, string): # first, modify a copy of filename and then move it with codecs.open(filename, 'r+', 'utf8') as f: contents = f.read() f.seek(0) if filename.endswith("PKGBUILD") or filename.endswith("build.collax"): contents_new, subs = re.subn( r"^{tag}=.*".format(tag=tag), r"{tag}={string}".format(tag=tag, string=string), contents, flags=re.MULTILINE) else: # keep inline macros for rpm contents_new, subs = re.subn( r'^{tag}:([ \t\f\v]*)[^%\n\r]*'.format(tag=tag), r'{tag}:\g<1>{string}'.format( tag=tag, string=string), contents, flags=re.MULTILINE) if subs > 0: f.truncate() f.write(contents_new) def _replace_variable(filename, variable, string): # cmake configure_file behavior, replace variables marked with @ sign with codecs.open(filename, 'r+', 'utf8') as f: contents = f.read() f.seek(0) contents_new, subs = re.subn( r"@{variable}@".format(variable=variable), string, contents, flags=re.MULTILINE) if subs > 0: f.truncate() f.write(contents_new) def _replace_debian_changelog_version(fname, version_new): # first, modify a copy of filename and then move it # get current version version_current = VersionDetector.get_version_via_debian_changelog(fname) with codecs.open(fname, 'r+', 'utf8') as f: content_lines = f.readlines() f.seek(0) content_lines[0] = content_lines[0].replace( version_current, version_new, 1) f.truncate() f.writelines(content_lines) def _version_python_pip2rpm(version_pip): """generate a rpm compatible version from a python pip version""" version_rpm = version_pip if not HAS_PACKAGING: return version_rpm try: v = parse(version_pip) with suppress(NameError): if isinstance(v, LegacyVersion): raise InvalidVersion except InvalidVersion: # Maybe is converted already? return None if isinstance(v, Version): if v.is_prerelease: v_rpm = v.public # we need to add the 'x' in front of alpha/beta release because # in the python world, "1.1a10" > "1.1.dev10" # but in the rpm world, "1.1~a10" < "1.1~dev10" v_rpm = v_rpm.replace('a', '~xalpha') v_rpm = v_rpm.replace('b', '~xbeta') v_rpm = v_rpm.replace('rc', '~xrc') v_rpm = v_rpm.replace('.dev', '~dev') version_rpm = v_rpm else: with suppress(NameError): if isinstance(v, LegacyVersion): # TODO(toabctl): handle setuptools style legacy version pass pass return version_rpm def _version_detect(args, files_local): vdetect = VersionDetector(args['regex'], files_local, args["basename"], args["fromfile"]) ver = vdetect.autodetect() logging.debug("Found version '%s'", ver) return ver def _revision_detect(args): revdetect = RevisionDetector() revision = revdetect.autodetect() logging.debug("Found revision '%s'", revision) return revision if __name__ == '__main__': parser = argparse.ArgumentParser( description='Open Build Service source service "set_version".' 'Used to update build description files with a ' 'detected or given version number.') parser.add_argument('--outdir', required=True, help='output directory for modified sources') parser.add_argument('--version', help='use given version string, do not detect it ' 'from source files') parser.add_argument('--revision', help='use given revision string, do not detect it ' 'from obs files') parser.add_argument('--basename', default="", help='detect version based on the file name with ' 'a given prefix') parser.add_argument('--file', action='append', help='modify only this build description. ' 'maybe used multiple times.') parser.add_argument('--debug', default=False, help='Enable more verbose output.') parser.add_argument('--regex', help='regex to be used by autodetect') parser.add_argument('--fromfile', help='detect version based on the ' 'file contents and regex') args = vars(parser.parse_args()) version = args['version'] revision = args['revision'] outdir = args['outdir'] if not outdir: print("no outdir specified") sys.exit(-1) if args['debug']: logging.getLogger().setLevel(logging.DEBUG) logging.debug("Running in debug mode") files_local = _get_local_files() if not version: try: version = _version_detect(args, files_local) except Exception as e: print("Detection failed with error: \"", e, "\".") sys.exit(-1) if not version: print("unable to detect the version") sys.exit(-1) if not revision: try: revision = _revision_detect(args) except Exception as e: print("Revision detection failed with error: \"", e, "\".") revision = '0' if not revision: print("unable to detect the revision") sys.exit(-1) # if no files explicitly specified process whole directory files = args['file'] or files_local # do version convertion if needed version_converted = None if PackageTypeDetector._get_package_type(files) == "python": version_converted = _version_python_pip2rpm(version) # handle rpm specs for f in filter(lambda x: x.endswith(".spec"), files): filename = outdir + "/" + f shutil.copyfile(f, filename) _replace_define(filename, "version_unconverted", version, add_if_missing=False) if version_converted and version_converted != version: _replace_define(filename, "version_unconverted", version) _replace_tag(filename, 'Version', version_converted) _replace_spec_setup(filename, "version_unconverted") else: _replace_tag(filename, 'Version', version) _replace_tag(filename, 'Release', "0") # handle debian packages # append -0 only for non-native packages, otherwise native packages # will be half-converted to non-native and break dpkg-buildpackage for f in filter(lambda x: x.endswith(".dsc"), files): filename = outdir + "/" + f shutil.copyfile(f, filename) if "-" in VersionDetector._get_version_via_debian_dsc(filename): _replace_tag(filename, 'Version', version + "-0") _replace_variable(filename, 'VERSION', version) _replace_variable(filename, 'VERSION-RELEASE', version + "-0") else: _replace_tag(filename, 'Version', version) _replace_variable(filename, 'VERSION', version) _replace_variable(filename, 'VERSION-RELEASE', version) for f in filter(lambda x: x.endswith(("debian.changelog")), files): filename = outdir + "/" + f shutil.copyfile(f, filename) if "-" in VersionDetector.get_version_via_debian_changelog(filename): _replace_debian_changelog_version(filename, version + "-0") else: _replace_debian_changelog_version(filename, version) # handle build.collax recipes for f in filter(lambda x: x.endswith(("build.collax")), files): filename = outdir + "/" + f shutil.copyfile(f, filename) _replace_tag(filename, "version", version) _replace_tag(filename, "build", "0") # handle arch linux PKGBUILD files # TODO: Handle the md5sums generation! for f in filter(lambda x: x.endswith(("PKGBUILD")), files): filename = outdir + "/" + f shutil.copyfile(f, filename) _replace_tag(filename, "md5sums", "('SKIP')") _replace_tag(filename, "sha256sums", "('SKIP')") _replace_tag(filename, "pkgver", version) _replace_tag(filename, "pkgrel", revision) 07070100000013000081A400000000000000000000000166438AD5000003B8000000000000000000000000000000000000003200000000obs-service-set_version-0.6.4/set_version.service<service name="set_version"> <summary>Updates version in spec and dsc files</summary> <description>This service updates a spec file according to the existing files. Can be used after download_url or tar_scm service. </description> <parameter name="version"> <description>Set version to this value, otherwise autodetection is running.</description> </parameter> <parameter name="basename"> <description>Limit version detection to files which start with given name.</description> </parameter> <parameter name="file"> <description>Update only the given file.</description> </parameter> <parameter name="fromfile"> <description>Try to detect version from the contents of the given file.</description> </parameter> <parameter name="regex"> <description>This regex can be used to autodetect the version from the source dir inside the source file or the source file directly.</description> </parameter> </service> 07070100000014000041ED00000000000000000000000366438AD500000000000000000000000000000000000000000000002400000000obs-service-set_version-0.6.4/tests07070100000015000081A400000000000000000000000166438AD500000095000000000000000000000000000000000000004400000000obs-service-set_version-0.6.4/tests/data_test_from_commandline.json[ [ "1.2.3", "1" ], [ "1.2.3", "3.4.5" ], [ "1.2.3~456+789-Devel3", "3.4.5" ], [ "3.4.5", "1.2.3~456+789-Devel3" ] ] 07070100000016000081A400000000000000000000000166438AD50000004C000000000000000000000000000000000000005800000000obs-service-set_version-0.6.4/tests/data_test_from_commandline_with_multiple_files.json[ [ {"Version": "4.5.6"}, "1", ["test1.spec", "test2.spec"] ] ] 07070100000017000081A400000000000000000000000166438AD500000151000000000000000000000000000000000000005500000000obs-service-set_version-0.6.4/tests/data_test_from_commandline_with_single_file.json[ [ {"Version": "4.5.6"}, "1", "test1.spec", ["test2.spec"] ], [ {"Version": "1.2.3"}, "3.4.5", "test1.spec", ["test2.spec"] ], [ {"Version": "1.2.3~456+789-Devel3"}, "3.4.5", "test1.spec", ["test2.spec"] ], [ {"Version": "3.4.5"}, "1.2.3~456+789-Devel3", "test1.spec", ["test2.spec"] ] ] 07070100000018000081A400000000000000000000000166438AD5000000E4000000000000000000000000000000000000004E00000000obs-service-set_version-0.6.4/tests/data_test_from_tarball_with_basename.json[ ["testprog-1.2.3.tar", [], "1.2.3"], ["testprog-1.2.3.tar", ["xyz-4.5.6"], "1.2.3"], ["helloworld-1.2.3.tar", ["testprog-4.5.6"], "4.5.6"], ["helloworld-1.2.3.tar", ["testprog-4.5.6", "another-testprog-7"], "4.5.6"] ] 07070100000019000081A400000000000000000000000166438AD500000294000000000000000000000000000000000000006200000000obs-service-set_version-0.6.4/tests/data_test_from_tarball_with_basename_with_multiple_files.json[ [ "testprog-1.2.3.tar", [], "1.2.3", [ "test1.spec", "test2.spec", "1.debian.changelog", "2.debian.changelog" ] ], [ "testprog-1.2.3.tar", ["xyz-4.5.6"], "1.2.3", [ "test1.spec", "test2.spec", "1.debian.changelog", "2.debian.changelog" ] ], [ "helloworld-1.2.3.tar", ["testprog-4.5.6"], "4.5.6", [ "test1.spec", "test2.spec", "1.debian.changelog", "2.debian.changelog" ] ], [ "helloworld-1.2.3.tar", ["testprog-4.5.6", "another-testprog-7"], "4.5.6", [ "test1.spec", "test2.spec", "1.debian.changelog", "2.debian.changelog" ] ] ] 0707010000001A000081A400000000000000000000000166438AD5000001C4000000000000000000000000000000000000005100000000obs-service-set_version-0.6.4/tests/data_test_from_tarball_with_single_file.json[ ["testprog-1.2.3.tar", [], "8.8.8", "1.2.3"], ["testprog-1.2.3.tar", ["testprog-4.5.6"], "8.8.8", "4.5.6"], ["tetsprog-2015.10.tar", [], "8.8.8", "2015.10"], ["testprog-512.tar", [], "8.8.8", "512"], ["1.2.3.tar", ["testprog-4.5.6"], "8.8.8", "4.5.6"], ["testprog-master.tar", ["testprog-4.5.6"], "8.8.8", "4.5.6"], ["testprog-master.tar", ["testprog-4.5.6"], " ", "4.5.6"], ["testprog-master.tar", ["testprog-4.5.6"], "", "4.5.6"] ] 0707010000001B000041ED00000000000000000000000266438AD500000000000000000000000000000000000000000000002D00000000obs-service-set_version-0.6.4/tests/fixtures0707010000001C000081A400000000000000000000000166438AD500000963000000000000000000000000000000000000003E00000000obs-service-set_version-0.6.4/tests/fixtures/broken-utf8.spec# # spec file for package rawspeed # # Copyright (c) 2017 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # Name: rawspeed Version: 0 Release: 0 License: LGPL-2.1 Summary: Fast raw decoding library Url: https://github.com/darktable-org/rawspeed Group: System/Libraries Source: %{name}-%{version}.tar.xz BuildRequires: cmake >= 3 BuildRequires: gcc-c++ >= 4.9 BuildRequires: libxml2-tools BuildRequires: pkgconfig BuildRequires: pugixml-devel BuildRequires: libjpeg-devel BuildRequires: zlib-devel BuildRequires: googletest-source BuildRoot: %{_tmppath}/%{name}-%{version}-build %description RawSpeed… - is capable of decoding various images in RAW file format. - is intended to provide the fastest decoding speed possible. - supports the most common DSLR and similar class brands. - supplies unmodified RAW data, optionally scaled to 16 bit, or normalized to 0->1 float point data. - supplies CFA layout for all known cameras. - provides automatic black level calculation for cameras having such information. - optionally crops off “junk” areas of images, containing no valid image information. - can add support for new cameras by adding definitions to an xml file. - ~~is extensively crash-tested on broken files~~. - decodes images from memory, not a file stream. You can use a memory mapped file, but it is rarely faster. - open source under the LGPL v2 license. %prep %setup -q %build %cmake -DGOOGLETEST_PATH:PATH=%{_datadir}/googletest-source/ -DBUILD_SHARED_LIBS:BOOL=OFF make %{?_smp_mflags} %check %ctest %install %cmake_install %files %defattr(-,root,root) %{_bindir}/rs-identify %dir %{_datadir}/rawspeed/ %{_datadir}/rawspeed/cameras.xml %{_datadir}/rawspeed/showcameras.xsl 0707010000001D000081A400000000000000000000000166438AD5000001DE000000000000000000000000000000000000002E00000000obs-service-set_version-0.6.4/tests/loader.pyimport importlib.machinery import importlib.util from pathlib import Path def import_set_version(): """Imports the set_version script as a python module and returns it.""" loader = importlib.machinery.SourceFileLoader( 'set_version', str(Path(__file__).parent.joinpath("..", "set_version")) ) spec = importlib.util.spec_from_loader('set_version', loader) sv = importlib.util.module_from_spec(spec) loader.exec_module(sv) return sv 0707010000001E000081A400000000000000000000000166438AD5000025F5000000000000000000000000000000000000003100000000obs-service-set_version-0.6.4/tests/test_base.py# Copyright (C) 2015 SUSE Linux GmbH # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. import os import re import shutil import subprocess import sys import tarfile import tempfile import unittest from ddt import data, ddt, unpack from loader import import_set_version DEBUG = False if os.environ.get('DEBUG_SET_VERSION') == "1": DEBUG = True sv = import_set_version() SET_VERSION_EXECUTABLE = os.path.abspath( os.path.join(os.path.dirname(__file__), '../', 'set_version') ) class SetVersionBaseTest(unittest.TestCase): """Basic test class. Other tests should use this one""" def setUp(self): self._tmpdir = tempfile.mkdtemp(prefix='obs-service-set_version-test-') os.chdir(self._tmpdir) def __file_contains_string(self, file_path, string): with open(file_path, "r") as f: content = f.read() m = re.search(re.escape(string), content) return (m is not None, content) def _check_file_assert_contains(self, file_path, string): contains, content = self.__file_contains_string(file_path, string) err_msg = "%s doesn't contain match of %s. " \ "Content is:\n#####\n%s#####" % ( file_path, string, content) self.assertTrue(contains, err_msg) def _check_file_assert_not_contains(self, file_path, string): contains, content = self.__file_contains_string(file_path, string) err_msg = "%s contain match of %s. " \ "Content is:\n#####\n%s#####" % ( file_path, string, content) self.assertFalse(contains, err_msg) def _write_tarfile(self, tar_name, tar_dirs, tar_files): """write a tarfile with the given dirs and given files""" tar_path = os.path.join(self._tmpdir, tar_name) with tarfile.open(tar_path, "w") as t: for d in tar_dirs: td = tarfile.TarInfo(d) td.type = tarfile.DIRTYPE t.addfile(td) for f in tar_files: td = tarfile.TarInfo(f) t.addfile(td) return tar_path def _run_set_version(self, params=[]): self._tmpoutdir = tempfile.mkdtemp( prefix='obs-service-set_version-test-outdir-') cmd = [sys.executable, SET_VERSION_EXECUTABLE, '--outdir', self._tmpoutdir] + params try: subprocess.check_output( cmd, stderr=subprocess.STDOUT, env=os.environ.copy()) for f in os.listdir(self._tmpoutdir): os.unlink(self._tmpdir+"/"+f) # FIXME: in most modes the files get not replaced, # but store in parallel with _service: prefix shutil.move(self._tmpoutdir+"/"+f, self._tmpdir) shutil.rmtree(self._tmpoutdir) except subprocess.CalledProcessError as e: raise Exception( "Can not call '%s' in dir '%s'. Error: %s" % (" ".join(cmd), self._tmpdir, e.output)) def tearDown(self): if DEBUG: print("DEBUG_SET_VERSION enabled: Please remove '%s' manually." % self._tmpdir) else: shutil.rmtree(self._tmpdir) @ddt class TestSetVersionBasics(SetVersionBaseTest): @data( ( ["%define version_unconverted 1.2.3"], ["%define version_unconverted 4.5.6"], "version_unconverted", "4.5.6" ), ( ["%define version_unconverted 1.2.3"], ["%define version_unconverted 4.5.6"], "version_unconverted", "4.5.6" ), ( ["Hi foo", "%define version_unconverted 1.2.3", "Ho bar"], ["Hi foo", "%define version_unconverted 4.5.6", "Ho bar"], "version_unconverted", "4.5.6" ), ( [ "%define foodef bar", "%define version_unconverted 1.2.3", "%define bardef foo" ], [ "%define foodef bar", "%define version_unconverted 4.5.6", "%define bardef foo" ], "version_unconverted", "4.5.6" ) ) @unpack def test_replace_define_replace(self, lines, expected_lines, define_name, define_value): fn = os.path.join(self._tmpdir, "test-file") with open(fn, "w") as f: f.write("\n".join(lines)) # do the replacement sv._replace_define(os.path.basename(fn), define_name, define_value) # check with open(fn, "r") as f: current_lines = f.read().split("\n") self.assertEqual(len(current_lines), len(expected_lines)) for nbr, l in enumerate(current_lines): self.assertEqual(l, expected_lines[nbr]) @data( ( ["Name: foobar"], ["%define version_unconverted 4.5.6", "", "Name: foobar"], "version_unconverted", "4.5.6" ), ( ["Name: foobar"], ["%define version_unconverted 4.5.6", "", "Name: foobar"], "version_unconverted", "4.5.6" ), ( ["AnyTag: ha", "Name: foo"], [ "AnyTag: ha", "%define version_unconverted 4.5.6", "", "Name: foo" ], "version_unconverted", "4.5.6" ), ( ["Name: foobar", "Version: 1.2.3"], [ "%define version_unconverted 4.5.6", "", "Name: foobar", "Version: 1.2.3" ], "version_unconverted", "4.5.6" ) ) @unpack def test_replace_define_add(self, lines, expected_lines, define_name, define_value): fn = os.path.join(self._tmpdir, "test-file") with open(fn, "w") as f: f.write("\n".join(lines)) # do the addition sv._replace_define(os.path.basename(fn), define_name, define_value) # check with open(fn, "r") as f: current_lines = f.read().split("\n") self.assertEqual(len(current_lines), len(expected_lines)) for nbr, l in enumerate(current_lines): self.assertEqual(l, expected_lines[nbr]) @data( ( ["%setup -q -n %{component}-%{version}"], ["%setup -q -n %{component}-%{version_unconverted}"], ), ( ["%setup -q -n %{component}-1.2.3"], ["%setup -q -n %{component}-1.2.3"], ), ( ["%setup -q -n foobar-%{version}"], ["%setup -q -n foobar-%{version_unconverted}"], ), ( ["%setup -q -n foobar-%{version}-bar"], ["%setup -q -n foobar-%{version_unconverted}-bar"], ), ( ["foo", "%setup -q -n %{component}-%{version}", "bar"], ["foo", "%setup -q -n %{component}-%{version_unconverted}", "bar"], ), ( ["foo", "%setup -q -n %{component}-%{version}", "bar"], ["foo", "%setup -q -n %{component}-%{version_unconverted}", "bar"], ), ( ["foo", "%setup -q", "bar"], ["foo", "%setup -q -n %{name}-%{version_unconverted}", "bar"], ), ( ["foo", "%setup", "bar"], ["foo", "%setup -n %{name}-%{version_unconverted}", "bar"], ) ) @unpack def test_replace_spec_setup(self, lines, expected_lines): fn = os.path.join(self._tmpdir, "test-file") with open(fn, "w") as f: f.write("\n".join(lines)) # do the replacement sv._replace_spec_setup(os.path.basename(fn), "version_unconverted") # check with open(fn, "r") as f: current_lines = f.read().split("\n") self.assertEqual(len(current_lines), len(expected_lines)) for nbr, l in enumerate(current_lines): self.assertEqual(l, expected_lines[nbr]) def test_autodetect_filename(self): dname = os.path.join(self._tmpdir, "test-v1.2.3") os.chdir(self._tmpdir) os.mkdir(dname) subprocess.call(['tar', '-cf', 'test-v1.2.3.tar', 'test-v1.2.3']) files_local = ['test-v1.2.3.tar'] # checking dirname in archive detection args = {'regex': '^test-v(.*)', 'basename': '', 'fromfile': None} ver = sv._version_detect(args, files_local) self.assertEqual(ver, '1.2.3') # checking archive filename detection args = {'regex': '^test-v(.*).tar', 'basename': '', 'fromfile': None} ver = sv._version_detect(args, files_local) self.assertEqual(ver, '1.2.3') 0707010000001F000081A400000000000000000000000166438AD5000010A5000000000000000000000000000000000000003C00000000obs-service-set_version-0.6.4/tests/test_debianchangelog.py# Copyright (C) 2015 SUSE Linux GmbH # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. import os import subprocess import unittest from ddt import ddt, file_data from test_base import SetVersionBaseTest def has_dch_executable(): """the devscripts package is needed to be able to use 'dch'""" with open(os.devnull, "wb") as devnull: try: subprocess.check_call("dch --version", stdout=devnull, stderr=devnull, shell=True) except subprocess.CalledProcessError: return False else: return True @ddt @unittest.skipUnless(has_dch_executable(), "'dch' executable not available") class SetVersionDebianChangelog(SetVersionBaseTest): """Test set_version service for debian/changelog files""" def _write_debian_changelog(self, filename, version): # debian changelogs can't be created with empty versions if not version.strip(): version = "0~0" subprocess.check_call("dch --create --empty -v " "%s --package foobar -c %s" % (version, filename), shell=True) return os.path.join(self._tmpdir, filename) @file_data("data_test_from_commandline.json") def test_from_commandline(self, data): old_version, new_version = data changelog_path = self._write_debian_changelog( "debian.changelog", old_version) self._run_set_version(params=['--version', new_version]) self._check_file_assert_contains(changelog_path, new_version) self._check_file_assert_not_contains(changelog_path, old_version) @file_data("data_test_from_tarball_with_single_file.json") def test_from_tarball_with_single_file(self, data): tarball_name, tarball_dirs, old_version, expected_version = data changelog_path = self._write_debian_changelog( "debian.changelog", old_version) self._write_tarfile(tarball_name, tarball_dirs, []) self._run_set_version() self._check_file_assert_contains(changelog_path, expected_version) if old_version.strip(): self._check_file_assert_not_contains(changelog_path, old_version) @file_data("data_test_from_tarball_with_basename_with_multiple_files.json") def test_from_tarball_with_basename_with_multiple_files(self, data): tarball_name, tarball_dirs, expected_version, dchlog_files = data dchlog_path = [] old_version = "9.9.9-1foobar3" for s in filter(lambda x: x.endswith("debian.changelog"), dchlog_files): dchlog_path.append( self._write_debian_changelog(s, old_version)) self._write_tarfile(tarball_name, tarball_dirs, []) self._run_set_version(["--basename", "testprog"]) for s in dchlog_path: self._check_file_assert_contains(s, expected_version) self._check_file_assert_not_contains(s, old_version) @file_data("data_test_from_tarball_with_basename.json") def test_from_tarball_with_basename(self, data): tarball_name, tarball_dirs, expected_version = data old_version = "9.9.9-0+git3~10" dchlog_path = self._write_debian_changelog("debian.changelog", old_version) self._write_tarfile(tarball_name, tarball_dirs, []) self._run_set_version(["--basename", "testprog"]) self._check_file_assert_contains(dchlog_path, expected_version) self._check_file_assert_not_contains(dchlog_path, old_version) 07070100000020000081A400000000000000000000000166438AD5000005DE000000000000000000000000000000000000004300000000obs-service-set_version-0.6.4/tests/test_package_type_detection.py# Copyright (C) 2015 SUSE Linux GmbH # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. from ddt import data, ddt, unpack from test_base import SetVersionBaseTest from tests.loader import import_set_version sv = import_set_version() @ddt class PackageTypeDetector(SetVersionBaseTest): @data( ("test.tar", [], ["test.egg-info/PKG-INFO"], "python"), ("test.tar", [], ["test-1.2.3a1/test.egg-info/PKG-INFO"], "python"), ("test.tar", [], ["PKG-INFO"], None), ("test.tar", [], ["foo.py"], None) ) @unpack def test_detection(self, tar_name, tar_dirs, tar_files, expected_result): self._write_tarfile(tar_name, tar_dirs, tar_files) files = sv._get_local_files() pack_type = sv.PackageTypeDetector._get_package_type(files) self.assertEqual(expected_result, pack_type) 07070100000021000081A400000000000000000000000166438AD5000008B3000000000000000000000000000000000000003500000000obs-service-set_version-0.6.4/tests/test_pkgbuild.py# Copyright (C) 2015 SUSE Linux GmbH # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. import os from ddt import ddt, file_data from test_base import SetVersionBaseTest @ddt class SetVersionPKGBUILD(SetVersionBaseTest): """Test set_version service for PKGBUILD files""" def _write_pkgbuild_file(self, pkgbuild_name, tags, custom=[]): """write a given filename with the given tags and custom strings""" pkgbuild_path = os.path.join(self._tmpdir, pkgbuild_name) with open(pkgbuild_path, "a") as f: for c in custom: f.write("%s\n" % c) for key, val in tags.items(): f.write("%s=%s\n" % (key, val)) f.write("\n") return pkgbuild_path @file_data("data_test_from_commandline.json") def test_from_commandline(self, data): old_version, new_version = data pkgbuild_path = self._write_pkgbuild_file( "PKGBUILD", {"pkgver": old_version, "md5sums": "fail", "sha256sums": "fail"}) self._run_set_version(params=['--version', new_version]) expected_str = "pkgver=%s" % (new_version) self._check_file_assert_contains(pkgbuild_path, expected_str) self._check_file_assert_not_contains(pkgbuild_path, old_version) expected_str = "md5sums=('SKIP')" self._check_file_assert_contains(pkgbuild_path, expected_str) expected_str = "sha256sums=('SKIP')" self._check_file_assert_contains(pkgbuild_path, expected_str) 07070100000022000081A400000000000000000000000166438AD50000286D000000000000000000000000000000000000003B00000000obs-service-set_version-0.6.4/tests/test_python_pip2rpm.py# Copyright (C) 2015 SUSE Linux GmbH # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. import os import subprocess import unittest from ddt import data, ddt, unpack from packaging.version import parse from test_base import SetVersionBaseTest from tests.loader import import_set_version sv = import_set_version() def _has_zypper(): with open(os.devnull, 'w') as dn: ret = subprocess.call("which zypper", stdout=dn, stderr=subprocess.STDOUT, shell=True) if int(ret) == 0: return True return False def _has_dpkg(): with open(os.devnull, 'w') as dn: ret = subprocess.call("which dpkg", stdout=dn, stderr=subprocess.STDOUT, shell=True) if int(ret) == 0: return True return False HAS_ZYPPER = _has_zypper() HAS_DPKG = _has_dpkg() class VersionCompareBase(object): def __init__(self, version): self.version_str = version def __repr__(self): return self.version_str class ZypperVersionCompare(VersionCompareBase): """ class to compare version strings with zypper""" def _do_compare(self, other): # zypper's return val is negative if v1 is older than v2. # See 'man zypper' ret = subprocess.check_output("zypper --terse versioncmp %s %s" % ( self.version_str, other.version_str), shell=True) return int(ret) def __lt__(self, other): return self._do_compare(other) < 0 def __gt__(self, other): return self._do_compare(other) > 0 def __eq__(self, other): return (self._do_compare(other) == 0) class DpkgVersionCompare(VersionCompareBase): def __do_compare(self, other, op): cmd = 'dpkg --compare-versions "%s" "%s" "%s"' % ( self.version_str, op, other.version_str) ret = subprocess.call(cmd, shell=True) if int(ret) == 0: return True return False def __lt__(self, other): return self.__do_compare(other, 'lt') def __le__(self, other): return self.__do_compare(other, 'le') def __eq__(self, other): return self.__do_compare(other, 'eq') def __gt__(self, other): return self.__do_compare(other, 'gt') def __ge__(self, other): return self.__do_compare(other, 'ge') @ddt class VersionConverterTest(SetVersionBaseTest): @data( ('1', '1'), ('1.0', '1.0'), ('1.0.1', '1.0.1'), ('5.0.0.0a1.dev13', '5.0.0.0~xalpha1~dev13'), ('2015.2.b123', '2015.2~xbeta123'), ('1.2-dev2', '1.2~dev2'), ('1.0.post1', '1.0.post1'), ('1.0rc1', '1.0~xrc1'), ('1.0b1', '1.0~xbeta1'), ('1.7.40~svn', None) ) @unpack def test_python_version_pip2rpm(self, pip_ver, expected_ver): """ See https://www.python.org/dev/peps/pep-0440/\ #examples-of-compliant-version-schemes """ rpm_ver = sv._version_python_pip2rpm(pip_ver) self.assertEqual(rpm_ver, expected_ver) @ddt @unittest.skipIf(HAS_ZYPPER is False and HAS_DPKG is False, "zypper and dpkg are both unavailable") class VersionCompareTests(SetVersionBaseTest): def _do_version_compare(self, v1, op, v2): """ make sure that a version compare with pip and zypper leads to the same result""" # parse pip versions v1_pip = parse(v1) v2_pip = parse(v2) # generate rpm version strings v1_rpm = sv._version_python_pip2rpm(v1) v2_rpm = sv._version_python_pip2rpm(v2) checked_package_managers = [('pip', v1_pip, v2_pip)] # generate Zypper objects to be able to compare the strings if HAS_ZYPPER: v1_zypp = ZypperVersionCompare(v1_rpm) v2_zypp = ZypperVersionCompare(v2_rpm) checked_package_managers.append(('zypper', v1_zypp, v2_zypp)) # generate dpkg objects to be able to compare the strings if HAS_DPKG: v1_dpkg = DpkgVersionCompare(v1_rpm) v2_dpkg = DpkgVersionCompare(v2_rpm) checked_package_managers.append(('dpkg', v1_dpkg, v2_dpkg)) # compare version strings for pip, zypper and dpkg for type_, vv1, vv2 in checked_package_managers: if op == '==': self.assertEqual(vv1, vv2, "%s: %s == %s" % (type_, vv1, vv2)) elif op == '>': self.assertGreater(vv1, vv2, "%s: %s > %s" % (type_, vv1, vv2)) elif op == '>=': self.assertGreaterEqual(vv1, vv2, "%s: %s >= %s" % (type_, vv1, vv2)) elif op == '<': self.assertLess(vv1, vv2, "%s: %s < %s" % (type_, vv1, vv2)) elif op == '<=': self.assertLessEqual(vv1, vv2, "%s: %s <= %s" % (type_, vv1, vv2)) else: raise Exception("Unknown operator '%s'" % op) @data( # pre release spelling # https://www.python.org/dev/peps/pep-0440/#pre-release-spelling ( [ '1.1a', '1.1-a', '1.1.a', '1.1_a', '1.1A', '1.1-A', '1.1.A', '1.1_A', '1.1a0', '1.1-a0', '1.1.a0', '1.1_a0', '1.1A0', '1.1-A0', '1.1.A0', '1.1_A0', '1.1alpha', '1.1-alpha', '1.1.alpha', '1.1_alpha', '1.1ALPHA', '1.1-ALPHA', '1.1.ALPHA', '1.1_ALPHA', '1.1alpha0', '1.1-alpha0', '1.1.alpha0', '1.1_alpha0', '1.1ALPHA0', '1.1-ALPHA0', '1.1.ALPHA0', '1.1_ALPHA0'], '==', '1.1a0' ), ( [ '1.1b', '1.1-b', '1.1.b', '1.1_b', '1.1B', '1.1-B', '1.1.B', '1.1_B', '1.1b0', '1.1-b0', '1.1.b0', '1.1_b0', '1.1B0', '1.1-B0', '1.1.B0', '1.1_B0', '1.1beta', '1.1-beta', '1.1.beta', '1.1_beta', '1.1BETA', '1.1-BETA', '1.1.BETA', '1.1_BETA', '1.1beta0', '1.1-beta0', '1.1.beta0', '1.1_beta0', '1.1BETA0', '1.1-BETA0', '1.1.BETA0', '1.1_BETA0'], '==', '1.1b0' ), ( [ '1.1c', '1.1-c', '1.1.c', '1.1_c', '1.1C', '1.1-C', '1.1.C', '1.1_C', '1.1c0', '1.1-c0', '1.1.c0', '1.1_c0', '1.1C0', '1.1-C0', '1.1.C0', '1.1_C0', '1.1rc', '1.1-rc', '1.1.rc', '1.1_rc', '1.1RC', '1.1-RC', '1.1.RC', '1.1_RC', '1.1rc0', '1.1-rc0', '1.1.rc0', '1.1_rc0', '1.1RC0', '1.1-RC0', '1.1.RC0', '1.1_RC0', '1.1pre', '1.1-pre', '1.1.pre', '1.1_pre', '1.1PRE', '1.1-PRE', '1.1.PRE', '1.1_PRE', '1.1pre0', '1.1-pre0', '1.1.pre0', '1.1_pre0', '1.1PRE0', '1.1-PRE0', '1.1.PRE0', '1.1_PRE0', '1.1preview', '1.1-preview', '1.1.preview', '1.1_preview', '1.1PREVIEW', '1.1-PREVIEW', '1.1.PREVIEW', '1.1_PREVIEW', '1.1preview0', '1.1-preview0', '1.1.preview0', '1.1_preview0', '1.1PREVIEW0', '1.1-PREVIEW0', '1.1.PREVIEW0', '1.1_PREVIEW0', ], '==', '1.1rc0' ), ) @unpack def test_version_normalization(self, v1_list, op, v2): """ test packaging's version normalization. There are crazy thinks like foo-1.0rc0.post1.dev5 possible""" # do the tests with and without 'post' releases # FIXME(toabctl): See https://github.com/pypa/packaging/issues/35 # for post releases, also check 'r', 'R', 'ref' and 'REF' for p in ['', 'post', '-post', '.post', '_post', 'post0', '-post0', '.post0', '_post0']: # do the tests with and without 'dev' releases for d in ['', 'dev', '-dev', '.dev', '_dev', 'dev0', '-dev0', '.dev0', '_dev0']: for vv1 in v1_list: self._do_version_compare("%s%s%s" % (vv1, p, d), op, "%s%s%s" % (v2, p, d)) @data( ( [ '1.1.post10+localver.1', '1.1.post10', # '1.1.post10.dev10+local1', '1.1.post10.dev10', '1.1+local1', '1.1', # '1.1rc10.post10+local1', '1.1rc10.post10', # '1.1rc10.post10.dev10+local1', '1.1rc10.post10.dev10', # '1.1rc9+local1', '1.1rc9', # '1.1b10.post10+local1', '1.1b10.post10', # '1.1b10.post10.dev10+local1', '1.1b10.post10.dev10', # '1.1b10+local1', '1.1b10', # '1.1a10.post10+local1', '1.1a10.post10', # '1.1a10.post10.dev10+local1', '1.1a10.post10.dev10', # '1.1a10+local1', '1.1a10', # '1.1.dev10+local1', '1.1.dev10', ], '>' ) ) @unpack def test_version_ordering(self, version_chain, op): """ version order should be same between pip and zypper""" for i, _ in enumerate(version_chain[:-1]): self._do_version_compare(version_chain[i], op, version_chain[i+1]) 07070100000023000081A400000000000000000000000166438AD500002B6E000000000000000000000000000000000000003400000000obs-service-set_version-0.6.4/tests/test_rpmspec.py# Copyright (C) 2015 SUSE Linux GmbH # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. import os import shutil from ddt import data, ddt, file_data, unpack from test_base import SetVersionBaseTest from tests.loader import import_set_version sv = import_set_version() @ddt class SetVersionSpecfile(SetVersionBaseTest): """Test set_version service for .spec files""" def _write_obsinfo(self, filename, version): # debian changelogs can't be created with empty versions if not version.strip(): version = "0~0" obsinfo_file = open(filename, "w") obsinfo_file.write("name: my_base_name\n") obsinfo_file.write("version: %s\n" % version) obsinfo_file.write("mtime: 1463080107\n") obsinfo_file.write("commit: " "01fcec0959b42a163a7b0a943933488a217f2c9a\n") obsinfo_file.close() return os.path.join(self._tmpdir, filename) def _write_specfile(self, spec_name, spec_tags, custom=[]): """write a given filename with the given rpm tags and custom strings (i.e. '%define foo bar')""" spec_path = os.path.join(self._tmpdir, spec_name) with open(spec_path, "a") as f: for c in custom: f.write("%s\n" % c) for key, val in spec_tags.items(): f.write("%s: %s\n" % (key, val)) f.write("\n") return spec_path def test_version_from_obsinfo(self): obsinfo = self._write_obsinfo("test.obsinfo", "0.0.1") files = [obsinfo] vdetector = sv.VersionDetector(None, files, '') ver = vdetector._get_version_via_obsinfo() self.assertEqual(ver, "0.0.1") @file_data("data_test_from_commandline.json") def test_from_commandline(self, data): old_version, new_version = data spec_path = self._write_specfile("test.spec", {"Version": old_version}) self._run_set_version(params=['--version', new_version]) self._check_file_assert_contains(spec_path, new_version) @file_data("data_test_from_commandline_with_single_file.json") def test_from_commandline_with_single_file(self, data): spec_tags, new_version, spec_file, other_spec_files = data """only a single .spec file should contain the given version""" spec_path = self._write_specfile(spec_file, spec_tags) # other spec file which shouldn't be updated other_spec_path = [] for s in other_spec_files: other_spec_path.append(self._write_specfile(s, spec_tags)) self._run_set_version(params=["--version", new_version, "--file", spec_file]) # our given spec should have the version self._check_file_assert_contains(spec_path, new_version) # all others shouldn't for s in other_spec_path: self._check_file_assert_not_contains(s, new_version) @file_data("data_test_from_commandline_with_multiple_files.json") def test_from_commandline_with_multiple_files(self, data): """all .spec files should contain the given version""" spec_tags, new_version, spec_files = data spec_path = [] for s in spec_files: spec_path.append(self._write_specfile(s, spec_tags)) self._run_set_version(params=["--version", new_version]) for s in spec_path: self._check_file_assert_contains(s, new_version) @file_data("data_test_from_tarball_with_single_file.json") def test_from_tarball_with_single_file(self, data): tarball_name, tarball_dirs, old_version, expected_version = data spec_path = self._write_specfile("test.spec", {"Name": "foo", "Version": old_version, "Group": "AnyGroup"}) self._write_tarfile(tarball_name, tarball_dirs, []) self._run_set_version() self._check_file_assert_contains(spec_path, expected_version) self._check_file_assert_contains(spec_path, "Name: foo") self._check_file_assert_contains(spec_path, "Group: AnyGroup") @file_data("data_test_from_tarball_with_single_file.json") def test_from_obsinfo(self, data): tarball_name, tarball_dirs, old_version, expected_version = data self._write_obsinfo("test.obsinfo", expected_version) spec_path = self._write_specfile("test.spec", {"Name": "foo", "Version": old_version, "Group": "AnyGroup"}) os.mkdir(os.path.join(self._tmpdir, "pristine-tar")) os.mkdir(os.path.join(self._tmpdir, "pristine.tar")) self._run_set_version() self._check_file_assert_contains(spec_path, expected_version) self._check_file_assert_contains(spec_path, "Name: foo") self._check_file_assert_contains(spec_path, "Group: AnyGroup") @file_data("data_test_from_tarball_with_basename_with_multiple_files.json") def test_from_tarball_with_basename_with_multiple_files(self, data): tarball_name, tarball_dirs, expected_version, spec_files = data spec_path = [] for s in filter(lambda x: x.endswith(".spec"), spec_files): spec_path.append(self._write_specfile(s, {"Version": "UNKNOWN"})) self._write_tarfile(tarball_name, tarball_dirs, []) self._run_set_version(["--basename", "testprog"]) for s in spec_path: self._check_file_assert_contains(s, expected_version) @file_data("data_test_from_tarball_with_basename.json") def test_from_tarball_with_basename(self, data): tarball_name, tarball_dirs, expected_version = data spec_path = self._write_specfile("test.spec", {"Version": "UNKNOWN"}) self._write_tarfile(tarball_name, tarball_dirs, []) self._run_set_version(["--basename", "testprog"]) self._check_file_assert_contains(spec_path, expected_version) @data( ( "test.spec", "test-master.tar", [], ["test-5.0.0.0b2dev188/test.egg-info/PKG-INFO"], "5.0.0.0b2dev188", "5.0.0.0~xbeta2~dev188" ) ) @unpack def test_python_package_from_tarball_with_single_file( self, spec_file, tar_name, tar_dirs, tar_files, org_version, conv_version): spec_path = self._write_specfile( spec_file, {"Name": "test", "Version": "UNKNOWN", "Group": "AnyGroup"}, ["%define foo bar"]) self._write_tarfile(tar_name, tar_dirs, tar_files) self._run_set_version() self._check_file_assert_contains( spec_path, "Version: %s" % conv_version) self._check_file_assert_contains( spec_path, "define version_unconverted %s" % org_version) self._check_file_assert_contains( spec_path, "Name: test") self._check_file_assert_contains( spec_path, "Group: AnyGroup") self._check_file_assert_contains( spec_path, "%define foo bar") self._check_file_assert_not_contains(spec_path, "UNKNOWN") @data( ( "test.spec", [ "Version: 1.2.3", "Name: test", "%define component test", "%setup -p -n %{component}-%{version}" ], [ "Version: 5.0.0.0~xbeta2~dev188", "%define version_unconverted 5.0.0.0b2dev188", "", "Name: test", "%define component test", "%setup -p -n %{component}-%{version_unconverted}" ], "test-master.tar", [], ["test-5.0.0.0b2dev188/test.egg-info/PKG-INFO"] ), ( "test.spec", [ "Version: 1.2.3", "Name: test", "%define component version", "%setup -p -n %{component}-%{version}-foobar" ], [ "Version: 5.0.0.0~xbeta2~dev188", "%define version_unconverted 5.0.0.0b2dev188", "", "Name: test", "%define component version", "%setup -p -n %{component}-%{version_unconverted}-foobar" ], "test-master.tar", [], ["test-5.0.0.0b2dev188/test.egg-info/PKG-INFO"] ), ( "test.spec", [ "Version: 5.0.0.0~xbeta2~dev188", "%define version_unconverted 5.0.0.0b2dev188", ], [ "Version: 5.1.0", "%define version_unconverted 5.1.0", ], "test-master.tar", [], ["test-5.1.0/test.egg-info/PKG-INFO"] ), ( "test.spec", [ "Version: 1.2.3", "Name: test", "%define component test", "%setup -p -n %{component}-%{version}" ], [ "Version: 5.0.0", "Name: test", "%define component test", "%setup -p -n %{component}-%{version}" ], "test-master.tar", [], ["test-5.0.0/test.egg-info/PKG-INFO"] ), ) @unpack def test_python_package( self, spec_file, spec_lines, expected_spec_lines, tar_name, tar_dirs, tar_files): fn = os.path.join(self._tmpdir, spec_file) with open(fn, "w") as f: f.write("\n".join(spec_lines)) self._write_tarfile(tar_name, tar_dirs, tar_files) self._run_set_version() # check with open(fn, "r") as f: current_lines = f.read().split("\n") self.assertEqual(len(current_lines), len(expected_spec_lines)) for nbr, l in enumerate(current_lines): self.assertEqual(l, expected_spec_lines[nbr]) def test_broken_utf8_spec(self): fn = os.path.join(os.path.dirname(__file__), 'fixtures', 'broken-utf8.spec') nfn = fn + "1" shutil.copyfile(fn, nfn) sv._replace_spec_setup(nfn, '0.0.1') os.unlink(nfn) 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!190 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor