Compare commits

...

8 Commits

Author SHA1 Message Date
Robert Kaussow cdac34d1a5
remove unused manifest template
continuous-integration/drone/push Build is passing Details
2023-01-14 23:44:23 +01:00
Robert Kaussow e4d556d7ae
fix ci formatting
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2022-10-25 12:24:44 +02:00
Robert Kaussow 73397186b1
trigger ci
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is failing Details
2022-10-25 11:38:08 +02:00
Robert Kaussow d51b046ecb
fix ci 2022-10-25 11:34:47 +02:00
Robert Kaussow 93bceb6dff
sign drone config
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is failing Details
2022-10-25 09:53:45 +02:00
Robert Kaussow b6f998bcba
bump version to v0.2.0 2022-10-25 09:41:51 +02:00
Robert Kaussow d3e7a4ba3c
fix: skip not parsable lines in json output 2022-10-25 09:41:17 +02:00
Robert Kaussow 9ea4b33577
chore: end of the year maintenance 2021-12-21 10:29:13 +01:00
11 changed files with 291 additions and 286 deletions

View File

@ -1,150 +1,151 @@
local PythonVersion(pyversion="3.5") = {
name: "python" + std.strReplace(pyversion, '.', '') + "-pytest",
image: "python:" + pyversion,
pull: "always",
environment: {
PY_COLORS: 1
},
commands: [
"pip install -r test-requirements.txt -qq",
"pip install -qq .",
"drone-cleanup-agents --help",
],
depends_on: [
"clone",
],
local PythonVersion(pyversion='3.7') = {
name: 'python' + std.strReplace(pyversion, '.', '') + '-pytest',
image: 'python:' + pyversion,
pull: 'always',
environment: {
PY_COLORS: 1,
},
commands: [
'pip install -r test-requirements.txt -qq',
'pip install -qq .',
'drone-cleanup-agents --help',
],
depends_on: [
'clone',
],
};
local PipelineLint = {
kind: "pipeline",
name: "lint",
platform: {
os: "linux",
arch: "amd64",
},
steps: [
{
name: "flake8",
image: "python:3.7",
pull: "always",
environment: {
PY_COLORS: 1
},
commands: [
"pip install -r test-requirements.txt -qq",
"pip install -qq .",
"flake8 ./cleanupagents",
],
},
],
trigger: {
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
kind: 'pipeline',
name: 'lint',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'flake8',
image: 'python:3.10',
pull: 'always',
environment: {
PY_COLORS: 1,
},
commands: [
'pip install -r test-requirements.txt -qq',
'pip install -qq .',
'flake8 ./cleanupagents',
],
},
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
local PipelineTest = {
kind: "pipeline",
name: "test",
platform: {
os: "linux",
arch: "amd64",
},
steps: [
PythonVersion(pyversion="3.5"),
PythonVersion(pyversion="3.6"),
PythonVersion(pyversion="3.7"),
PythonVersion(pyversion="3.8"),
],
trigger: {
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
},
depends_on: [
"lint",
],
kind: 'pipeline',
name: 'test',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
PythonVersion(pyversion='3.7'),
PythonVersion(pyversion='3.8'),
PythonVersion(pyversion='3.9'),
PythonVersion(pyversion='3.10'),
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
depends_on: [
'lint',
],
};
local PipelineSecurity = {
kind: "pipeline",
name: "security",
platform: {
os: "linux",
arch: "amd64",
},
steps: [
{
name: "bandit",
image: "python:3.7",
pull: "always",
environment: {
PY_COLORS: 1
},
commands: [
"pip install -r test-requirements.txt -qq",
"pip install -qq .",
"bandit -r ./cleanupagents -x ./cleanupagents/tests",
],
},
],
depends_on: [
"test",
],
trigger: {
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
kind: 'pipeline',
name: 'security',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'bandit',
image: 'python:3.10',
pull: 'always',
environment: {
PY_COLORS: 1,
},
commands: [
'pip install -r test-requirements.txt -qq',
'pip install -qq .',
'bandit -r ./cleanupagents -x ./cleanupagents/tests',
],
},
],
depends_on: [
'test',
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
local PipelineBuild = {
kind: "pipeline",
name: "build",
platform: {
os: "linux",
arch: "amd64",
kind: 'pipeline',
name: 'build',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'build',
image: 'python:3.10',
pull: 'always',
commands: [
'python setup.py sdist bdist_wheel',
],
},
steps: [
{
name: "build",
image: "python:3.7",
pull: "always",
commands: [
"python setup.py sdist bdist_wheel",
]
},
{
name: "checksum",
image: "alpine",
pull: "always",
commands: [
"cd dist/ && sha256sum * > sha256sum.txt"
],
},
{
name: "publish-gitea",
image: "plugins/gitea-release",
pull: "always",
settings: {
base_url: "https://gitea.owncloud.services",
api_key: { "from_secret": "gitea_token"},
files: ["dist/*", "sha256sum.txt"],
title: "${DRONE_TAG}",
note: "CHANGELOG.md",
},
when: {
ref: [ "refs/tags/**" ],
},
},
],
depends_on: [
"security",
],
trigger: {
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
{
name: 'checksum',
image: 'alpine',
pull: 'always',
commands: [
'cd dist/ && sha256sum * > sha256sum.txt',
],
},
{
name: 'publish-gitea',
image: 'plugins/gitea-release',
pull: 'always',
settings: {
api_key: {
from_secret: 'gitea_token',
},
base_url: 'https://gitea.rknet.org',
files: ['dist/*', 'sha256sum.txt'],
title: '${DRONE_TAG}',
note: 'CHANGELOG.md',
},
when: {
ref: ['refs/tags/**'],
},
},
],
depends_on: [
'security',
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
[
PipelineLint,
PipelineTest,
PipelineSecurity,
PipelineBuild,
PipelineLint,
PipelineTest,
PipelineSecurity,
PipelineBuild,
]

View File

@ -7,21 +7,21 @@ platform:
arch: amd64
steps:
- name: flake8
pull: always
image: python:3.7
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- flake8 ./cleanupagents
environment:
PY_COLORS: 1
- name: flake8
pull: always
image: python:3.10
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- flake8 ./cleanupagents
environment:
PY_COLORS: 1
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
- refs/heads/master
- refs/tags/**
- refs/pull/**
---
kind: pipeline
@ -32,62 +32,62 @@ platform:
arch: amd64
steps:
- name: python35-pytest
pull: always
image: python:3.5
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python37-pytest
pull: always
image: python:3.7
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python36-pytest
pull: always
image: python:3.6
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python38-pytest
pull: always
image: python:3.8
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python37-pytest
pull: always
image: python:3.7
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python39-pytest
pull: always
image: python:3.9
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python38-pytest
pull: always
image: python:3.8
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python310-pytest
pull: always
image: python:3.10
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- drone-cleanup-agents --help
environment:
PY_COLORS: 1
depends_on:
- clone
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- lint
- lint
---
kind: pipeline
@ -98,24 +98,24 @@ platform:
arch: amd64
steps:
- name: bandit
pull: always
image: python:3.7
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- bandit -r ./cleanupagents -x ./cleanupagents/tests
environment:
PY_COLORS: 1
- name: bandit
pull: always
image: python:3.10
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- bandit -r ./cleanupagents -x ./cleanupagents/tests
environment:
PY_COLORS: 1
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- test
- test
---
kind: pipeline
@ -126,41 +126,45 @@ platform:
arch: amd64
steps:
- name: build
pull: always
image: python:3.7
commands:
- python setup.py sdist bdist_wheel
- name: build
pull: always
image: python:3.10
commands:
- python setup.py sdist bdist_wheel
- name: checksum
pull: always
image: alpine
commands:
- cd dist/ && sha256sum * > sha256sum.txt
- name: checksum
pull: always
image: alpine
commands:
- cd dist/ && sha256sum * > sha256sum.txt
- name: publish-gitea
pull: always
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://gitea.owncloud.services
files:
- dist/*
- sha256sum.txt
note: CHANGELOG.md
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
- name: publish-gitea
pull: always
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://gitea.rknet.org
files:
- dist/*
- sha256sum.txt
note: CHANGELOG.md
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- security
- security
---
kind: signature
hmac: 00fd801ccec7b1f5d7495a39ffaa5905cb34b79fa4f79d290e10ca9214c94e74
...

View File

@ -1,8 +0,0 @@
[flake8]
# Temp disable Docstring checks D101, D102, D103, D107
ignore = E501, W503, F401, N813, D101, D102, D103, D107
max-line-length = 100
inline-quotes = double
exclude = .git,.tox,__pycache__,build,dist,tests,*.pyc,*.egg-info,.cache,.eggs,env*
application-import-names = cleanupagents
format = ${cyan}%(path)s:%(row)d:%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
.drone.yml
*.tpl.md
LICENSE

20
LICENSE
View File

@ -1,9 +1,21 @@
MIT License
Copyright (c) 2019 Robert Kaussow
Copyright (c) 2022 Robert Kaussow <mail@thegeeklab.de>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -3,20 +3,16 @@
import argparse
import json
import logging
import os
import pickle # nosec
import shutil
import sys
from collections import defaultdict
from urllib.parse import urlparse
from cleanupagents import __version__
from cleanupagents.Logging import SingleLog
from cleanupagents.Utils import humanize
from cleanupagents.Utils import normalize_path
from cleanupagents.Utils import run_command
from cleanupagents.Utils import to_bool
class AgentCleanup:
@ -102,7 +98,11 @@ class AgentCleanup:
self.log.sysexit_with_message("Command error:\n{}".format(humanize(res.stdout)))
for line in res.stdout.splitlines():
obj = json.loads(line)
try:
obj = json.loads(line)
except json.decoder.JSONDecodeError:
self.logger.debug("Unable to parse line: {}".format(line))
continue
if obj["state"] == "error":
error.append(obj["name"])

View File

@ -9,7 +9,6 @@ import sys
import colorama
from pythonjsonlogger import jsonlogger
import cleanupagents.Utils
from cleanupagents.Utils import Singleton
from cleanupagents.Utils import to_bool
@ -65,11 +64,11 @@ class MultilineJsonFormatter(jsonlogger.JsonFormatter):
class Log:
def __init__(self, level=logging.WARN, name="cleanupagents", logfile="/var/log/drone-agents.log", json=False):
def __init__(self, level=logging.WARNING, name="cleanupagents", logfile="/var/log/drone-agents.log", json=False):
self.logger = logging.getLogger(name)
self.logger.setLevel(level)
self.logger.addHandler(self._get_error_handler(json=json))
self.logger.addHandler(self._get_warn_handler(json=json))
self.logger.addHandler(self._get_warning_handler(json=json))
self.logger.addHandler(self._get_info_handler(json=json))
self.logger.addHandler(self._get_critical_handler(json=json))
self.logger.addHandler(self._get_debug_handler(json=json))
@ -105,12 +104,12 @@ class Log:
return handler
def _get_warn_handler(self, json=False):
def _get_warning_handler(self, json=False):
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.WARN)
handler.addFilter(LogFilter(logging.WARN))
handler.setLevel(logging.WARNING)
handler.addFilter(LogFilter(logging.WARNING))
handler.setFormatter(MultilineFormatter(
self.warn(CONSOLE_FORMAT.format(colorama.Fore.YELLOW, colorama.Style.RESET_ALL))))
self.warning(CONSOLE_FORMAT.format(colorama.Fore.YELLOW, colorama.Style.RESET_ALL))))
if json:
handler.setFormatter(MultilineJsonFormatter(JSON_FORMAT))
@ -168,8 +167,8 @@ class Log:
"""Format error messages and return string."""
return msg
def warn(self, msg):
"""Format warn messages and return string."""
def warning(self, msg):
"""Format warning messages and return string."""
return msg
def info(self, msg):

View File

@ -4,7 +4,6 @@
import os
import shlex
import subprocess # nosec
import sys
from distutils.util import strtobool

View File

@ -2,8 +2,8 @@
__author__ = "Robert Kaussow"
__project__ = "drone-cleanup-agents"
__version__ = "0.1.3"
__version__ = "0.2.0"
__license__ = "MIT"
__maintainer__ = "Robert Kaussow"
__email__ = "rkaussow@owncloud.com"
__url__ = "https://gitea.owncloud.services/internal/drone-cleanup-agents"
__email__ = "mail@thegeeklab.de"
__url__ = "https://gitea.rknet.org/xoxys/drone-cleanup-agents"

View File

@ -1,24 +0,0 @@
image: internal/drone-cleanup-agents:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
- image: internal/drone-cleanup-agents:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
platform:
architecture: amd64
os: linux
- image: internal/drone-cleanup-agents:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
platform:
architecture: arm64
os: linux
variant: v8
- image: internal/drone-cleanup-agents:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm
platform:
architecture: arm
os: linux
variant: v7

View File

@ -18,3 +18,22 @@ filterwarnings =
ignore::FutureWarning
ignore:.*collections.*:DeprecationWarning
ignore:.*pep8.*:FutureWarning
[flake8]
# Explanation of errors
#
# D100: Missing docstring in public module
# D101: Missing docstring in public class
# D102: Missing docstring in public method
# D103: Missing docstring in public function
# D105: Missing docstring in magic method
# D107: Missing docstring in __init__
# D202: No blank lines allowed after function docstring
# G001: Logging statements should not use string.format() for their first argument
# G004: Logging statements should not use f"..." for their first argument
# W503: Line break occurred before a binary operator
ignore = D100, D101, D102, D103, D105, D107, D202, G001, G004, W503
max-line-length = 200
inline-quotes = double
exclude = .git,.tox,__pycache__,build,dist,tests,*.pyc,*.egg-info,.cache,.eggs,env*
application-import-names = cleanupagents