Hello community,

here is the log from the commit of package 
obs-service-replace_using_package_version for openSUSE:Factory checked in at 
2018-10-09 15:54:13
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/obs-service-replace_using_package_version 
(Old)
 and      
/work/SRC/openSUSE:Factory/.obs-service-replace_using_package_version.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "obs-service-replace_using_package_version"

Tue Oct  9 15:54:13 2018 rev:2 rq:640750 version:0.0.2

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/obs-service-replace_using_package_version/obs-service-replace_using_package_version.changes
      2018-03-26 13:02:01.903571479 +0200
+++ 
/work/SRC/openSUSE:Factory/.obs-service-replace_using_package_version.new/obs-service-replace_using_package_version.changes
 2018-10-09 15:54:15.070276788 +0200
@@ -1,0 +2,10 @@
+Tue Oct 09 07:24:59 UTC 2018 - [email protected]
+
+- Update to version 1539069197.d0e12bd:
+  * Bump version: 0.0.1 → 0.0.2
+  * Add bumpversion support
+  * Add the `--parse-version` flag (fixes bsc#1111089)
+  * Add a simple example in README.md
+  * Adjusting readme and tests code style
+
+-------------------------------------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ obs-service-replace_using_package_version.spec ++++++
--- /var/tmp/diff_new_pack.rY9sul/_old  2018-10-09 15:54:15.446276342 +0200
+++ /var/tmp/diff_new_pack.rY9sul/_new  2018-10-09 15:54:15.446276342 +0200
@@ -1,5 +1,5 @@
 #
-# spec file for package obs-service-replace_with_package_version
+# spec file for package obs-service-replace_using_package_version
 #
 # Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
 #
@@ -14,10 +14,13 @@
 
 # Please submit bugfixes or comments via http://bugs.opensuse.org/
 #
+
+
+#
 %define service replace_using_package_version
 
 Name:           obs-service-%{service}
-Version:        0.0.1
+Version:        0.0.2
 Release:        0
 Summary:        An OBS service: Replaces a regex  with the version value of a 
package
 License:        GPL-3.0-or-later
@@ -26,12 +29,12 @@
 Source0:        %{service}.tar
 %if 0%{?suse_version} > 1315
 BuildRequires:  python3-setuptools
-Requires:       python3-setuptools
 Requires:       python3-docopt
+Requires:       python3-setuptools
 %else
 BuildRequires:  python-setuptools
-Requires:       python-setuptools
 Requires:       python-docopt
+Requires:       python-setuptools
 %endif
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
 BuildArch:      noarch

++++++ _servicedata ++++++
--- /var/tmp/diff_new_pack.rY9sul/_old  2018-10-09 15:54:15.478276305 +0200
+++ /var/tmp/diff_new_pack.rY9sul/_new  2018-10-09 15:54:15.478276305 +0200
@@ -1,4 +1,4 @@
 <servicedata>
 <service name="tar_scm">
                 <param 
name="url">https://github.com/openSUSE/obs-service-replace_using_package_version.git</param>
-              <param 
name="changesrevision">36ea78a0c49b10c8aeafbb0d5d0a81081bc67cff</param></service></servicedata>
\ No newline at end of file
+              <param 
name="changesrevision">d0e12bd2a9d638b630e37f88659261c942a841d6</param></service></servicedata>
\ No newline at end of file

++++++ replace_using_package_version.tar ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/replace_using_package_version/.bumpversion.cfg 
new/replace_using_package_version/.bumpversion.cfg
--- old/replace_using_package_version/.bumpversion.cfg  1970-01-01 
01:00:00.000000000 +0100
+++ new/replace_using_package_version/.bumpversion.cfg  2018-10-09 
09:13:17.000000000 +0200
@@ -0,0 +1,7 @@
+[bumpversion]
+current_version = 0.0.2
+commit = True
+tag = True
+
+[bumpversion:file:obs-service-replace_using_package_version.spec]
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/replace_using_package_version/README.md 
new/replace_using_package_version/README.md
--- old/replace_using_package_version/README.md 2018-03-20 18:07:46.000000000 
+0100
+++ new/replace_using_package_version/README.md 2018-10-09 09:13:17.000000000 
+0200
@@ -28,3 +28,29 @@
 # Run tests and code style checks
 $ tox
 ```
+
+## Usage
+
+Consider a `_service` file that includes the following:
+
+```xml
+<service name="replace_using_package_version" mode="buildtime">
+  <param name="file">mariadb-image.kiwi</param>
+  <param name="regex">%%TAG%%</param>
+  <param name="package">mariadb</param>
+  <param name="parse-version">minor</param>
+</service>
+```
+
+The service in this case would look for the `mariadb` package in the build
+environment, get its version, and try to replace any occurrence of `%%TAG%%`
+in `mariadb-imgae.kiwi` file with the `mariadb` package version.
+
+The `parse-version` states to use only up to the minor version part for a given
+versio string. For instance, in this specific case, the service will
+apply the `^(\d+(\.\d+){0,1})` regular expression and use only the first match.
+In case `mariadb` version was `10.3.4~git_r154` only the `10.3` part would be
+used as the replacement string.
+
+This service is mainly designed to work in `buildtime` mode, so it is applied
+inside the build environment just before the start of the build.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/replace_using_package_version/obs-service-replace_using_package_version.spec
 
new/replace_using_package_version/obs-service-replace_using_package_version.spec
--- 
old/replace_using_package_version/obs-service-replace_using_package_version.spec
    2018-03-20 18:07:46.000000000 +0100
+++ 
new/replace_using_package_version/obs-service-replace_using_package_version.spec
    2018-10-09 09:13:17.000000000 +0200
@@ -17,7 +17,7 @@
 %define service replace_using_package_version
 
 Name:           obs-service-%{service}
-Version:        0.0.1
+Version:        0.0.2
 Release:        0
 Summary:        An OBS service: Replaces a regex  with the version value of a 
package
 License:        GPL-3.0-or-later
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/replace_using_package_version/replaceUsingPackageVersion/replace_using_package_version.py
 
new/replace_using_package_version/replaceUsingPackageVersion/replace_using_package_version.py
--- 
old/replace_using_package_version/replaceUsingPackageVersion/replace_using_package_version.py
       2018-03-20 18:07:46.000000000 +0100
+++ 
new/replace_using_package_version/replaceUsingPackageVersion/replace_using_package_version.py
       2018-10-09 09:13:17.000000000 +0200
@@ -26,6 +26,7 @@
     replace_using_package_version.py -h
     replace_using_package_version.py --file=FILE --regex=REGEX --outdir=DIR
         (--package=PACKAGE | --replacement=REPLACEMENT)
+        [--parse-version=DEPTH]
 
 Options:
     -h,--help                   : show this help message
@@ -33,7 +34,10 @@
     --file=FILE                 : file to update
     --package=PACKAGE           : package to check
     --replacement=REPLACEMENT   : replacement string for any match
-    --regex=REGEX               : regular expression for parsing
+    --regex=REGEX               : regular expression for parsing file
+    --parse-version=DEPTH       : parse the package version string to match
+                                    major.minor.patch format. It can be set
+                                    to 'major', 'minor' or 'patch'.
 """
 import docopt
 import re
@@ -49,6 +53,12 @@
     # TODO: probably there is a better way to set the repositories path
     rpm_dir = './repos'
 
+    version_regex = {
+        'major': '^(\d+)',
+        'minor': '^(\d+(\.\d+){0,1})',
+        'patch': '^(\d+(\.\d+){0,2})'
+    }
+
     command_args = docopt.docopt(__doc__)
 
     if not os.path.isfile(command_args['--file']):
@@ -64,7 +74,17 @@
     ])
 
     if command_args['--package']:
+        parse_version = command_args['--parse-version']
         version = find_package_version(command_args['--package'], rpm_dir)
+        if parse_version and parse_version not in version_regex.keys():
+            raise Exception((
+                'Invalid value for this flag. Expected format is: '
+                '--parse-version=[major|minor|patch]'
+            ))
+        elif parse_version:
+            version = find_match_in_version(
+                version_regex[parse_version], version
+            )
         replacement = version
     else:
         replacement = command_args['--replacement']
@@ -106,6 +126,14 @@
     return str(version)
 
 
+def find_match_in_version(regexpr, version):
+    search = re.search(regexpr, version)
+    if search is None:
+        return version
+    else:
+        return search.group(1)
+
+
 def run_command(command):
     process = subprocess.Popen(
         command,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/replace_using_package_version/replace_using_package_version.service 
new/replace_using_package_version/replace_using_package_version.service
--- old/replace_using_package_version/replace_using_package_version.service     
2018-03-20 18:07:46.000000000 +0100
+++ new/replace_using_package_version/replace_using_package_version.service     
2018-10-09 09:13:17.000000000 +0200
@@ -14,9 +14,20 @@
     <description>This is the package whos version will be used as a replacement
 for the regex. It must be included to the build as dependency.</description>
   </parameter>
+  <parameter name="parse-version">
+    <description>Parses the package version string to match the
+major.minor.patch format. Then any found match is used as the replacement
+string. It can be set to three different values: major, minor or patch.
+If set to major only the first numeric value will be used as the
+replacement (e.g. if version is 3.1.3 only 3 will be used). If set to minor
+only the first and seconf numeric values separated by a dot will be used
+(e.g. if version is 3.1~git_r125 only 3.1 will be used). If set to patch
+it will reach up to the first three numeric values separated with a dots.
+  </parameter>
   <parameter name="replacement">
     <description>This parameter is an alternative to the package parameter,
 instead to look for a package version it will just use the given string
-for the regex replacement. It is mostly used to debug or test the 
regex.</description>
+for the regex replacement. It is mostly used to debug or test the
+regex.</description>
   </parameter>
 </service>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/replace_using_package_version/requirements.txt 
new/replace_using_package_version/requirements.txt
--- old/replace_using_package_version/requirements.txt  2018-03-20 
18:07:46.000000000 +0100
+++ new/replace_using_package_version/requirements.txt  2018-10-09 
09:13:17.000000000 +0200
@@ -1,8 +1,8 @@
 coverage
 docopt
 flake8
-pycodestyle
 pytest
 pytest-cov
 tox
 mock
+bumpversion
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/replace_using_package_version/test/replace_using_package_version_test.py 
new/replace_using_package_version/test/replace_using_package_version_test.py
--- 
old/replace_using_package_version/test/replace_using_package_version_test.py    
    2018-03-20 18:07:46.000000000 +0100
+++ 
new/replace_using_package_version/test/replace_using_package_version_test.py    
    2018-10-09 09:13:17.000000000 +0200
@@ -1,10 +1,10 @@
 import sys
 from mock import patch, mock_open, call, Mock
-from pkg_resources import parse_version
 
 from replaceUsingPackageVersion.replace_using_package_version import (
     apply_regex_to_file,
     find_package_version,
+    find_match_in_version,
     main,
     run_command,
     init
@@ -31,6 +31,18 @@
             'and yet CHANGED line\n'
         ))
 
+    def test_find_match_in_version(self):
+        match = find_match_in_version('^(\d+)', '0.0.1')
+        assert match == '0'
+        match = find_match_in_version('^(\d+(\.\d+){0,1})', '0.0.1~rev+af232f')
+        assert match == '0.0'
+        match = find_match_in_version('^(\d+(\.\d+){0,2})', '0.0.1~rev+af232f')
+        assert match == '0.0.1'
+        match = find_match_in_version('^(\d+(\.\d+){0,2})', '234~rev+af232f')
+        assert match == '234'
+        match = find_match_in_version('^(\d+(\.\d+){0,1})', 'as234~rev+af232f')
+        assert match == 'as234~rev+af232f'
+
     @patch((
         'replaceUsingPackageVersion.'
         'replace_using_package_version.run_command'
@@ -129,7 +141,8 @@
             '--package': 'package',
             '--file': 'file',
             '--outdir': 'outdir',
-            '--regex': 'regex'
+            '--regex': 'regex',
+            '--parse-version': 'minor'
         }
         mock_find_pkg.return_value = '0.0.1'
         main()
@@ -137,11 +150,80 @@
             'package', './repos'
         )
         mock_apply_regex.assert_called_once_with(
-            'file', 'outdir/file', 'regex', '0.0.1'
+            'file', 'outdir/file', 'regex', '0.0'
         )
 
     @patch((
         'replaceUsingPackageVersion.'
+        'replace_using_package_version.find_match_in_version'
+    ))
+    @patch((
+        'replaceUsingPackageVersion.'
+        'replace_using_package_version.apply_regex_to_file'
+    ))
+    @patch((
+        'replaceUsingPackageVersion.'
+        'replace_using_package_version.find_package_version'
+    ))
+    @patch('docopt.docopt')
+    @patch('os.path.isdir')
+    @patch('os.path.isfile')
+    def test_main_package_parse_version(
+        self, mock_isfile, mock_isdir, mock_docopt,
+        mock_find_pkg, mock_apply_regex, mock_match_version
+    ):
+        mock_isdir.return_value = True
+        mock_isfile.return_value = True
+        mock_docopt.return_value = {
+            '--package': 'package',
+            '--file': 'file',
+            '--outdir': 'outdir',
+            '--regex': 'regex',
+            '--parse-version': 'minor'
+        }
+        mock_find_pkg.return_value = '0.0.1'
+        mock_match_version.return_value = '0.0'
+        main()
+        mock_find_pkg.assert_called_once_with(
+            'package', './repos'
+        )
+        mock_apply_regex.assert_called_once_with(
+            'file', 'outdir/file', 'regex', '0.0'
+        )
+        mock_match_version.assert_called_once_with(
+            '^(\d+(\.\d+){0,1})', '0.0.1'
+        )
+
+    @patch((
+        'replaceUsingPackageVersion.'
+        'replace_using_package_version.find_package_version'
+    ))
+    @patch('docopt.docopt')
+    @patch('os.path.isdir')
+    @patch('os.path.isfile')
+    def test_main_package_parse_version_invalid_argument(
+        self, mock_isfile, mock_isdir, mock_docopt, mock_find_pkg
+    ):
+        mock_find_pkg.return_value = '1.34.2'
+        mock_isdir.return_value = True
+        mock_isfile.return_value = True
+        mock_docopt.return_value = {
+            '--package': 'package',
+            '--file': 'file',
+            '--outdir': 'outdir',
+            '--regex': 'regex',
+            '--parse-version': 'invalid-value'
+        }
+        exception = False
+        try:
+            main()
+        except Exception as e:
+            assert 'Invalid value for this flag.' in str(e)
+            exception = True
+        assert exception
+
+    @patch((
+        'replaceUsingPackageVersion.'
         'replace_using_package_version.apply_regex_to_file'
     ))
     @patch('docopt.docopt')


Reply via email to