Browse Source

check images even for python 3

rachels 3 years ago
parent
commit
606f85474b
4 changed files with 118 additions and 45 deletions
  1. 26 1
      checkpics.bat
  2. 0 44
      tools/check_images.py
  3. 45 0
      tools/check_images2.py
  4. 47 0
      tools/check_images3.py

+ 26 - 1
checkpics.bat

@@ -1 +1,26 @@
-python tools/check_images.py > missing_pictures.txt
+@echo off
+set "$py=0"
+call:construct
+
+for /f "delims=" %%a in ('python #.py ^| findstr "2"') do set "$py=2"
+for /f "delims=" %%a in ('python #.py ^| findstr "3"') do set "$py=3"
+del #.py
+goto:%$py%
+
+echo python is not installed or python's path Path is not in the %%$path%% env. var
+exit/b
+
+:2
+python tools/check_images2.py > missing_pictures.txt
+
+exit/b
+
+:3
+python tools/check_images3.py > missing_pictures.txt
+
+exit/b
+
+:construct
+echo import sys; print('{0[0]}.{0[1]}'.format(sys.version_info^)^) >#.py
+
+

+ 0 - 44
tools/check_images.py

@@ -1,44 +0,0 @@
-#!/usr/bin/env python
-
-import io
-import os
-import re
-
-#path = os.getcwd()
-#print path
-
-startpattern = """images/"""
-imgFormats = ['jpg','gif','png','mp4']
-
-infile = io.open('glife.txt',mode='r',encoding='utf-16')
-lines = infile.readlines()
-
-images = []
-
-for name in os.listdir("locations"):
-	path = os.path.join("locations", name)
-	if os.path.isdir(path):
-		continue
-		# skip directories
-	else:
-		ifile = io.open(
-			os.path.join("locations", name),
-			mode='rt',
-			encoding='utf-8'
-		)
-		text = ifile.read()
-		for match in re.finditer(r"images.+?[.](gif|jpg|png|mp4)", text, flags=re.U):
-			imgfile = match.group().encode("utf-8")
-			randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
-			if randmatch != None:
-				for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
-					images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
-			else:
-				images.append(imgfile)
-		
-		ifile.close()
-
-
-for image in images:
-    if not re.search(r"[<$]", image) and not os.path.isfile(image):
-        print "Image not found:", image

+ 45 - 0
tools/check_images2.py

@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import io
+import os
+import re
+import sys
+
+#path = os.getcwd()
+#print path
+
+startpattern = """images/"""
+imgFormats = ['jpg','gif','png','mp4']
+
+infile = io.open('glife.txt',mode='r',encoding='utf-16')
+lines = infile.readlines()
+
+images = []
+
+for name in os.listdir("locations"):
+    path = os.path.join("locations", name)
+    if os.path.isdir(path):
+        continue
+        # skip directories
+    else:
+        ifile = io.open(
+            os.path.join("locations", name),
+            mode='rt',
+            encoding='utf-8'
+        )
+        text = ifile.read()
+        for match in re.finditer(r"images.+?[.](gif|jpg|png|mp4)", text, flags=re.U):
+            imgfile = match.group().encode("utf-8")
+            randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
+            if randmatch != None:
+                for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
+                    images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
+            else:
+                images.append(imgfile)
+        
+        ifile.close()
+
+for image in images:
+    if not re.search(r"[<$]", image) and not os.path.isfile(image):
+        print "Image not found:", image
+

+ 47 - 0
tools/check_images3.py

@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+import io
+import os
+import re
+import sys
+from sys import version_info
+
+#path = os.getcwd()
+#print path
+
+startpattern = """images/"""
+imgFormats = ['jpg','gif','png','mp4']
+
+infile = io.open('glife.txt',mode='r',encoding='utf-16')
+lines = infile.readlines()
+
+images = []
+
+for name in os.listdir("locations"):
+    path = os.path.join("locations", name)
+    if os.path.isdir(path):
+        continue
+        # skip directories
+    else:
+        ifile = io.open(
+            os.path.join("locations", name),
+            mode='rt',
+            encoding='utf-8'
+        )
+        text = ifile.read()
+        for match in re.finditer(r"images.+?[.](gif|jpg|png|mp4)", text, flags=re.U):
+            imgfile = match.group().encode("utf-8")
+            imgfile = imgfile.decode('utf-8')
+            randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
+            if randmatch != None:
+                for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
+                    images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
+            else:
+                images.append(imgfile)
+        
+        ifile.close()
+
+for image in images:
+    if not re.search(r"[<$]", image) and not os.path.isfile(image):
+        print ("Image not found:", image)
+