210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
1 |
# cmd_inventory.py - web interface for bazaar
|
214
by ghigo
update the copyright statement |
2 |
# this code is derived by the hgweb server of the Matt Mackall's mercurial
|
3 |
# project
|
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
4 |
#
|
214
by ghigo
update the copyright statement |
5 |
# Copyright 2006 Goffredo Baroncelli <kreijack@inwind.it>
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
6 |
#
|
7 |
# This file is part of bazaar-webserve.
|
|
8 |
#
|
|
9 |
# bazaar-webserve is free software; you can redistribute it and/or modify
|
|
10 |
# it under the terms of the GNU General Public License as published by
|
|
11 |
# the Free Software Foundation; either version 2 of the License, or
|
|
12 |
# (at your option) any later version.
|
|
13 |
#
|
|
14 |
# bazaar-webserve is distributed in the hope that it will be useful,
|
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 |
# GNU General Public License for more details.
|
|
18 |
#
|
|
19 |
# You should have received a copy of the GNU General Public License
|
|
20 |
# along with bazaar-webserve; if not, write to the Free Software
|
|
21 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
22 |
||
23 |
||
24 |
import hgweb |
|
216
by ghigo
- added missing import |
25 |
from hgweb import ( |
26 |
WebServeErrorRevisionNotFound, |
|
27 |
WebServeErrorPathNotFound
|
|
28 |
)
|
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
29 |
|
235
by ghigo
pep8 cleanup |
30 |
|
31 |
def dname(path): |
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
32 |
d = path.rfind('/') |
33 |
if d>= 0: |
|
34 |
return path[:d] |
|
35 |
else: |
|
36 |
return "" |
|
37 |
||
235
by ghigo
pep8 cleanup |
38 |
|
39 |
def fname(path): |
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
40 |
d = path.rfind('/') |
41 |
return path[d+1:] |
|
42 |
||
235
by ghigo
pep8 cleanup |
43 |
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
44 |
def filelist(webserve, rev, inv, path2): |
45 |
parity=0 |
|
46 |
for fpath, entry in inv.entries(): |
|
47 |
if dname(fpath) != path2: |
|
48 |
continue
|
|
49 |
bname = fname(fpath) |
|
50 |
#FIXME: remeber of the link, and the x attribute
|
|
51 |
if entry.kind == "file": |
|
52 |
yield webserve.t("inventoryfileentry", |
|
53 |
perm = entry.executable, |
|
54 |
parity = parity, |
|
55 |
name = bname, |
|
56 |
fullname = fpath, |
|
57 |
id = entry.file_id, |
|
58 |
entryrevision = entry.revision, |
|
59 |
rev = rev, |
|
235
by ghigo
pep8 cleanup |
60 |
filesize = entry.text_size, |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
61 |
)
|
62 |
elif entry.kind == "directory": |
|
63 |
yield webserve.t("inventorydirentry", |
|
64 |
perm = entry.executable, |
|
65 |
parity = parity, |
|
66 |
name = bname + '/', |
|
67 |
path = fpath, |
|
68 |
id = entry.file_id, |
|
69 |
entryrevision = entry.revision, |
|
70 |
rev = rev, |
|
71 |
)
|
|
72 |
elif entry.kind == "symlink": |
|
73 |
yield webserve.t("inventorylinkentry", |
|
74 |
perm = entry.executable, |
|
75 |
parity = parity, |
|
235
by ghigo
pep8 cleanup |
76 |
name = bname, |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
77 |
fullname = fpath, |
78 |
id = entry.file_id, |
|
79 |
entryrevision = entry.revision, |
|
80 |
rev = rev, |
|
81 |
)
|
|
82 |
parity = 1 - parity |
|
83 |
||
235
by ghigo
pep8 cleanup |
84 |
|
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
85 |
def inventory(webserve, rev, path=None, pathrevid=None): |
86 |
||
87 |
rev = webserve.get_revid(rev) |
|
88 |
||
89 |
if not webserve.revision_history.exist_revision(rev): |
|
90 |
raise WebServeErrorRevisionNotFound(rev) |
|
91 |
||
92 |
inv = webserve.branch.repository.get_revision_inventory(rev) |
|
235
by ghigo
pep8 cleanup |
93 |
if not path: |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
94 |
path2 = "" |
95 |
path = "/" |
|
96 |
file_id = None |
|
97 |
pathrevid = rev |
|
98 |
else: |
|
235
by ghigo
pep8 cleanup |
99 |
pathrevid = webserve.get_revid(pathrevid, rev) |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
100 |
if not webserve.revision_history.exist_revision(pathrevid): |
101 |
raise WebServeErrorRevisionNotFound(pathrevid) |
|
235
by ghigo
pep8 cleanup |
102 |
file_id = webserve.get_fileid(path, pathrevid) |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
103 |
if file_id == None or not inv.has_id(file_id): |
104 |
raise WebServeErrorPathNotFound(rev, path, pathrevid) |
|
105 |
path2 = inv.id2path(file_id) |
|
106 |
||
107 |
revision = webserve.branch.repository.get_revision(rev) |
|
108 |
yield webserve.t("inventory", |
|
109 |
rev = rev, |
|
110 |
invnav = webserve.template_nav_revid( |
|
111 |
"invnaventry", rev, path=path, |
|
235
by ghigo
pep8 cleanup |
112 |
pathrevid=pathrevid), |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
113 |
path = path, |
114 |
actualpath = path2, |
|
235
by ghigo
pep8 cleanup |
115 |
linkpath = webserve.template_path(rev, path, pathrevid), |
210
by ghigo
- moved the inventory( ) function to the cmd_inventory file |
116 |
pathrevid = pathrevid, |
117 |
revlink = webserve.template_revid(rev), |
|
118 |
fileid = file_id and file_id or "", |
|
119 |
parent = dname(path[:-1]), |
|
120 |
entries = [x for x in filelist(webserve, rev, inv, path2)], |
|
121 |
author = revision.committer, |
|
122 |
desc = revision.message, |
|
123 |
date = revision.timestamp, |
|
124 |
)
|