-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathproject_list.py
153 lines (125 loc) · 5 KB
/
project_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
##
# pitweb - Web interface for git repository written in python
# ------------------------------------------------------------
# Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
#
#
# This file is part of pitweb.
#
# pitweb is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#
# pitweb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
from mod_python import apache, util
import os
from project import Project
import common
class ProjectListBase(common.ModPythonOutput):
def __init__(self, req, projects = [], basepath = '/'):
super(ProjectListBase, self).__init__(req)
# set default content-type to text/html
self.setContentType('text/html')
self._projects = projects
self._basepath = basepath
def _uri(self):
uri = self._req.uri.split('/')
uri = filter(lambda x: len(x) > 0, uri)
return uri
def run(self):
uri = self._uri()
if len(uri) > 0:
prj_name = uri[-1]
for p in self._projects:
if prj_name == p.projectName():
return p.run()
self.write(self.tpl(self._fProjectList()))
return apache.OK
def _fProjectList(self):
html = ''
html += '<table class="projects">'
html += '<tr class="header">'
html += '<td>Project</td>'
html += '<td>Owner</td>'
html += '<td>Description</td>'
html += '<td>Last change</td>'
html += '</tr>'
for prj in self._projects:
name = self._esc(prj.projectName())
owner = self._esc(prj.owner())
desc = self._esc(prj.description())
last_change = self._esc(prj.lastChange())
html += '<tr>'
html += '<td><a href="{0}{1}">{1}</a></td>'.format(self._basepath, name)
html += '<td>{0}</td>'.format(owner)
html += '<td>{0}</td>'.format(desc)
html += '<td>{0}</td>'.format(last_change)
html += '</tr>'
html += '</table>'
return html
def tpl(self, content):
html = '''
<html>
<head>
<style type="text/css">
{css}
</style>
<title>pitweb</title>
</head>
<body>
<div class="content">
{content}
</div>
</body>
</html>
'''.format(css = self.css(), content = content)
return html
def css(self):
h = '''
html * { font-family: sans; font-size: 13px; }
body { padding: 5px; }
table tr td { vertical-align: top; padding-left: 4px; padding-right: 4px; }
table tr.header { font-weight: bold; font-size: 15px; }
table tr.title td { padding: 3px; padding-left: 7px; font-size: 16px; font-weight: bold; background-color: #edece6; }
table tr:hover { background-color: #fbfaf7; }
a { color: #0000cc; text-decoration: none; }
a:hover { text-decoration: underline; }
a.comment { font-weight: bold; color: #666666; }
a.tag { display: block-inline; background-color: #ffffaa; border: 1px solid #f1ee00; color: black;
margin-left: 2px; margin-right: 2px;
padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; }
a.branch { display: block-inline; background-color: #88ff88; border: 1px solid #39ba39; color: black;
margin-left: 2px; margin-right: 2px;
padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; }
a.remote { display: block-inline; background-color: #AAAAFF; border: 1px solid #8888ff; color: black;
margin-left: 2px; margin-right: 2px;
padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; }
a.blob { color: black; }
a.menu { font-family: sans !important; font-size: 11px !important; }
'''
return h
class ProjectListDir(ProjectListBase):
""" List of projects is based on one directory.
All subdirectories which contain config file (piteweb.py) are taken
as project.
"""
def __init__(self, req, dir, basepath = '/'):
projects = self._projects(req, dir, basepath)
super(ProjectListDir, self).__init__(req, projects, basepath = basepath)
def _projects(self, req, parent_dir, basepath):
projects = []
dirs = sorted(os.listdir(parent_dir), key=str.lower)
for dir in dirs:
path = os.path.join(parent_dir, dir)
config = os.path.join(path, 'pitweb.py')
if os.path.isdir(path) and os.path.isfile(config):
projects.append(Project(req, path, basepath))
return projects