]> git.phdru.name Git - ppu.git/commitdiff
Split test_remove_old_files.py into find_in_path.py
authorOleg Broytman <phd@phdru.name>
Sun, 30 Apr 2017 16:53:07 +0000 (19:53 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 30 Apr 2017 17:16:04 +0000 (20:16 +0300)
tests/find_in_path.py [new file with mode: 0644]
tests/test_remove_old_files.py

diff --git a/tests/find_in_path.py b/tests/find_in_path.py
new file mode 100644 (file)
index 0000000..4d00613
--- /dev/null
@@ -0,0 +1,9 @@
+import os
+
+
+def find_in_path(name):
+    for path in os.environ["PATH"].split(os.pathsep):
+        path = path.strip('"')
+        test_prog_path = os.path.join(path, name)
+        if os.path.exists(test_prog_path):
+            return test_prog_path
index ea36506dd4d4198acc97dd31abd7e8fae64581a6..95dd98cb46111219b7f7df24f43d9a39bdd09e64 100755 (executable)
@@ -6,17 +6,14 @@ import shutil
 import subprocess
 import sys
 from tempfile import mkdtemp
+from find_in_path import find_in_path
 
 
 tmp_dir = None
 old_time = time() - 1000 * 24 * 3600  # 1000 days ago
 
-for path in os.environ["PATH"].split(os.pathsep):
-    path = path.strip('"')
-    test_prog_path = os.path.join(path, 'remove-old-files.py')
-    if os.path.exists(test_prog_path):
-        break
-else:
+test_prog_path = find_in_path('remove-old-files.py')
+if not test_prog_path:
     sys.exit("Cannot find remove-old-files.py in %s" % os.environ["PATH"])