#1003 backend: expect removed directories while trying to list them
Merged 4 years ago by msuchy. Opened 4 years ago by frostyx.
copr/ frostyx/copr fix-print-results-to-delete  into  master

@@ -19,27 +19,35 @@ 

      for ownername in os.listdir(config.destdir):

          ownerpath = os.path.join(config.destdir, ownername)

  

-         for projectname in os.listdir(ownerpath):

-             projectpath = os.path.join(ownerpath, projectname)

- 

-             # It may be a good idea, to not DoS attack the frontend

-             # Set whatever number of seconds is necessary

-             time.sleep(0)

- 

-             # If a project doesn't exist in frontend, it should be removed

-             try:

-                 client.project_proxy.get(ownername=ownername, projectname=projectname)

-             except CoprNoResultException:

-                 print(projectpath)

-                 continue

- 

-             # If a chroot is not enabled in the project, it should be removed

-             for chroot in os.listdir(projectpath):

-                 if chroot in ["srpm-builds", "modules"]:

+         try:

+             for projectname in os.listdir(ownerpath):

+                 projectpath = os.path.join(ownerpath, projectname)

+ 

+                 # I don't know how to determine whether a PR dir can be deleted or not

+                 # just ommit the logic for the time being.

+                 if ":pr:" in projectname:

                      continue

-                 if not is_outdated_to_be_deleted(get_chroot_safe(client, ownername, projectname, chroot)):

+ 

+                 # It may be a good idea, to not DoS attack the frontend

+                 # Set whatever number of seconds is necessary

+                 time.sleep(0)

+ 

+                 # If a project doesn't exist in frontend, it should be removed

+                 try:

+                     client.project_proxy.get(ownername=ownername, projectname=projectname)

+                 except CoprNoResultException:

+                     print(projectpath)

                      continue

-                 print(os.path.join(projectpath, chroot))

+ 

+                 # If a chroot is not enabled in the project, it should be removed

+                 for chroot in os.listdir(projectpath):

+                     if chroot in ["srpm-builds", "modules", "repodata", "pubkey.gpg"]:

+                         continue

+                     if not is_outdated_to_be_deleted(get_chroot_safe(client, ownername, projectname, chroot)):

+                         continue

+                     print(os.path.join(projectpath, chroot))

+         except NotADirectoryError as ex:

+             print(str(ex))

  

  

  def get_chroot_safe(client, ownername, projectname, chrootname):

While recursively walking through the results directory, expect
that some of the directories may be deleted in the meantime.

With this change, I was able to successfully finish a run of the
copr_print_results_to_delete.py script on the production instance.

+1, --ignore-space-change translation:

--- a/backend/run/copr_print_results_to_delete.py
+++ b/backend/run/copr_print_results_to_delete.py
@@ -19,6 +19,7 @@ def main():
     for ownername in os.listdir(config.destdir):
         ownerpath = os.path.join(config.destdir, ownername)

+        try:
             for projectname in os.listdir(ownerpath):
                 projectpath = os.path.join(ownerpath, projectname)

@@ -40,6 +41,8 @@ def main():
                     if not is_outdated_to_be_deleted(get_chroot_safe(client, ownername, projectname, chroot)):
                         continue
                     print(os.path.join(projectpath, chroot))
+        except NotADirectoryError as ex:
+            print(str(ex))


 def get_chroot_safe(client, ownername, projectname, chrootname):

1 new commit added

  • backend: do not suggest to remove repodata and pubkey
4 years ago

1 new commit added

  • backend: do not remove any PR directories
4 years ago

I've added two more commits to this PR. First, we definitely do not want to remove repodata directory and pubkey.gpg files, so the script should not suggest them. Also, I am not sure how to determine whether a PR directory should be kept or deleted, so I've left them untouched.

Pull-Request has been merged by msuchy

4 years ago