Use std.exception.enforce
This commit is contained in:
parent
92cbf5c6eb
commit
3bbdc75efd
15
wp2git.d
15
wp2git.d
|
@ -14,7 +14,7 @@ import ae.utils.xmllite;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
string name, language="en";
|
string language="en";
|
||||||
bool usage, noImport;
|
bool usage, noImport;
|
||||||
getopt(args,
|
getopt(args,
|
||||||
"h|help", &usage,
|
"h|help", &usage,
|
||||||
|
@ -34,14 +34,13 @@ int main(string[] args)
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name)
|
enforce(args.length==2, "No article specified");
|
||||||
throw new Exception("No article specified");
|
auto name = args[1];
|
||||||
|
|
||||||
if (name.length>=2 && name[0]=='"' && name[$-1]=='"')
|
if (name.length>=2 && name[0]=='"' && name[$-1]=='"')
|
||||||
name = name[1..$-1]; // strip quotes
|
name = name[1..$-1]; // strip quotes
|
||||||
|
|
||||||
if (spawnvp(P_WAIT, "curl", ["curl", "-d", "\"\"", "http://" ~ language ~ ".wikipedia.org/w/index.php?title=Special:Export&pages=" ~ encodeComponent(name), "-o", "history.xml"]))
|
enforce(spawnvp(P_WAIT, "curl", ["curl", "-d", "\"\"", "http://" ~ language ~ ".wikipedia.org/w/index.php?title=Special:Export&pages=" ~ encodeComponent(name), "-o", "history.xml"])==0, "curl error");
|
||||||
throw new Exception("curl error");
|
|
||||||
|
|
||||||
stderr.writefln("Loading history...");
|
stderr.writefln("Loading history...");
|
||||||
string xmldata = cast(string) read("history.xml");
|
string xmldata = cast(string) read("history.xml");
|
||||||
|
@ -50,8 +49,7 @@ int main(string[] args)
|
||||||
|
|
||||||
string data = "reset refs/heads/master\n";
|
string data = "reset refs/heads/master\n";
|
||||||
auto page = xml[0]["page"];
|
auto page = xml[0]["page"];
|
||||||
if (!page)
|
enforce(page, "No such page");
|
||||||
throw new Exception("No such page");
|
|
||||||
foreach (child; page)
|
foreach (child; page)
|
||||||
if (child.tag=="revision")
|
if (child.tag=="revision")
|
||||||
{
|
{
|
||||||
|
@ -77,8 +75,7 @@ int main(string[] args)
|
||||||
if (noImport)
|
if (noImport)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (exists(".git"))
|
enforce(!exists(".git"), "A git repository already exists here!");
|
||||||
throw new Exception("A git repository already exists here!");
|
|
||||||
|
|
||||||
system("git init");
|
system("git init");
|
||||||
system("git fast-import --date-format=rfc2822 < fast-import-data");
|
system("git fast-import --date-format=rfc2822 < fast-import-data");
|
||||||
|
|
Loading…
Reference in New Issue