diff --git a/.github/workflows/pycodestyle.yml b/.github/workflows/pycodestyle.yml new file mode 100644 index 0000000..9334712 --- /dev/null +++ b/.github/workflows/pycodestyle.yml @@ -0,0 +1,59 @@ +name: PyCodeStyle +on: +- push +- pull_request +- workflow_call + +jobs: + python-3: + name: PyCodeStyle + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install pylint + run: | + python -m pip install --upgrade pip + pip install pycodestyle + + - name: Analysing the code with pylint + run: | + pycodestyle --config=./.pycodestyle . + + python-2-7: + name: PyCodeStyle + runs-on: ubuntu-latest + container: + image: python:2.7.18-buster + strategy: + fail-fast: false + matrix: + python-version: ["2.7"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install pylint + run: | + python -m pip install --upgrade pip + pip install pycodestyle + + - name: Analysing the code with pylint + run: | + pycodestyle --config=./.pycodestyle . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c81211..0731eb0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,8 @@ jobs: uses: redhat-cop/infra.lvm_snapshots/.github/workflows/ansible-lint.yml@main pylint: uses: redhat-cop/infra.lvm_snapshots/.github/workflows/pylint.yml@main + pycodestyle: + uses: redhat-cop/infra.lvm_snapshots/.github/workflows/pycodestyle.yml@main shellcheck: uses: redhat-cop/infra.lvm_snapshots/.github/workflows/shellcheck.yml@main codespell: @@ -19,6 +21,7 @@ jobs: needs: - ansible-lint - pylint + - pycodestyle - shellcheck - codespell runs-on: ubuntu-latest @@ -27,6 +30,7 @@ jobs: python -c "assert set([ '${{ needs.ansible-lint.result }}', '${{ needs.pylint.result }}', + '${{ needs.pycodestyle.result }}', '${{ needs.shellcheck.result }}', '${{ needs.codespell.result }}', ]) == {'success'}" diff --git a/.pycodestyle b/.pycodestyle new file mode 100644 index 0000000..2b68278 --- /dev/null +++ b/.pycodestyle @@ -0,0 +1,2 @@ +[pycodestyle] +max-line-length=120 diff --git a/roles/snapshot_create/files/check.py b/roles/snapshot_create/files/check.py index b79a5d4..02d483b 100644 --- a/roles/snapshot_create/files/check.py +++ b/roles/snapshot_create/files/check.py @@ -30,13 +30,16 @@ 'ext4' ] + class CheckException(Exception): """ Exception wrapper """ + parser = argparse.ArgumentParser() parser.add_argument('that', help='What should the script check', type=str, choices=['snapshots', 'resize']) parser.add_argument('volumes', help='Volumes JSON array in a string', type=str) + def _main(): args = parser.parse_args() @@ -157,7 +160,7 @@ def _calc_requested_size(group_info, volume): def _get_volume_size(vol): volume_info_str = subprocess.check_output( - [_LVS_COMMAND, "{vg}/{lv}".format(vg=vol['vg'],lv=vol['lv']), '-v', '--units', 'b', '--reportformat', 'json'] + [_LVS_COMMAND, "{vg}/{lv}".format(vg=vol['vg'], lv=vol['lv']), '-v', '--units', 'b', '--reportformat', 'json'] ) volume_info_json = json.loads(volume_info_str) volume_info = volume_info_json['report'][0]['lv'][0] @@ -230,5 +233,6 @@ def _to_printable_volumes(volumes): } for volume in volumes } + if __name__ == '__main__': _main()