comparison contrib/sawmill/web/details.py @ 490:73a2e603a23b

sawmill: Prepared detail view for syndication: Added anchors for each build and added render rel link if RSS file exists next to treepkg.xml.
author Sascha Teichmann <teichmann@intevation.de>
date Wed, 29 Sep 2010 19:25:52 +0000
parents f208b139190b
children
comparison
equal deleted inserted replaced
489:e7114ac643c3 490:73a2e603a23b
22 22
23 STATUS_LINE = re.compile(r"^([^:]+):(.+)") 23 STATUS_LINE = re.compile(r"^([^:]+):(.+)")
24 24
25 UNDER_SCORE = re.compile(r"_+(\w)") 25 UNDER_SCORE = re.compile(r"_+(\w)")
26 26
27 INVALID_LABEL = re.compile(r"[^a-zA-Z0-9_]")
28
27 def _create_time(s, format="%Y-%m-%d %H:%M:%S"): 29 def _create_time(s, format="%Y-%m-%d %H:%M:%S"):
28 return datetime.datetime(*(time.strptime(s, format)[0:6])) 30 return datetime.datetime(*(time.strptime(s, format)[0:6]))
29 31
30 def _pretty_log_name(log): 32 def _pretty_log_name(log):
31 log = log.replace(".txt", "").replace(".gz", "").capitalize() 33 log = log.replace(".txt", "").replace(".gz", "").capitalize()
32 return UNDER_SCORE.sub(lambda x: " %s" % x.group(1).upper(), log) 34 return UNDER_SCORE.sub(lambda x: " %s" % x.group(1).upper(), log)
35
36 def _make_valid_label(label):
37 return INVALID_LABEL.sub("_", label)
33 38
34 class TrackItem(object): 39 class TrackItem(object):
35 40
36 def __init__(self, treepkg, track, revision, status_file): 41 def __init__(self, treepkg, track, revision, status_file):
37 self.treepkg = treepkg 42 self.treepkg = treepkg
76 81
77 def get_tags(self): 82 def get_tags(self):
78 self.check_loaded() 83 self.check_loaded()
79 return self.tags 84 return self.tags
80 85
86 def get_label(self):
87 self.check_loaded()
88 out = [
89 _make_valid_label(self.track),
90 _make_valid_label(self.revision) ]
91 if self.start:
92 out.append(self.start.strftime("%Y%m%d%H%M%S"))
93 return ''.join(out)
94
81 def log_path(self, log): 95 def log_path(self, log):
82 return "%s/tracks/%s/pkg/%s/log/%s" % ( 96 return "%s/tracks/%s/pkg/%s/log/%s" % (
83 self.treepkg, self.track, self.revision, log) 97 self.treepkg, self.track, self.revision, log)
84 98
85 def get_build_logs(self): 99 def get_build_logs(self):
97 build_status = property(get_build_status) 111 build_status = property(get_build_status)
98 build_start = property(get_build_start) 112 build_start = property(get_build_start)
99 build_stop = property(get_build_stop) 113 build_stop = property(get_build_stop)
100 build_logs = property(get_build_logs) 114 build_logs = property(get_build_logs)
101 build_tags = property(get_tags) 115 build_tags = property(get_tags)
116 build_label = property(get_label)
102 117
103 118
104 def __scan_track_items(treepkg, path): 119 def __scan_track_items(treepkg, path):
105 items = [] 120 items = []
106 121
137 return "unknown", "" 152 return "unknown", ""
138 153
139 def index(req, treepkg=''): 154 def index(req, treepkg=''):
140 if not treepkg: util.redirect(req, "index.py") 155 if not treepkg: util.redirect(req, "index.py")
141 156
142 found = None 157 package_dir = None
143 for d in os.listdir(TREEPKG_DIR): 158 for d in os.listdir(TREEPKG_DIR):
144 dp = os.path.join(TREEPKG_DIR, d) 159 dp = os.path.join(TREEPKG_DIR, d)
145 if d == treepkg and os.path.isdir(dp): 160 if d == treepkg and os.path.isdir(dp):
146 found = dp 161 package_dir = dp
147 break 162 break
148 163
149 if not found: 164 if not package_dir:
150 req.status = apache.HTTP_NOT_FOUND 165 req.status = apache.HTTP_NOT_FOUND
151 return "requested TreePkg not found" 166 return "requested TreePkg not found"
152 167
153 description, header = __description_header(found) 168 description, header = __description_header(package_dir)
154 169
155 track_items = __scan_track_items(treepkg, found) 170 track_items = __scan_track_items(treepkg, package_dir)
156 171
157 req.content_type = 'text/html;charset=utf-8' 172 parameters = {
158 template = psp.PSP(req, filename='templates/details.html')
159 template.run({
160 'page_title' : description, 173 'page_title' : description,
161 'back_link' : 'index.py', 174 'back_link' : 'index.py',
162 'base_dir' : BASE_DIR, 175 'base_dir' : BASE_DIR,
163 'description': description, 176 'description': description,
164 'header' : header, 177 'header' : header,
165 'track_items': track_items 178 'track_items': track_items
166 }) 179 }
180
181 if os.path.isfile(os.path.join(package_dir, "rss.xml")):
182 parameters['syndicate'] = (
183 'Build error feed',
184 'treepkgs/%s/rss.xml' % treepkg)
185
186 req.content_type = 'text/html;charset=utf-8'
187 template = psp.PSP(req, filename='templates/details.html')
188 template.run(parameters)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)