1 # Copyright (C) 2006 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 REG_EXPR_TITLE = re.compile(".*<>.*<>.*<>.*<>(.*)")
26 REG_EXPR_ELEM = re.compile( \
27 "(?P<name>.*)<>(?P<mail>.*)<>(?P<date>.*)<>(?P<msg>.*)<>")
29 def get_dat_file_size(bbs, board, thread):
30 """Returns size of dat file"""
31 dat_path = misc.get_thread_dat_path(bbs, board, thread)
32 if not os.path.exists(dat_path):
35 return os.path.getsize(dat_path)
37 def get_dat_line_count(bbs, board, thread):
38 """Returns the number of line of a dat file specified by bbs, board
47 dat_path = misc.get_thread_dat_path(bbs, board, thread)
48 if not os.path.exists(dat_path):
51 f = fileinput.FileInput(dat_path)
55 def get_title_from_dat(bbs, board, thread):
56 """Returns thread title in dat file
64 If failed, return None
66 dat_path = misc.get_thread_dat_path(bbs, board, thread)
67 if not os.path.exists(dat_path):
70 f = open(dat_path, "r")
74 m = REG_EXPR_TITLE.match(line.decode("cp932", "replace"))
80 def split_line_to_elems(line, func):
81 """Splits a line to elements and invokes func
83 line: represents one res
85 func: is invoked after splitting
86 format of user functon is:
87 def some_func(name, mail, date, msg):
88 where parameters represent corresponding elements of the res
90 m = REG_EXPR_ELEM.match(line)
92 name = m.group("name")
93 mail = m.group("mail")
94 date = m.group("date")
96 func(name, mail, date, msg)
98 def load_dat(bbs, board, thread, func):
99 """Loads entire dat and invokes func per one res
107 func: is invoked per one res
108 format of user function is:
110 where line is raw body of the res
112 dat_path = misc.get_thread_dat_path(bbs, board, thread)
113 if not os.path.exists(dat_path):
116 f = fileinput.FileInput(dat_path)
121 def load_dat_partly(bbs, board, thread, func, resnum):
123 similar to load_dat, but load_dat_partly does not load entire dat.
131 func: invoked per one res
133 resnum: load downward resnum
135 dat_path = misc.get_thread_dat_path(bbs, board, thread)
136 if not os.path.exists(dat_path):
139 f = fileinput.FileInput(dat_path)