Mercurial > treepkg
annotate contrib/sawmill/web/details.py @ 527:8138df69a32e
implement export_tag for git working copy
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Mon, 15 Nov 2010 14:53:00 +0000 |
parents | 73a2e603a23b |
children |
rev | line source |
---|---|
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 # -*- coding: UTF-8 -*- |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 # |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 # Copyright (C) 2010 by Intevation GmbH |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 # Authors: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 # Sascha L. Teichmann <sascha.teichmann@intevation.de> |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 # |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 # This program is free software under the GPL (>=v2) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 # Read the file COPYING coming with the software for details. |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 from mod_python import apache, psp, util |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 import os |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 import re |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 import datetime |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 import time |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 from lxml import etree |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 BASE_DIR = "treepkgs" |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 TREEPKG_DIR = os.path.join(os.path.dirname(__file__), BASE_DIR) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 STATUS_LINE = re.compile(r"^([^:]+):(.+)") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 UNDER_SCORE = re.compile(r"_+(\w)") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
27 INVALID_LABEL = re.compile(r"[^a-zA-Z0-9_]") |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
28 |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 def _create_time(s, format="%Y-%m-%d %H:%M:%S"): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 return datetime.datetime(*(time.strptime(s, format)[0:6])) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
32 def _pretty_log_name(log): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 log = log.replace(".txt", "").replace(".gz", "").capitalize() |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 return UNDER_SCORE.sub(lambda x: " %s" % x.group(1).upper(), log) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
36 def _make_valid_label(label): |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
37 return INVALID_LABEL.sub("_", label) |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
38 |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
39 class TrackItem(object): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 def __init__(self, treepkg, track, revision, status_file): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
42 self.treepkg = treepkg |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
43 self.track = track |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
44 self.revision = revision |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
45 self.status_file = status_file |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
46 self.loaded = False |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
47 self.status = None |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
48 self.start = None |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
49 self.stop = None |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
50 self.logs = None |
474
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
51 self.tags = None |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
52 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
53 def check_loaded(self): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
54 if not self.loaded: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
55 f = open(self.status_file) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
56 try: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
57 for line in f: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
58 m = STATUS_LINE.match(line) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
59 if not m: continue |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
60 key, value = [x.strip() for x in m.groups()] |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
61 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
62 if key == 'status': self.status = value |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
63 elif key == 'start': self.start = _create_time(value) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
64 elif key == 'stop': self.stop = _create_time(value) |
474
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
65 elif key == 'tags': self.tags = value |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
66 finally: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
67 f.close() |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
68 self.loaded = True |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
69 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
70 def get_build_status(self): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
71 self.check_loaded() |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
72 return self.status |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
73 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
74 def get_build_start(self): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
75 self.check_loaded() |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
76 return self.start |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
77 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
78 def get_build_stop(self): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
79 self.check_loaded() |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
80 return self.stop |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
81 |
474
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
82 def get_tags(self): |
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
83 self.check_loaded() |
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
84 return self.tags |
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
85 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
86 def get_label(self): |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
87 self.check_loaded() |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
88 out = [ |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
89 _make_valid_label(self.track), |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
90 _make_valid_label(self.revision) ] |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
91 if self.start: |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
92 out.append(self.start.strftime("%Y%m%d%H%M%S")) |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
93 return ''.join(out) |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
94 |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
95 def log_path(self, log): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
96 return "%s/tracks/%s/pkg/%s/log/%s" % ( |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
97 self.treepkg, self.track, self.revision, log) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
98 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
99 def get_build_logs(self): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
100 oj = os.path.join |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
101 if self.logs is None: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
102 log_dir = oj(os.path.dirname(self.status_file), "log") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
103 if not os.path.isdir(log_dir): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
104 self.logs = [] |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
105 else: |
473
d8012571f9e1
sawmill: removed trailing whitespace
Sascha Teichmann <teichmann@intevation.de>
parents:
467
diff
changeset
|
106 self.logs =[(_pretty_log_name(f), self.log_path(f)) |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
107 for f in os.listdir(log_dir) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
108 if os.path.isfile(oj(log_dir, f)) and f.find("txt") >= 0] |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
109 return self.logs |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
110 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
111 build_status = property(get_build_status) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
112 build_start = property(get_build_start) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
113 build_stop = property(get_build_stop) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
114 build_logs = property(get_build_logs) |
474
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
115 build_tags = property(get_tags) |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
116 build_label = property(get_label) |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
117 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
118 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
119 def __scan_track_items(treepkg, path): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
120 items = [] |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
121 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
122 tracks_path = os.path.join(path, "tracks") |
474
a8f77807d710
sawmill: create links for tag builds
Sascha Teichmann <teichmann@intevation.de>
parents:
473
diff
changeset
|
123 if os.path.isdir(tracks_path): |
467
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
124 for track in os.listdir(tracks_path): |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
125 track_path = os.path.join(tracks_path, track) |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
126 if not os.path.isdir(track_path): continue |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
127 revisions_path = os.path.join(track_path, "pkg") |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
128 if not os.path.isdir(revisions_path): continue |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
129 for revision in os.listdir(revisions_path): |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
130 revision_path = os.path.join(revisions_path, revision) |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
131 if not os.path.isdir(revision_path): continue |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
132 status_file = os.path.join(revision_path, "status") |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
133 if not os.path.isfile(status_file): continue |
7fd8af79e652
check if tracks directory exists before walking it.
Sascha Teichmann <teichmann@intevation.de>
parents:
463
diff
changeset
|
134 items.append(TrackItem(treepkg, track, revision, status_file)) |
473
d8012571f9e1
sawmill: removed trailing whitespace
Sascha Teichmann <teichmann@intevation.de>
parents:
467
diff
changeset
|
135 |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
136 return items |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
137 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
138 def __description_header(treepkg): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
139 treepkg_xml = os.path.join(treepkg, "treepkg.xml") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
140 if os.path.isfile(treepkg_xml): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
141 xml = None |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
142 try: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
143 xml = open(treepkg_xml, "rb") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
144 dom = etree.parse(xml) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
145 finally: |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
146 if xml: xml.close() |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
147 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
148 description = ''.join(dom.xpath("//description/text()")) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
149 header = ''.join([etree.tostring(x, encoding="UTF-8", method="html") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
150 for x in dom.xpath("//header/*")]) |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
151 return description, header |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
152 return "unknown", "" |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
153 |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
154 def index(req, treepkg=''): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
155 if not treepkg: util.redirect(req, "index.py") |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
156 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
157 package_dir = None |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
158 for d in os.listdir(TREEPKG_DIR): |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
159 dp = os.path.join(TREEPKG_DIR, d) |
487
f208b139190b
sawmill: Made html head elements HTML 4.01 compatible.
Sascha Teichmann <teichmann@intevation.de>
parents:
483
diff
changeset
|
160 if d == treepkg and os.path.isdir(dp): |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
161 package_dir = dp |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
162 break |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
163 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
164 if not package_dir: |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
165 req.status = apache.HTTP_NOT_FOUND |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
166 return "requested TreePkg not found" |
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
167 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
168 description, header = __description_header(package_dir) |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
169 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
170 track_items = __scan_track_items(treepkg, package_dir) |
473
d8012571f9e1
sawmill: removed trailing whitespace
Sascha Teichmann <teichmann@intevation.de>
parents:
467
diff
changeset
|
171 |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
172 parameters = { |
483
28aa6ac933fb
sawmill: moved wald's table layout into common header and footer
Sascha Teichmann <teichmann@intevation.de>
parents:
474
diff
changeset
|
173 'page_title' : description, |
28aa6ac933fb
sawmill: moved wald's table layout into common header and footer
Sascha Teichmann <teichmann@intevation.de>
parents:
474
diff
changeset
|
174 'back_link' : 'index.py', |
28aa6ac933fb
sawmill: moved wald's table layout into common header and footer
Sascha Teichmann <teichmann@intevation.de>
parents:
474
diff
changeset
|
175 'base_dir' : BASE_DIR, |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
176 'description': description, |
483
28aa6ac933fb
sawmill: moved wald's table layout into common header and footer
Sascha Teichmann <teichmann@intevation.de>
parents:
474
diff
changeset
|
177 'header' : header, |
452
333232953771
Initial check-in of sawmill a simple mod_python based
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
178 'track_items': track_items |
490
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
179 } |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
180 |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
181 if os.path.isfile(os.path.join(package_dir, "rss.xml")): |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
182 parameters['syndicate'] = ( |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
183 'Build error feed', |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
184 'treepkgs/%s/rss.xml' % treepkg) |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
185 |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
186 req.content_type = 'text/html;charset=utf-8' |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
187 template = psp.PSP(req, filename='templates/details.html') |
73a2e603a23b
sawmill: Prepared detail view for syndication:
Sascha Teichmann <teichmann@intevation.de>
parents:
487
diff
changeset
|
188 template.run(parameters) |