[geany/geany-osx] ff7c35: Add a script that can be used to remove files which are not symlinked

Jiří Techet git-noreply at xxxxx
Thu Oct 24 20:01:50 UTC 2019


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Thu, 24 Oct 2019 20:01:50 UTC
Commit:      ff7c35fd0fb105bf93d66eed36ef9ee573fa6739
             https://github.com/geany/geany-osx/commit/ff7c35fd0fb105bf93d66eed36ef9ee573fa6739

Log Message:
-----------
Add a script that can be used to remove files which are not symlinked

This is useful for deleting icons in theme directories we don't need
where we want to be sure they aren't symlinked from other directories of
the theme.


Modified Paths:
--------------
    utils/remove_nonlinked.py

Modified: utils/remove_nonlinked.py
50 lines changed, 50 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import os, sys
+from pathlib import Path
+
+
+if len(sys.argv) != 3:
+    print('Error: Incorrect number of arguments of the script (expected 2)')
+    sys.exit(1)
+
+rm_dir = sys.argv[1]
+all_dir = sys.argv[2]
+
+if not os.path.isdir(rm_dir) or not os.path.isdir(rm_dir):
+    print('Error: Both arguments of the script have to be directories')
+    sys.exit(1)
+
+rm_dir = str(Path(rm_dir).resolve())
+all_dir = str(Path(all_dir).resolve())
+
+print('The script DELETES ALL FILES from "' + rm_dir + '" which are not symlinked from "' + all_dir + '"')
+resp = input('Are you sure you want to continue? [Y/n]: ')
+if resp != 'Y':
+    sys.exit(1)
+
+if not rm_dir.endswith('/'):
+    rm_dir = rm_dir + '/'
+
+for i in range(5):
+    symlink_targets = set()
+    for filename in Path(all_dir).glob('**/*'):
+        if os.path.islink(filename):
+            target = os.readlink(filename)
+            if not os.path.isabs(target):
+                target = os.path.join(os.path.dirname(filename), target)
+            symlink_targets.add(os.path.normpath(target))
+
+    for filename in Path(rm_dir).glob('**/*'):
+        if not str(filename) in symlink_targets:
+            try:
+                os.remove(filename)
+            except:
+                pass
+
+for filename in Path(rm_dir).glob('**/*'):
+    if os.path.isdir(filename):
+        try:
+            os.rmdir(filename)
+        except:
+            pass



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list