From 7cc29fcf7b32430fab5206e5b0637b802bfcd27f Mon Sep 17 00:00:00 2001 From: Olivier Soldano Date: Wed, 22 Feb 2023 14:40:49 +0100 Subject: [PATCH 1/5] add support for rpm %attr for files --- rpmvenv/extensions/files/extras.py | 23 ++++++++++++++--------- rpmvenv/extensions/files/option.py | 24 ++++++++++++++++++++---- tests/test_fileoption.py | 24 +++++++++++++++++++++++- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/rpmvenv/extensions/files/extras.py b/rpmvenv/extensions/files/extras.py index 88b231c..476fd62 100644 --- a/rpmvenv/extensions/files/extras.py +++ b/rpmvenv/extensions/files/extras.py @@ -42,22 +42,32 @@ def generate(config, spec): """Produce file block segments for packaging files.""" for file_ in config.file_extras.files: + file_directive = "" + if file_.file_attr is not None: + # file with attributes modifiers (permissions, user, group) + file_directive = '%attr({0}, {1}, {2}) '.format( + file_.file_attr['permissions'], + file_.file_attr['user'], + file_.file_attr['group'], + ) + if file_.file_type is not None: if file_.file_type_option is not None: # file with a modifier (e.g. config) including an option # (e.g. noreplace) - file_directive = '%{1}({2}) /{0}'.format( + file_directive += '%{1}({2}) /{0}'.format( file_.dest, file_.file_type, file_.file_type_option ) else: # file with a modifier (e.g. doc) but no additional option - file_directive = '%{1} /{0}'.format(file_.dest, - file_.file_type) + file_directive += file_directive + '%{1} /{0}'.format( + file_.dest, + file_.file_type) else: # simple file without an extra modifiers - file_directive = '/{0}'.format(file_.dest) + file_directive += '/{0}'.format(file_.dest) spec.blocks.install.append( 'mkdir -p "%{{buildroot}}/%(dirname {0})"'.format(file_.dest) @@ -69,10 +79,5 @@ def generate(config, spec): ) ) spec.blocks.files.append(file_directive) - spec.blocks.post.append( - 'chown -R ' - '%{{file_permissions_user}}:%{{file_permissions_group}} ' - '/{0}'.format(file_.dest) - ) return spec diff --git a/rpmvenv/extensions/files/option.py b/rpmvenv/extensions/files/option.py index f1647ef..94f97b2 100644 --- a/rpmvenv/extensions/files/option.py +++ b/rpmvenv/extensions/files/option.py @@ -1,5 +1,4 @@ """Confpy extension that supports using RPM file paths as config options.""" - from collections.abc import MutableMapping from collections import namedtuple @@ -11,7 +10,11 @@ basestring = str RpmFile = namedtuple('RpmFile', - ['src', 'dest', 'file_type', 'file_type_option']) + ['src', + 'dest', + 'file_type', + 'file_type_option', + 'file_attr']) class FileOption(option.Option): @@ -52,10 +55,22 @@ def coerce(self, value): elif value.get('doc', False): file_type = 'doc' + file_attr = value.get('attr', None) + if file_attr is not None and isinstance(file_attr, MutableMapping): + if 'permissions' not in file_attr: + file_attr['permissions'] = '-' + if 'user' not in file_attr: + file_attr['user'] = '-' + if 'group' not in file_attr: + file_attr['group'] = '-' + elif file_attr is not None: # Erase wrong values + file_attr = None + return RpmFile(src=value['src'], dest=value['dest'], file_type=file_type, - file_type_option=file_type_option) + file_type_option=file_type_option, + file_attr=file_attr,) elif isinstance(value, basestring): try: @@ -63,7 +78,8 @@ def coerce(self, value): return RpmFile(src=src, dest=dest, file_type=None, - file_type_option=None) + file_type_option=None, + file_attr=None,) except ValueError: raise ValueError('The value {0} is missing a :'.format(value)) diff --git a/tests/test_fileoption.py b/tests/test_fileoption.py index 8eefc54..e31eda1 100644 --- a/tests/test_fileoption.py +++ b/tests/test_fileoption.py @@ -64,6 +64,7 @@ def test_parse_dict_no_file_type_explicit(): assert rpm_file.dest == value['dest'] assert rpm_file.file_type is None assert rpm_file.file_type_option is None + assert rpm_file.file_attr is None def test_parse_dict_doc_file(): @@ -72,7 +73,7 @@ def test_parse_dict_doc_file(): value = { 'src': '/foo/bar', 'dest': '/etc/foo', - 'doc': 'foobar' # anything truthy is okay, value is ignored + 'doc': 'foobar', # anything truthy is okay, value is ignored } rpm_file = parser.coerce(value) @@ -100,6 +101,27 @@ def test_parse_dict_config_file_no_option(): assert rpm_file.file_type_option is None +def test_parse_dict_file_with_attributes(): + parser = file_opt.FileOption() + + value = { + 'src': '/foo/bar', + 'dest': '/etc/foo', + 'attr': { + "permissions": "0644", + "user": "testuser" + } + } + + rpm_file = parser.coerce(value) + assert isinstance(rpm_file, file_opt.RpmFile) + assert rpm_file.src == value['src'] + assert rpm_file.dest == value['dest'] + assert rpm_file.file_type == None + assert rpm_file.file_type_option == None + assert rpm_file.file_attr == {"permissions": "0644", "user":"testuser", "group":"-"} + + def test_parse_dict_config_file_with_option(): parser = file_opt.FileOption() From e538a8798cb1d73ff41e301ad17a132286d03d8c Mon Sep 17 00:00:00 2001 From: Olivier Soldano Date: Wed, 22 Feb 2023 16:50:36 +0100 Subject: [PATCH 2/5] fix forgotten lnts --- rpmvenv/extensions/files/option.py | 2 +- tests/test_fileoption.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rpmvenv/extensions/files/option.py b/rpmvenv/extensions/files/option.py index 94f97b2..204ba65 100644 --- a/rpmvenv/extensions/files/option.py +++ b/rpmvenv/extensions/files/option.py @@ -63,7 +63,7 @@ def coerce(self, value): file_attr['user'] = '-' if 'group' not in file_attr: file_attr['group'] = '-' - elif file_attr is not None: # Erase wrong values + elif file_attr is not None: # Erase wrong values file_attr = None return RpmFile(src=value['src'], diff --git a/tests/test_fileoption.py b/tests/test_fileoption.py index e31eda1..0f8e184 100644 --- a/tests/test_fileoption.py +++ b/tests/test_fileoption.py @@ -117,9 +117,13 @@ def test_parse_dict_file_with_attributes(): assert isinstance(rpm_file, file_opt.RpmFile) assert rpm_file.src == value['src'] assert rpm_file.dest == value['dest'] - assert rpm_file.file_type == None - assert rpm_file.file_type_option == None - assert rpm_file.file_attr == {"permissions": "0644", "user":"testuser", "group":"-"} + assert rpm_file.file_type is None + assert rpm_file.file_type_option is None + assert rpm_file.file_attr == { + "permissions": "0644", + "user": "testuser", + "group": "-" + } def test_parse_dict_config_file_with_option(): From 7c09d8dfbfaf4a8496ab5824ed4e3ac336ce74a2 Mon Sep 17 00:00:00 2001 From: Olivier Soldano Date: Thu, 23 Feb 2023 11:26:08 +0100 Subject: [PATCH 3/5] update addon package denomination --- .github/workflows/ci.yml | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2d323f..b923189 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: fail-fast: true steps: - name: Install deps - run: sudo apt update && sudo apt install -y rpm enchant + run: sudo apt update && sudo apt install -y rpm enchant-2 - name: Checkhout uses: actions/checkout@v2.4.0 - name: Setup Python ${{ matrix.pyver }} diff --git a/.travis.yml b/.travis.yml index 6172691..d9ea9ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ addons: apt: packages: - rpm - - enchant + - enchant-2 install: - if [[ "$(python --version 2>&1)" =~ Python\ (2\.*) ]]; then pip install -U jinja2; else echo "Skipping JINJA2 for $(python --version 2>&1)."; fi - pip install -rtest-requirements.txt From 8848a9f2ce262a724eb717d46e5488a9732420d6 Mon Sep 17 00:00:00 2001 From: Olivier Soldano Date: Thu, 23 Feb 2023 11:26:08 +0100 Subject: [PATCH 4/5] update python versions for tests conform to versions available in https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json selected the most recent at date of commit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b923189..bc88528 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pyver: ["3.6", "3.7", "3.8", "3.9", "3.10"] + pyver: ["3.6.15", "3.7.15", "3.8.16", "3.9.16", "3.10.10"] fail-fast: true steps: - name: Install deps From 26b38b6105c4bb894fcd1dcf450a671968ed6415 Mon Sep 17 00:00:00 2001 From: Kevin Conway Date: Thu, 23 Feb 2023 08:27:27 -0600 Subject: [PATCH 5/5] Remove Python 3.6 from build matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc88528..65d9aa9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pyver: ["3.6.15", "3.7.15", "3.8.16", "3.9.16", "3.10.10"] + pyver: ["3.7", "3.8", "3.9", "3.10", "3.11"] fail-fast: true steps: - name: Install deps