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
20 from misc import get_thread_idx_path
22 metadata_namelist = ["title", "lineCount", "lastModified", "etag"]
24 def load_idx(bbs, board, thread):
25 """Loads index file of thread
33 return dictionary which key is in metadata_namelist if idx file exist,
34 otherwise return empty dic
36 idxfile_path = get_thread_idx_path(bbs, board, thread)
37 if not os.path.exists(idxfile_path):
38 return {"title":None,"lineCount":0,"lastModified":None,"etag":None}
40 f = open(idxfile_path, "r")
44 for name in metadata_namelist:
45 if line.startswith(name+"="):
46 value = line[len(name)+1:].rstrip("\n")
47 if name is "lineCount":
49 datadic[name] = int(value)
54 #print name, datadic[name]
59 # if datadic does not have key, insert empty entry.
60 for name in metadata_namelist:
61 if name not in datadic:
62 if name is "lineCount":
68 def save_idx(bbs, board, thread, datadic):
69 """Saves thread metadatas to a index file
77 datadic: dictionary which key is in metadata_namelist
79 no need to save empty or non-existing metadata
82 # create a directory where idx file should belong if does not exist
83 idxfile_path = get_thread_idx_path(bbs, board, thread)
84 basedir = os.path.dirname(idxfile_path)
85 if not os.path.isdir(basedir):
88 f = open(idxfile_path, "w")
89 for name in metadata_namelist:
91 if name is "lineCount":
93 f.write(name + "=" + str(datadic[name]) + "\n")
96 f.write(name + "=" + datadic[name] + "\n")