Adding classes Address and Coord, moving functions into the classes.
[treecutter.git] / treecutter / link.py
1 #!/usr/bin/python
2 import glob
3 from treecutter.page import Page
4
5 class Link():
6     """Class representing a webpage on the site"""
7     def __init__(self,link):
8         self._link = link
9         # find the representations of the link.
10         self._pages = []
11         path = link
12         if self._link[-1] == '/':
13             path = path+'index'
14         lang = self._scan_languages(path)
15         for l in lang:
16             self._pages.append(Page(self,l))
17
18     def add_page(self,l):
19         self._pages.append(Page(self,l))
20
21     def _scan_languages(self,path):
22         lang = []
23         for l in  glob.glob('.'+path+'*'):
24             ls = l.split('.')
25             if len(ls) > 3 and ls[3] == 'xml':
26                 lang.append((ls[2],l))
27         return lang
28
29     def link(self):
30         return self._link
31
32     def prepare(self):
33         for page in self._pages:
34             page.prepare()
35
36     def languages(self):
37         p = []
38         for page in self._pages:
39             p.append(page.language())
40         return p
41
42     def render(self, style):
43         for page in self._pages:
44             page.render(style)
45
46     def template(self,sitemap,style,tdir):
47         for page in self._pages:
48             page.template(sitemap,style,tdir)
49
50     def page(self,lang):
51         for page in self._pages:
52             if page.language()==lang:
53                 return page
54         return None
55
56     def resources(self):
57         res  = set()
58         for page in self._pages:
59             res = res.union(page.resources())
60         return res