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_HTTPDATE = re.compile("((?:Mon)|(?:Tue)|(?:Wed)|(?:Thu)|(?:Fri)|(?:Sat)|(?:Sun)), (\d{2}) ((?:Jan)|(?:Feb)|(?:Mar)|(?:Apr)|(?:May)|(?:Jun)|(?:Jul)|(?:Aug)|(?:Sep)|(?:Oct)|(?:Nov)|(?:Dec)) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT")
26 WDAY_DICT = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6}
27 MON_DICT = {"Jan":1, "Feb":2, "Mar":3, "Apr":4, "May":5, "Jun":6, "Jul":7,
28 "Aug":8, "Sep":9, "Oct":10, "Nov":11, "Dec":12}
30 def get_logs_dir_path():
31 return os.path.join(config.get_config_dir_path(), "logs")
33 def get_board_base_url(bbs, board):
35 None: this function uses brdlist.get function, so brdlist.read function
36 should have been called before this function is called
38 # if parameter is empty, raise ValueError
39 if not bbs or not board:
40 raise ValueError, "parameter must not be empty"
42 return "http://" + brdlist.get(bbs, board, "host") + "/" + board + "/"
44 def get_thread_dat_url(bbs, board, thread):
45 """Returns thread dat url"""
47 # if parameter is empty, raise ValueError
48 if not bbs or not board or not thread:
49 raise ValueError, "parameter must not be empty"
51 return get_board_base_url(bbs, board) + "dat/" + thread + ".dat"
53 def get_thread_dat_path(bbs, board, thread):
54 """Returns thread dat file path
63 # if parameter is empty, raise ValueError
64 if not bbs or not board or not thread:
65 raise ValueError, "parameter must not be empty"
67 return os.path.join(get_board_dir_path(bbs, board), thread + ".dat")
69 def get_board_subjecttxt_url(bbs, board):
70 """Returns subject.txt file url
77 # if parameter is empty, raise ValueError
78 if not bbs or not board:
79 raise ValueError, "parameter must not be empty"
81 return get_board_base_url(bbs, board) + "subject.txt"
83 def get_board_subjecttxt_path(bbs, board):
84 """Returns subject.txt file path
91 # if parameter is empty, raise ValueError
92 if not bbs or not board:
93 raise ValueError, "parameter must not be empty"
95 return os.path.join(get_logs_dir_path(), bbs, board, "subject.txt")
97 def get_board_idx_path(bbs, board):
98 """Returns board idx file path
105 # if parameter is empty, raise ValueError
106 if not bbs or not board:
107 raise ValueError, "parameter must not be empty"
109 return os.path.join(get_logs_dir_path(), bbs, board, "subject.idx")
111 def get_board_dir_path(bbs, board):
112 """Returns board dir path
119 # if parameter is empty, raise ValueError
120 if not bbs or not board:
121 raise ValueError, "parameter must not be empty"
123 return os.path.join(get_logs_dir_path(), bbs, board)
125 def get_thread_idx_path(bbs, board, thread):
126 """Returns idx file path of thread
134 Note: if parameter is empty, raise ValueError
137 # if parameter is empty, raise ValueError
138 if not bbs or not board or not thread:
139 raise ValueError, "parameter must not be empty"
141 return os.path.join(get_logs_dir_path(), bbs, board, thread + ".idx")
143 def get_board_cache_path(bbs, board):
144 """ Returns .cache file path of board
150 Note: if parameter is empty, raise ValueError
153 # if parameter is empty, raise ValueError
154 if not bbs or not board:
155 raise ValueError, "parameter must not be empty"
157 return os.path.join(get_logs_dir_path(), bbs, board, ".cache")
159 def httpdate_to_secs(httpdate):
160 """Returns the seconds since the epoch"""
162 m = REG_EXPR_HTTPDATE.match(httpdate)
164 tm_wday = WDAY_DICT[m.group(1)]
165 tm_mday = int(m.group(2))
166 tm_mon = MON_DICT[m.group(3)]
167 tm_year = int(m.group(4))
168 tm_hour = int(m.group(5))
169 tm_min = int(m.group(6))
170 tm_sec = int(m.group(7))
172 return int(time.mktime(
173 (tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,0,-1)) \