Commit fef02529 authored by Julien Muchembled's avatar Julien Muchembled

prune: add support for new name of signature files

parent f97375bd
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import sys import sys
import glob import glob
import os import os
from fnmatch import fnmatchcase
import six.moves.configparser as configparser import six.moves.configparser as configparser
from slapos.cli.command import check_root_user from slapos.cli.command import check_root_user
...@@ -92,7 +93,8 @@ def _prune( ...@@ -92,7 +93,8 @@ def _prune(
logger, software_root, shared_root, ignored_shared_parts) logger, software_root, shared_root, ignored_shared_parts)
# recursively look in instance # recursively look in instance
signatures.update(getUsageSignaturesFromSubInstance(logger, instance_root, set([]))) signatures.update(getUsageSignaturesFromSubInstance(
logger, instance_root, set()))
for shared_part in glob.glob(os.path.join(shared_root, '*', '*')): for shared_part in glob.glob(os.path.join(shared_root, '*', '*')):
if shared_part not in ignored_shared_parts: if shared_part not in ignored_shared_parts:
...@@ -112,7 +114,7 @@ def _prune( ...@@ -112,7 +114,7 @@ def _prune(
def _prune_loop(logger, shared_root, software_root, instance_root, dry_run): def _prune_loop(logger, shared_root, software_root, instance_root, dry_run):
ignored_shared_parts = set([]) ignored_shared_parts = set()
while True: while True:
pruned = list( pruned = list(
_prune( _prune(
...@@ -123,9 +125,9 @@ def _prune_loop(logger, shared_root, software_root, instance_root, dry_run): ...@@ -123,9 +125,9 @@ def _prune_loop(logger, shared_root, software_root, instance_root, dry_run):
ignored_shared_parts, ignored_shared_parts,
dry_run, dry_run,
)) ))
ignored_shared_parts.update(pruned)
if not pruned: if not pruned:
break break
ignored_shared_parts.update(pruned)
def do_prune(logger, options, dry_run): def do_prune(logger, options, dry_run):
...@@ -219,14 +221,12 @@ def readSlaposCfg(logger, path): ...@@ -219,14 +221,12 @@ def readSlaposCfg(logger, path):
def getUsageSignatureFromSoftwareAndSharedPart( def getUsageSignatureFromSoftwareAndSharedPart(
logger, software_root, shared_root, ignored_shared_parts=None): logger, software_root, shared_root, ignored_shared_parts=()):
"""Look in all softwares and shared parts to collect the signatures """Look in all softwares and shared parts to collect the signatures
that are used. that are used.
`ignored_shared_parts` is useful during dry-run, we want to ignore `ignored_shared_parts` is useful during dry-run, we want to ignore
already the parts that we are about to delete. already the parts that we are about to delete.
""" """
if ignored_shared_parts is None:
ignored_shared_parts = set([])
signatures = {} signatures = {}
for installed_cfg in glob.glob(os.path.join(software_root, '*', for installed_cfg in glob.glob(os.path.join(software_root, '*',
'.installed.cfg')): '.installed.cfg')):
...@@ -239,10 +239,12 @@ def getUsageSignatureFromSoftwareAndSharedPart( ...@@ -239,10 +239,12 @@ def getUsageSignatureFromSoftwareAndSharedPart(
except UnicodeDecodeError: except UnicodeDecodeError:
logger.debug("Skipping script %s that could not be decoded", script) logger.debug("Skipping script %s that could not be decoded", script)
if shared_root: if shared_root:
for shared_signature in glob.glob(os.path.join(shared_root, '*', '*', for shared_part in glob.glob(os.path.join(shared_root, '*', '*')):
'.*signature')): if shared_part not in ignored_shared_parts:
if not any(shared_signature.startswith(ignored_shared_part) for x in os.listdir(shared_part):
for ignored_shared_part in ignored_shared_parts): if x == '.buildout-shared.json' or \
with open(shared_signature) as f: fnmatchcase(x, '.*signature'):
signatures[shared_signature] = f.read() x = os.path.join(shared_part, x)
with open(x) as f:
signatures[x] = f.read()
return signatures return signatures
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment