mirror of
https://github.com/openwrt/openwrt.git
synced 2025-01-30 16:14:12 +00:00
scripts: add clean of build dir to dl_cleanup script
Improve dl_cleanup by adding an option to also clean the build directory related to the downloaded package. The script will check every directory in build_dir/ and check if any old package is present there. If outdated package are found, the old one are cleared leaving only the last one. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
This commit is contained in:
parent
69760d415d
commit
cf2c9498be
@ -13,6 +13,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import getopt
|
import getopt
|
||||||
|
import shutil
|
||||||
|
|
||||||
# Commandline options
|
# Commandline options
|
||||||
opt_dryrun = False
|
opt_dryrun = False
|
||||||
@ -140,15 +141,18 @@ class EntryParseError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class Entry:
|
class Entry:
|
||||||
def __init__(self, directory, filename):
|
def __init__(self, directory, builddir, filename):
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.builddir = builddir
|
||||||
self.progname = ""
|
self.progname = ""
|
||||||
self.fileext = ""
|
self.fileext = ""
|
||||||
|
self.filenoext = ""
|
||||||
|
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
if filename.endswith(ext):
|
if filename.endswith(ext):
|
||||||
filename = filename[0 : 0 - len(ext)]
|
filename = filename[0 : 0 - len(ext)]
|
||||||
|
self.filenoext = filename
|
||||||
self.fileext = ext
|
self.fileext = ext
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -168,12 +172,27 @@ class Entry:
|
|||||||
def getPath(self):
|
def getPath(self):
|
||||||
return (self.directory + "/" + self.filename).replace("//", "/")
|
return (self.directory + "/" + self.filename).replace("//", "/")
|
||||||
|
|
||||||
|
def getBuildPaths(self):
|
||||||
|
paths = []
|
||||||
|
for subdir in os.scandir(self.builddir):
|
||||||
|
package_build_dir = os.path.join(subdir.path, self.filenoext)
|
||||||
|
if os.path.exists(package_build_dir):
|
||||||
|
paths.append(package_build_dir)
|
||||||
|
return paths
|
||||||
|
|
||||||
def deleteFile(self):
|
def deleteFile(self):
|
||||||
path = self.getPath()
|
path = self.getPath()
|
||||||
print("Deleting", path)
|
print("Deleting", path)
|
||||||
if not opt_dryrun:
|
if not opt_dryrun:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|
||||||
|
def deleteBuildDir(self):
|
||||||
|
paths = self.getBuildPaths()
|
||||||
|
for path in paths:
|
||||||
|
print("Deleting BuildDir", path)
|
||||||
|
if not opt_dryrun:
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def __ge__(self, y):
|
def __ge__(self, y):
|
||||||
return self.version >= y.version
|
return self.version >= y.version
|
||||||
|
|
||||||
@ -188,6 +207,9 @@ def usage():
|
|||||||
print(
|
print(
|
||||||
" -D|--download-dir Provide path to dl dir to clean also the build directory"
|
" -D|--download-dir Provide path to dl dir to clean also the build directory"
|
||||||
)
|
)
|
||||||
|
print(
|
||||||
|
" -b|--build-dir Provide path to build dir to clean also the build directory"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
@ -196,13 +218,14 @@ def main(argv):
|
|||||||
try:
|
try:
|
||||||
(opts, args) = getopt.getopt(
|
(opts, args) = getopt.getopt(
|
||||||
argv[1:],
|
argv[1:],
|
||||||
"hdBwD:",
|
"hdBwDb:",
|
||||||
[
|
[
|
||||||
"help",
|
"help",
|
||||||
"dry-run",
|
"dry-run",
|
||||||
"show-blacklist",
|
"show-blacklist",
|
||||||
"whitelist=",
|
"whitelist=",
|
||||||
"download-dir=",
|
"download-dir=",
|
||||||
|
"build-dir=",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
except getopt.GetoptError as e:
|
except getopt.GetoptError as e:
|
||||||
@ -210,6 +233,7 @@ def main(argv):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
directory = "dl/"
|
directory = "dl/"
|
||||||
|
builddir = "build_dir/"
|
||||||
|
|
||||||
for (o, v) in opts:
|
for (o, v) in opts:
|
||||||
if o in ("-h", "--help"):
|
if o in ("-h", "--help"):
|
||||||
@ -235,11 +259,17 @@ def main(argv):
|
|||||||
return 0
|
return 0
|
||||||
if o in ("-D", "--download-dir"):
|
if o in ("-D", "--download-dir"):
|
||||||
directory = v
|
directory = v
|
||||||
|
if o in ("-b", "--build-dir"):
|
||||||
|
builddir = v
|
||||||
|
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
print("Can't find dl path", directory)
|
print("Can't find dl path", directory)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
if not os.path.exists(builddir):
|
||||||
|
print("Can't find dl path", builddir)
|
||||||
|
return 1
|
||||||
|
|
||||||
# Create a directory listing and parse the file names.
|
# Create a directory listing and parse the file names.
|
||||||
entries = []
|
entries = []
|
||||||
for filename in os.listdir(directory):
|
for filename in os.listdir(directory):
|
||||||
@ -252,7 +282,7 @@ def main(argv):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
entries.append(Entry(directory, filename))
|
entries.append(Entry(directory, builddir, filename))
|
||||||
except EntryParseError as e:
|
except EntryParseError as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -277,6 +307,8 @@ def main(argv):
|
|||||||
for version in versions:
|
for version in versions:
|
||||||
if version is not lastVersion:
|
if version is not lastVersion:
|
||||||
version.deleteFile()
|
version.deleteFile()
|
||||||
|
if builddir:
|
||||||
|
version.deleteBuildDir()
|
||||||
if opt_dryrun:
|
if opt_dryrun:
|
||||||
print("Keeping", lastVersion.getPath())
|
print("Keeping", lastVersion.getPath())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user