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
24 def get_dat_file_size(bbs_type):
25 """Returns size of dat file"""
26 dat_path = misc.get_thread_dat_path(bbs_type)
27 if not os.path.exists(dat_path):
30 return os.path.getsize(dat_path)
32 def get_dat_line_count(bbs_type):
33 """Returns the number of line of a dat file specified by bbs, board
42 dat_path = misc.get_thread_dat_path(bbs_type)
43 if not os.path.exists(dat_path):
46 f = fileinput.FileInput(dat_path)
50 def get_title_from_dat(bbs_type):
51 """Returns thread title in dat file
59 If failed, return None
61 dat_path = misc.get_thread_dat_path(bbs_type)
62 if not os.path.exists(dat_path):
65 f = open(dat_path, "r")
68 return bbs_type.get_title_from_dat(line)
72 def load_dat(bbs_type, func):
73 """Loads entire dat and invokes func per one res
81 func: is invoked per one res
82 format of user function is:
84 where line is raw body of the res
86 dat_path = misc.get_thread_dat_path(bbs_type)
87 if not os.path.exists(dat_path):
90 f = fileinput.FileInput(dat_path)
95 def load_dat_partly(bbs_type, func, resnum):
97 similar to load_dat, but load_dat_partly does not load entire dat.
105 func: invoked per one res
107 resnum: load downward resnum
109 dat_path = misc.get_thread_dat_path(bbs_type)
110 if not os.path.exists(dat_path):
113 f = fileinput.FileInput(dat_path)