yocto-autobuilder-helper/janitor/clobberdir
Richard Purdie 8702fdbb72 Clarify license and copyright information
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2022-05-17 10:29:45 +01:00

1.5 KiB
Executable File

#!/usr/bin/env python3

Copyright Linux Foundation, Richard Purdie

SPDX-License-Identifer: GPL-2.0-only

Delete a directory using the ionice backgrounded command

Called with $1 - Our config file

$2 - The directory to delete

import os import sys import subprocess import errno import time import random

sys.path.append(os.path.join(os.path.dirname(file), '..', 'scripts'))

import utils

ourconfig = utils.loadconfig()

def mkdir(path): try: os.makedirs(path) except OSError as e: if e.errno != errno.EEXIST: # Do not complain if the directory exists raise e

if len(sys.argv) != 2: print("Incorrect number of parameters, please call as %s " % sys.argv[0]) sys.exit(1)

clobberdir = sys.argv[1]

if clobberdir == "/" or clobberdir == ".": print("Deleting %s is probably not what you want" % clobberdir) sys.exit(1)

if "TRASH_DIR" not in ourconfig: print("Please set TRASH_DIR in the configuration file") sys.exit(1)

trashdir = utils.getconfig("TRASH_DIR", ourconfig)

for x in [clobberdir]: if os.path.exists(x) and os.path.exists(trashdir): if (os.stat(trashdir).st_dev == os.stat(x).st_dev): trashdest = trashdir + "/" + str(int(time.time())) + '-' + str(random.randrange(100, 100000, 2)) mkdir(trashdest) subprocess.check_call(['mv', x, trashdest]) else: subprocess.check_call(['rm', "-rf", x])