Skip to content

Commit

Permalink
Update: pre-commit Python
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
  • Loading branch information
nlamirault committed Mar 7, 2021
1 parent deb218e commit 1294fee
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ repos:
# name: "Check YAML files"
# - id: end-of-file-fixer
# - id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
36 changes: 21 additions & 15 deletions hack/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,40 @@
import logging
import os
from os import path
import shutil
import shutil
import zipfile

import coloredlogs
import requests


MIXINS_VERSION="v0.2.0"
MIXIN_ARCHIVE="monitoring-mixins-%s.zip" % MIXINS_VERSION
MIXIN_URL="https://github.com/nlamirault/monitoring-mixins/releases/download/%s/%s" % (
MIXINS_VERSION, MIXIN_ARCHIVE
MIXINS_VERSION = "v0.2.0"
MIXIN_ARCHIVE = "monitoring-mixins-%s.zip" % MIXINS_VERSION
MIXIN_URL = (
"https://github.com/nlamirault/monitoring-mixins/releases/download/%s/%s"
% (MIXINS_VERSION, MIXIN_ARCHIVE)
)
MIXIN_DIRECTORY="monitoring-mixins"
MIXIN_DIRECTORY = "monitoring-mixins"


logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG')
coloredlogs.install(level="DEBUG")


def escape(s):
return s.replace("{{", "{{`{{").replace("}}", "}}`}}").replace("{{`{{", "{{`{{`}}").replace("}}`}}", "{{`}}`}}")
return (
s.replace("{{", "{{`{{")
.replace("}}", "}}`}}")
.replace("{{`{{", "{{`{{`}}")
.replace("}}`}}", "{{`}}`}}")
)


def download(url, filename):
logger.info("Download Mixin : %s", url)
r = requests.get(url)
with open(filename,'wb') as f:
f.write(r.content)
with open(filename, "wb") as f:
f.write(r.content)


def manage_mixin(mixin_directory, mixin):
Expand All @@ -66,11 +72,11 @@ def manage_mixin(mixin_directory, mixin):
fout.write(escape(line))
else:
logger.warning("Mixin chart not found")


def main(url, filename, mixin_directory, chart):
download(url, filename)
with zipfile.ZipFile(filename,"r") as zf:
with zipfile.ZipFile(filename, "r") as zf:
zf.extractall()
logger.info("Monitoring mixins")
for mixin in os.listdir(path=mixin_directory):
Expand All @@ -80,8 +86,8 @@ def main(url, filename, mixin_directory, chart):
shutil.rmtree(mixin_directory)


if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('chart', type=str, help='Chart to update')
parser.add_argument("chart", type=str, help="Chart to update")
args = parser.parse_args()
main(MIXIN_URL, MIXIN_ARCHIVE, MIXIN_DIRECTORY, args.chart)
main(MIXIN_URL, MIXIN_ARCHIVE, MIXIN_DIRECTORY, args.chart)
167 changes: 166 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1294fee

Please sign in to comment.