Skip to content
Snippets Groups Projects
Commit 65771bbb authored by Samuel GAIST's avatar Samuel GAIST Committed by Flavio TARSETTI
Browse files

[backend][management][commands] Pre-commit cleanup

parent 2e21994e
No related branches found
No related tags found
2 merge requests!347Cleanup backend,!342Django 3 migration
......@@ -25,54 +25,68 @@
# #
###############################################################################
import os
import logging
logger = logging.getLogger('beat.web')
import os
from django.core.management.base import BaseCommand
from django.conf import settings
from django.core.management.base import BaseCommand
from ...utils import cleanup_cache
from ....import __version__
logger = logging.getLogger("beat.web")
class Command(BaseCommand):
help = 'Cleans-up the cache, removing old files'
class Command(BaseCommand):
help = "Cleans-up the cache, removing old files"
def add_arguments(self, parser):
parser.add_argument('--olderthan', type=int, metavar='MINUTES',
default=0, help='All files which are older than this value ' \
'in *minutes* and are not locked or being used by active ' \
'experiments (running or scheduled) will be deleted ' \
'[default: %(default)s]')
parser.add_argument('--delete', action='store_true', default=False,
help='By default we only list cache files that will ' \
'be erased. If you pass this flag, then we really erase them')
parser.add_argument('--path', default=settings.CACHE_ROOT,
help='By default, we erase the CACHE path on your settings. Set ' \
'this flag if you want to operate on a different path ' \
'[default: %(default)s]')
parser.add_argument(
"--olderthan",
type=int,
metavar="MINUTES",
default=0,
help="All files which are older than this value "
"in *minutes* and are not locked or being used by active "
"experiments (running or scheduled) will be deleted "
"[default: %(default)s]",
)
parser.add_argument(
"--delete",
action="store_true",
default=False,
help="By default we only list cache files that will "
"be erased. If you pass this flag, then we really erase them",
)
parser.add_argument(
"--path",
default=settings.CACHE_ROOT,
help="By default, we erase the CACHE path on your settings. Set "
"this flag if you want to operate on a different path "
"[default: %(default)s]",
)
def handle(self, *ignored, **arguments):
# Setup this command's logging level
global logger
arguments['verbosity'] = int(arguments['verbosity'])
if arguments['verbosity'] >= 1:
if arguments['verbosity'] == 1: logger.setLevel(logging.INFO)
elif arguments['verbosity'] >= 2: logger.setLevel(logging.DEBUG)
deleted = cleanup_cache(arguments['path'],
age_in_minutes=arguments['olderthan'],
delete=arguments['delete'])
if not arguments['delete']:
arguments["verbosity"] = int(arguments["verbosity"])
if arguments["verbosity"] >= 1:
if arguments["verbosity"] == 1:
logger.setLevel(logging.INFO)
elif arguments["verbosity"] >= 2:
logger.setLevel(logging.DEBUG)
deleted = cleanup_cache(
arguments["path"],
age_in_minutes=arguments["olderthan"],
delete=arguments["delete"],
)
if not arguments["delete"]:
print("%d cache files can be deleted" % len(deleted))
for k in deleted:
print(os.path.join(arguments['path'], k))
print(os.path.join(arguments["path"], k))
......@@ -25,17 +25,17 @@
# #
###############################################################################
import sys
import logging
import simplejson
import socket
import sys
# Default configuration to start the state with
import psutil
import socket
import simplejson
from django.core.management.base import BaseCommand
from ...utils import setup_backend, dump_backend
from ...utils import dump_backend
from ...utils import setup_backend
logger = logging.getLogger("beat.web")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment