1 |
douglas |
696 |
// Wiki |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#include <cxx/standard.hh> |
8 |
|
|
|
9 |
douglas |
714 |
#include <api/files.hpp> |
10 |
douglas |
713 |
#include <api/pcre/regex.hpp> |
11 |
|
|
|
12 |
douglas |
696 |
#include "Wiki.hpp" |
13 |
|
|
|
14 |
douglas |
713 |
Wiki::Wiki(const cse::String &sitemap, const cse::String &base, ext::Queue<Url> &queue, api::ThreadMutex &queueLock, const _R<WikiCommand> &command) : CommandRunner(sitemap, queue, queueLock) |
15 |
douglas |
696 |
{ |
16 |
|
|
api::Cout << _B("Wiki") << ios::NewLine; |
17 |
douglas |
713 |
|
18 |
|
|
Entries(command->root, _S<ios::String>() << base << command->path); |
19 |
douglas |
696 |
} |
20 |
douglas |
713 |
|
21 |
|
|
void Wiki::Entries(const api::Path &directory, const cse::String &base) |
22 |
|
|
{ |
23 |
douglas |
717 |
{ |
24 |
|
|
cse::String wiki(client.GetProperty(_B("GoogleTron:Wiki"), directory.GetPath())); |
25 |
douglas |
713 |
|
26 |
douglas |
717 |
if (wiki != _B("PmWiki")) |
27 |
|
|
throw ext::NotImplementedException(_S<ios::String>(_B("unknown wiki ")) << wiki); |
28 |
|
|
} |
29 |
douglas |
713 |
|
30 |
|
|
api::Path wikiDirectory(directory.GetChild(_B("wiki.d"))); |
31 |
|
|
ext::RedBlackSet<cse::String> excludes(GetProperties<ext::RedBlackSet<cse::String> >(_B("GoogleTron:Exclude"), wikiDirectory.GetPath())); |
32 |
|
|
ext::RedBlackSet<cse::String> sections(GetProperties<ext::RedBlackSet<cse::String> >(_B("GoogleTron:Section"), wikiDirectory.GetPath())); |
33 |
|
|
api::Pcre::RegEx wikiEntry(_B("^([^a-z].*)\\.([^a-z].*)$")); |
34 |
|
|
|
35 |
|
|
_foreach (const _L<Subversion::Entry>, entry, client.GetEntries(wikiDirectory.GetPath())) |
36 |
|
|
{ |
37 |
|
|
api::Pcre::RegEx::Match match; |
38 |
|
|
|
39 |
|
|
if (!entry->GetName().StartsWith('.') && !excludes.Contains(entry->GetName()) && (match = wikiEntry(entry->GetName())) && sections.Contains(match[1])) |
40 |
douglas |
714 |
Entry(wikiDirectory.GetChild(entry->GetName()), base, *entry, match[1], match[2]); |
41 |
douglas |
713 |
} |
42 |
|
|
} |
43 |
douglas |
714 |
|
44 |
|
|
void Wiki::Entry(const api::Path &file, const cse::String &base, const Subversion::Entry &entry, const cse::String §ion, const cse::String &page) |
45 |
|
|
{ |
46 |
|
|
std::time_t modified(entry.GetModified()); |
47 |
|
|
|
48 |
|
|
try |
49 |
|
|
{ |
50 |
|
|
_S<api::FileReader> reader(file.GetPath()); |
51 |
|
|
ext::Buffer key, value; |
52 |
|
|
|
53 |
|
|
while (key = ios::ReadUntil(reader, '='), ios::ReadLine(reader, value)) |
54 |
|
|
if (key == _B("time")) |
55 |
|
|
{ |
56 |
|
|
modified = lexical_cast<std::time_t>(cse::String(value)); |
57 |
|
|
|
58 |
|
|
break; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
catch (ext::EosException) {} |
62 |
|
|
|
63 |
|
|
Url url(_S<ios::String>() << base << section << _B("/") << page, modified, always, GetPriority(client.GetProperty(_B("GoogleTron:Priority"), file.GetPath()))); |
64 |
|
|
|
65 |
|
|
_synchronized (queueLock) |
66 |
|
|
queue.Push(url); |
67 |
|
|
} |