10 |
|
#include <api/pcre/regex.hpp> |
11 |
|
#include <api/process.hpp> |
12 |
|
#include <app/simple.hpp> |
13 |
+ |
#include <hop/bind.hpp> |
14 |
|
#include <xml/textwriter.hpp> |
15 |
|
|
16 |
|
#include "GoogleTron.hpp" |
16 |
– |
#include "GzipWriter.hpp" |
17 |
|
#include "Sleep.hpp" |
18 |
+ |
#include "Zlib/GzipWriter.hpp" |
19 |
|
|
20 |
|
int Main(const app::Options &options) |
21 |
|
{ |
22 |
|
cse::String sitemap(_B("sitemap.gz")); |
23 |
+ |
_L<_R<Command> > commands; |
24 |
|
|
25 |
< |
api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$")); |
25 |
> |
api::Pcre::RegEx sitemap_(_B("^-sitemap=(.+)$")), fs_(_B("^-fs=(.*)$")), exclude(_B("^-exclude=(.+)$")); |
26 |
|
|
27 |
|
_foreach (const app::ArgumentList, arg, app::GetArguments()) |
28 |
|
{ |
29 |
|
api::Pcre::RegEx::Match match; |
30 |
+ |
_R<FileSystemCommand> fs; |
31 |
|
|
32 |
|
if (match = sitemap_(*arg)) |
33 |
|
sitemap = match[1]; |
34 |
+ |
else if (match = fs_(*arg)) |
35 |
+ |
commands.InsertLast(new _H<FileSystemCommand>(match[1])); |
36 |
+ |
else if (commands.GetSize() && (fs = dynamic_cast<FileSystemCommand *>(commands.Last().GetValue())) && (match = exclude(*arg))) |
37 |
+ |
fs->excludes.InsertLast(match[1]); |
38 |
|
else |
39 |
|
{ |
40 |
< |
api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=sitemap]") << ios::NewLine; |
40 |
> |
api::Cout << _B("Usage: ") << api::GetExecutablePath().GetName() << _B(" [-sitemap=.+] [-fs=.* [-exclude=.+] ...] ...") << ios::NewLine; |
41 |
|
|
42 |
|
return 1; |
43 |
|
} |
44 |
|
} |
45 |
|
|
46 |
< |
GoogleTron tron(sitemap); |
46 |
> |
GoogleTron tron(sitemap, commands); |
47 |
|
|
48 |
|
return 0; |
49 |
|
} |
50 |
|
|
51 |
< |
GoogleTron::GoogleTron(const cse::String &sitemap) : working(true), sitemap(sitemap) |
51 |
> |
GoogleTron::GoogleTron(const cse::String &sitemap, const _L<_R<Command> > &commands) : working(true), sitemap(sitemap), output(hop::BindAll(&GoogleTron::Output, this)) |
52 |
|
{ |
53 |
< |
// XXX: start some threads |
53 |
> |
_foreach (const _L<_R<Command> >, command_, commands) |
54 |
> |
if (_R<FileSystemCommand> command = dynamic_cast<FileSystemCommand *>(command_->GetValue())) |
55 |
> |
threads.Add(hop::BindAll(&GoogleTron::FileSystem_, this, command)); |
56 |
|
} |
57 |
|
|
58 |
|
GoogleTron::~GoogleTron() |
59 |
|
{ |
60 |
< |
// XXX: wait on threads |
61 |
< |
|
60 |
> |
threads.Join(); |
61 |
> |
|
62 |
|
working = false; |
63 |
|
|
64 |
< |
// XXX: wait on output thread |
64 |
> |
output.Join(); |
65 |
|
} |
66 |
|
|
67 |
|
int GoogleTron::Output() |
68 |
|
{ |
69 |
< |
_S<GzipWriter> gzip(sitemap); |
69 |
> |
_S<Zlib::GzipWriter> gzip(sitemap); |
70 |
|
_S<xml::TextWriter> writer(gzip); |
71 |
|
xml::ScopeElement urlset(writer, _B("urlset")); |
72 |
|
|
115 |
|
|
116 |
|
return 0; |
117 |
|
} |
118 |
+ |
|
119 |
+ |
int GoogleTron::FileSystem_(const _R<FileSystemCommand> &command) |
120 |
+ |
{ |
121 |
+ |
FileSystem fs(sitemap, queue, queueLock, command); |
122 |
+ |
|
123 |
+ |
return 0; |
124 |
+ |
} |