[Bf-extensions-cvs] [295faf9] master: tweaks to file line reading
Campbell Barton
noreply at git.blender.org
Sat Jan 31 18:51:22 CET 2015
Commit: 295faf9ec610d6e33bfecacbef1c687b891b7957
Author: Campbell Barton
Date: Sun Feb 1 04:50:35 2015 +1100
Branches: master
https://developer.blender.org/rBAC295faf9ec610d6e33bfecacbef1c687b891b7957
tweaks to file line reading
===================================================================
M ui_splash_tips/__init__.py
===================================================================
diff --git a/ui_splash_tips/__init__.py b/ui_splash_tips/__init__.py
index d8528e0..26eb22f 100644
--- a/ui_splash_tips/__init__.py
+++ b/ui_splash_tips/__init__.py
@@ -28,7 +28,7 @@ bl_info = {
}
-def find_random_line(f):
+def read_random_line(f):
import os
chunk_size = 16
@@ -36,31 +36,28 @@ def find_random_line(f):
import random
f_handle.seek(0, os.SEEK_END)
size = f_handle.tell()
- i = random.randint(1, size)
-
- # find the line
- while i != 0:
+ i = random.randint(0, size)
+ while True:
i -= chunk_size
if i < 0:
+ chunk_size += i
i = 0
f_handle.seek(i, os.SEEK_SET)
d = f_handle.read(chunk_size)
i_newline = d.rfind(b'\n')
- if i_newline == -1:
- pass
- else:
+ if i_newline != -1:
i += i_newline + 1
break
-
+ if i == 0:
+ break
f_handle.seek(i, os.SEEK_SET)
- data = f_handle.readline()
- return data
+ return f_handle.readline()
def find_random_tip():
import os
- text = find_random_line(
+ text = read_random_line(
os.path.join(os.path.dirname(__file__), "tips.txt"),
).rstrip()
@@ -69,8 +66,6 @@ def find_random_tip():
text, url = text[:url_index], text[url_index + 2:]
else:
url = b''
- print(text)
- print(url)
return text.decode("utf-8"), url.decode("utf-8")
More information about the Bf-extensions-cvs
mailing list