OSDN Git Service

ab8269e16d7b5d3e19d4d886311ad4ffa78a2501
[fukui-no-namari/fukui-no-namari.git] / src / Hage1 / misc.py
1 # Copyright (C) 2006 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
3 #
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.
8 #
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.
13 #
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
17
18 import os.path
19
20 import config
21 import brdlist
22
23 def get_logs_dir_path():
24     return os.path.join(config.get_config_dir_path(), "logs")
25
26 def get_board_base_url(bbs, board):
27     """
28     None: this function uses brdlist.get function, so brdlist.read function
29     should have been called before this function is called
30     """
31     # if parameter is empty, raise ValueError
32     if not bbs or not board:
33         raise ValueError, "parameter must not be empty"
34
35     return "http://" + brdlist.get(bbs, board, "host") + "/" + board + "/"
36
37 def get_thread_dat_path(bbs, board, thread):
38     """Returns thread dat file path
39
40     bbs: bbs id
41
42     board: board id
43
44     thread: thread id
45     """
46
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"
50
51     return os.path.join(get_board_dir_path(bbs, board), thread + ".dat")
52
53 def get_board_subjecttxt_url(bbs, board):
54     """Returns subject.txt file url
55
56     bbs: bbs id
57
58     board: board id
59     """
60
61     # if parameter is empty, raise ValueError
62     if not bbs or not board:
63         raise ValueError, "parameter must not be empty"
64
65     return get_board_base_url(bbs, board) + "subject.txt"
66
67 def get_board_subjecttxt_path(bbs, board):
68     """Returns subject.txt file path
69
70     bbs: bbs id
71
72     board: board id
73     """
74
75     # if parameter is empty, raise ValueError
76     if not bbs or not board:
77         raise ValueError, "parameter must not be empty"
78
79     return os.path.join(get_logs_dir_path(), bbs, board, "subject.txt")
80
81 def get_board_dir_path(bbs, board):
82     """Returns board dir path
83
84     bbs: bbs ID
85
86     board: board ID
87     """
88
89     # if parameter is empty, raise ValueError
90     if not bbs or not board:
91         raise ValueError, "parameter must not be empty"
92
93     return os.path.join(get_logs_dir_path(), bbs, board)
94
95 def get_thread_idx_path(bbs, board, thread):
96     """Returns idx file path of thread
97
98     bbs: bbs ID
99
100     board: board ID
101
102     thread: thread ID
103
104     Note: if parameter is empty, raise ValueError
105     """
106
107     # if parameter is empty, raise ValueError
108     if not bbs or not board or not thread:
109         raise ValueError, "parameter must not be empty"
110
111     return os.path.join(get_logs_dir_path(), bbs, board, thread + ".idx")
112
113 def get_board_cache_path(bbs, board):
114     """ Returns .cache file path of board
115
116     bbs: bbs ID
117
118     board: board ID
119
120     Note: if parameter is empty, raise ValueError
121     """
122
123     # if parameter is empty, raise ValueError
124     if not bbs or not board:
125         raise ValueError, "parameter must not be empty"
126
127     return os.path.join(get_logs_dir_path(), bbs, board, ".cache")