#682 Possibility to specify just one project for prune results script
Closed 4 years ago by frostyx. Opened 5 years ago by frostyx.
copr/ frostyx/copr prune-results-whitelist  into  master

@@ -28,6 +28,7 @@ 

  

  parser = argparse.ArgumentParser(

          description="Automatically prune copr result directory")

+ parser.add_argument("--path", help="Specify just one project to prune; e.g. /path/to/results/<user>/<project>")

  parser.add_argument(

          "--no-mtime-optimization",

          action='store_true',
@@ -71,17 +72,14 @@ 

  class Pruner(object):

      def __init__(self, opts, cmdline_opts=None):

          self.opts = opts

-         self.prune_days = getattr(self.opts, "prune_days", DEF_DAYS)

-         self.chroots = {}

          self.frontend_client = FrontendClient(self.opts)

+         self.prune_days = getattr(self.opts, "prune_days", DEF_DAYS)

+         self.chroots = self.fetch_chroots()

          self.mtime_optimization = True

          if cmdline_opts:

              self.mtime_optimization = not cmdline_opts.no_mtime_optimization

  

      def run(self):

-         response = self.frontend_client._post_to_frontend_repeatedly("", "chroots-prunerepo-status")

-         self.chroots = json.loads(response.content)

- 

          results_dir = self.opts.destdir

          loginfo("Pruning results dir: {} ".format(results_dir))

          user_dir_names, user_dirs = list_subdir(results_dir)
@@ -107,6 +105,10 @@ 

          loginfo("--------------------------------------------")

          loginfo("Pruning finished")

  

+     def fetch_chroots(self):

+         response = self.frontend_client._post_to_frontend_repeatedly("", "chroots-prunerepo-status")

+         return json.loads(response.content)

+ 

      def prune_project(self, project_path, username, projectdir):

          loginfo("Going to prune {}/{}".format(username, projectdir))

  
@@ -183,6 +185,10 @@ 

      config_file = os.environ.get("BACKEND_CONFIG", "/etc/copr/copr-be.conf")

      pruner = Pruner(BackendConfigReader(config_file).read(), args)

      try:

+         if args.path:

+             ownername, projectdir = args.path.rstrip("/").split("/")[-2:]

+             pruner.prune_project(args.path, ownername, projectdir)

+             return

          pruner.run()

      except Exception as e:

          logexception(e)

This change was taken from PR#679 to separate PR.

From previous discussion

@praiskup:
The non-deamon mode seems misleading .. we run it in cron.

This is already fixed

@praiskup:
This feels like a work-around, what about to re-specify the whole result-dir (the path without
ownername and projectdir), and thus guarantee that we never debug against real data? If you intend to have something like "white-list" feature (only one project affected), I'd love to see something like --whitelist or so (and the original idea --dry-run anyways).

@frostyx:
I just wasn't sure how to work with the copr_prune_results.py script, so I've added the param for convenience. I wasn't sure, whether to add --path, --project, --whitelist, etc.

I'm not terribly excited about this, per previous comment.

Metadata Update from @frostyx:
- Pull-request tagged with: needs-work

5 years ago

I don't want to force this controversial change, so I am dropping this PR.
Once I will be working on prunerepo again and find myself in a need for this feature, I will try to implement some of the @praiskup suggestions above.

Pull-Request has been closed by frostyx

4 years ago