Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/labels/issue_labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Add/remove 'critical' label if issue contains the words 'urgent' or 'critical'
critical:
- '(critical|urgent)'

# Add/remove 'bug' label if issue contains the words 'bug'
bug:
- '(bug)'

# Add/remove 'feature' label if issue contains the words 'feature'
feature:
- '(feature)'
30 changes: 30 additions & 0 deletions .github/labels/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# configuration spec at https://github.com/actions/labeler/blob/master/README.md
sh/docs:
- CHANGELOG.md
- CONTRIBUTING.md
- LICENSE
- README.md
sh/tests:
- tests/*
- tox.ini
sh/code:
- data/*
- asserts/*
- shconfparser
sh/ci:
- .github/workflows/*
- .github/labels/*
- .travis.yml
- .coveralls.yml
sh/settings:
- setup.py
- tox.ini
- .gitignore
- .python-version
sh/pip:
- requirements.txt
- requirements_dev.txt
- requirements_dev27.txt
- Pipfile
- Pipfile.lock
49 changes: 49 additions & 0 deletions .github/labels/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# Default GitHub labels
- color: d73a4a
name: bug
description: Something isn't working
- color: cfd3d7
name: duplicate
description: This issue or pull request already exists
- color: a2eeef
name: enhancement
description: New feature or request
- color: 7057ff
name: good first issue
description: Good for newcomers
- color: 008672
name: help wanted
description: Extra attention is needed
- color: e4e669
name: invalid
description: This doesn't seem right
- color: d876e3
name: question
description: Further information is requested
- color: ffffff
name: wontfix
description: This will not be worked on

# Labels specific to shconfparser
- color: 0366d6
name: sh/wip
description: Work in progress
- color: 0366d6
name: sh/docs
description: Improvements or additions to documentation
- color: 0366d6
name: sh/tests
description: Everything related to molecule tests and linters
- color: 0366d6
name: sh/code
description: Bots, bots everywhere
- color: 0366d6
name: sh/ci
description: Ansible variables used in role
- color: 0366d6
name: sh/settings
description: Logic behind ansible role
- color: 0366d6
name: sh/pip
description: Templates
15 changes: 15 additions & 0 deletions .github/workflows/issue_labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Issue Labeler"
on:
issues:
types: [opened, edited]

jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v2.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labels/issue_labeler.yml
# not-before: 2020-01-15T02:54:32Z
enable-versioned-regex: 0
13 changes: 13 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Pull request labeler
on:
schedule:
- cron: '*/15 * * * *'
jobs:
labeler:
runs-on: ubuntu-latest
steps:
- uses: paulfantom/periodic-labeler@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
17 changes: 17 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Sync labels in the declarative way
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1.0.0
- uses: micnncim/action-label-syncer@v0.3.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
with:
manifest: .github/labels/labels.yml
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build python package
run: |
python setup.py sdist bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
verbose: true
43 changes: 43 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "pytest"

on:
push:
branches:
- '**'
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.9]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements_dev.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -v --cov=shconfparser
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
31 changes: 31 additions & 0 deletions .github/workflows/pytest_27.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "pytest 2.7.x"

on:
push:
branches:
- '**'
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [2.7]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements_dev27.txt
- name: Test with pytest
run: |
pytest -v --cov=shconfparser
14 changes: 14 additions & 0 deletions .github/workflows/remove_labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Remove All Labels

on:
pull_request:
types: [closed]

jobs:
remove_labels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rogerluan/label-remover@v1.0.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Editor specific

.idea
.idea/
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Empty file added CHANGELOG.md
Empty file.
Empty file added CONTRIBUTING.md
Empty file.
2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ pytest-cov==2.8.1
pytest==5.3.0
coveralls==1.5.1
tox==3.7.0
wheel
flake8

29 changes: 15 additions & 14 deletions shconfparser/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,47 @@ def validate(self, data, dtype=OrderedDict):
"""
if data == None:
return None

if type(data) != dtype:
return None

return True

def get_pattern(self, pattern, strip=True):
"""
This method converts the given string to regex pattern
"""
if type(pattern) == re.Pattern:
return pattern
try:
if type(pattern) == re.Pattern:
return pattern
except AttributeError:
if type(pattern) != str:
return pattern

if strip and type(pattern) == str:
pattern = pattern.strip()

return re.compile(pattern)


def search_in_tree(self, pattern, data=None):
if not self.validate(data):
return None

p = self.get_pattern(pattern)
for key in data.keys():
if p.match(key):
return key
res = p.match(key)
if res:
return res
return None


def search_all_in_tree(self, pattern, data=None):
if not self.validate(data):
return None

p = self.get_pattern(pattern)
match = OrderedDict()
for key in data.keys():
if p.match(key):
match[key] = key

res = p.match(key)
if res:
match[res] = key
return match if len(match) else None

def search_in_tree_level(self, pattern, data=None, level=0):
Expand All @@ -75,7 +76,7 @@ def search_in_tree_level(self, pattern, data=None, level=0):
return None

def search_in_table(self, pattern, data=None, header_column=None):
if not self.validate(data):
if not self.validate(data, dtype=list):
return None

p = self.get_pattern(pattern)
Expand All @@ -84,13 +85,13 @@ def search_in_table(self, pattern, data=None, header_column=None):
return each_row

def search_all_in_table(self, pattern, data=None, header_column=None):
if not self.validate(data):
if not self.validate(data, dtype=list):
return None

p = self.get_pattern(pattern)
match = []
match = []
for each_row in data:
if p.match(each_row[header_column]):
match.append(each_row)

return match if len(match) else None
Loading