1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-19 23:16:49 -04:00
parent 794b5a232f
commit 8e041d6e06
834 changed files with 4749 additions and 4461 deletions

View File

@@ -51,27 +51,32 @@ public class Xob_dump_file {
public boolean Connect() {
IoEngine_xrg_downloadFil args = Io_mgr.I.DownloadFil_args("", Io_url_.Empty);
boolean rv = Connect_exec(args, file_url);
if ( !rv
&& String_.In(server_url, Xob_dump_file_.Server_wmf_http, Xob_dump_file_.Server_wmf_https)
&& String_.Eq(dump_date, Xob_dump_file_.Date_latest)
) { // WMF changed dumping approach to partial dumps; this sometimes causes /latest/ to be missing page_articles; try to get earlier dump; DATE:2015-07-09
// WMF changed dumping approach to partial dumps; this sometimes causes /latest/ to be missing page_articles; try to get earlier dump; DATE:2015-07-09
if ( !rv // not found
&& String_.In(server_url, Xob_dump_file_.Server_wmf_http, Xob_dump_file_.Server_wmf_https) // server is dumps.wikimedia.org
&& String_.Eq(dump_date, Xob_dump_file_.Date_latest) // request dump was latest
) {
Xoa_app_.Usr_dlg().Warn_many("", "", "wmf.dump:latest not found; url=~{0}", file_url);
byte[] abrv_wm = Xow_wiki_alias.Build_alias(wiki_domain_itm);
String new_dump_root = Xob_dump_file_.Server_wmf_https + String_.new_u8(abrv_wm) + "/"; // EX: http://dumps.wikimedia.org/enwiki/
byte[] wiki_dump_dirs_src = args.Exec_as_bry(new_dump_root);
if (wiki_dump_dirs_src == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "could not connect to dump server; url=~{0}", new_dump_root); return false;}
String[] dates = gplx.xowa.wmfs.dump_pages.Xowmf_wiki_dump_dirs_parser.Parse(wiki_domain_itm.Domain_bry(), wiki_dump_dirs_src);
int dates_len = dates.length;
if ( dates_len > 3 // need at least 3; EX: 20150601,20150701,latest; 20150701 and latest are same; 20150601 is last good
&& String_.Eq(dates[dates_len - 1], Xob_dump_file_.Date_latest)) { // last itm is latest
String new_dump_date = dates[dates_len - 3];
for (int i = dates_len - 1; i > -1; --i) {
String new_dump_date = dates[i];
if (String_.Eq(new_dump_date, Xob_dump_file_.Date_latest)) continue; // skip latest; assume it is bad
String new_dump_file = String_.Replace(file_name, Xob_dump_file_.Date_latest, new_dump_date); // replace "-latest-" with "-20150602-";
String new_file_url = new_dump_root + new_dump_date + "/" + new_dump_file;
rv = Connect_exec(args, new_file_url);
if (rv) {
Xoa_app_.Usr_dlg().Note_many("", "", "wmf.dump:dump found; url=~{0}", new_file_url);
dump_date = new_dump_date;
file_name = new_dump_file;
file_url = new_file_url;
}
else
Xoa_app_.Usr_dlg().Warn_many("", "", "wmf.dump:dump not found; url=~{0}", new_file_url);
}
}
return rv;

View File

@@ -51,8 +51,8 @@ abstract class Xoi_cmd_base implements Gfo_thread_cmd {
try {bldr.Run();}
catch (Exception e) {
running = false;
install_mgr.Cmd_mgr().Working_n_();
throw Exc_.new_exc(e, "xo", "error during import");
install_mgr.Cmd_mgr().Working_(Bool_.N);
throw Err_.new_exc(e, "xo", "error during import");
}
app.Usr_dlg().Prog_none("", "clear", "");
app.Usr_dlg().Note_none("", "clear", "");

View File

@@ -70,7 +70,7 @@ class Xoi_cmd_dumpfile_fxt {
else if (expd != null && actl != null) {
Tfds.Eq(expd, actl.Raw());
}
else if (expd == null) throw Exc_.new_("actl should be null", "expd", expd);
else if (actl == null) throw Exc_.new_("actl should not be null", "expd", expd);
else if (expd == null) throw Err_.new_wo_type("actl should be null", "expd", expd);
else if (actl == null) throw Err_.new_wo_type("actl should not be null", "expd", expd);
}
}

View File

@@ -22,7 +22,11 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
public Xoi_cmd_mgr(Xoi_setup_mgr install_mgr) {this.app = install_mgr.App(); this.install_mgr = install_mgr;} private Xoae_app app; Xoi_setup_mgr install_mgr;
public Xoae_app App() {return app;}
public void Canceled_y_() {canceled = true;} private boolean canceled = false;
public boolean Working() {return working;} public void Working_n_() {working = false;} private boolean working;
public boolean Working() {return working;} private boolean working;
public void Working_(boolean v) {
working = v;
app.Bldr__running_(v);
}
private void Process_async(Gfo_thread_cmd cmd) {
byte init_rslt = cmd.Async_init();
if (init_rslt == Gfo_thread_cmd_.Init_ok) {
@@ -31,7 +35,7 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
boolean async_prog_enabled = cmd.Async_prog_enabled();
int async_sleep_sum = 0;
while (cmd.Async_running()) {
if (canceled) {working = false; return;}
if (canceled) {this.Working_(Bool_.N); return;}
if (async_prog_enabled) cmd.Async_prog_run(async_sleep_sum);
Thread_adp_.Sleep(async_sleep_interval);
async_sleep_sum += async_sleep_interval; // NOTE: this is not exact
@@ -41,7 +45,7 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
if (cmd.Async_next_cmd() != null && init_rslt != Gfo_thread_cmd_.Init_cancel_all && term_pass)
Run_async(cmd.Async_next_cmd());
else
working = false;
this.Working_(Bool_.N);
}
private void Run_async(Gfo_thread_cmd cmd) {Thread_adp_.invk_msg_(cmd.Async_key(), this, GfoMsg_.new_cast_(Invk_process_async).Add("v", cmd)).Start();}
private void Cmds_run() {
@@ -59,12 +63,13 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
}
Gfo_thread_cmd cmd = (Gfo_thread_cmd)cmds.Get_at(0);
cmds.Clear();
working = true;
this.Working_(Bool_.Y);
app.Bldr__running_(true);
this.Run_async(cmd);
}
Object Dump_add_many(GfoMsg m) {
int args_len = m.Args_count();
if (args_len < 4) throw Exc_.new_("Please provide the following: wiki name, wiki date, dump_type, and one command; EX: ('simple.wikipedia.org', 'latest', 'pages-articles', 'wiki.download')");
if (args_len < 4) throw Err_.new_wo_type("Please provide the following: wiki name, wiki date, dump_type, and one command; EX: ('simple.wikipedia.org', 'latest', 'pages-articles', 'wiki.download')");
String wiki_key = m.Args_getAt(0).Val_to_str_or_empty();
String wiki_date = m.Args_getAt(1).Val_to_str_or_empty();
String dump_type = m.Args_getAt(2).Val_to_str_or_empty();
@@ -110,7 +115,7 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
else if (String_.Eq(cmd_key, Xoi_cmd_category2_page_props.KEY_category2)) return new Xoi_cmd_category2_page_props(install_mgr, wiki_key, wiki_date).Owner_(this);
else if (String_.Eq(cmd_key, Xoi_cmd_category2_categorylinks.KEY_category2)) return new Xoi_cmd_category2_categorylinks(install_mgr, wiki_key, wiki_date).Owner_(this);
else if (String_.Eq(cmd_key, Xoi_cmd_search2_build.KEY)) return new Xoi_cmd_search2_build(install_mgr, wiki_key).Owner_(this);
else throw Exc_.new_unhandled(cmd_key);
else throw Err_.new_unhandled(cmd_key);
}
public static final String[] Wiki_cmds_valid = new String[] {Xoi_cmd_wiki_download.Key_wiki_download, Xoi_cmd_wiki_unzip.KEY_dump, Xoi_cmd_wiki_import.KEY, Xoi_cmd_wiki_zip.KEY, Xoi_cmd_category2_build.KEY, Xoi_cmd_category2_page_props.KEY_category2, Xoi_cmd_category2_categorylinks.KEY_category2};
public static final String Wiki_cmd_custom = "wiki.custom", Wiki_cmd_dump_file = "wiki.dump_file";
@@ -126,7 +131,7 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
// else if (String_.Eq(cmd_key, Gfo_thread_exec_sync.KEY)) return new Gfo_thread_exec_sync(app.Usr_dlg(), app.Gui_mgr().Kit(), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("url")), m.ReadStr("args")).Owner_(this);
else if (String_.Eq(cmd_key, Xoi_cmd_imageMagick_download.KEY_imageMagick)) return new Xoi_cmd_imageMagick_download(app.Usr_dlg(), app.Gui_mgr().Kit(), Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("trg"))).Owner_(this);
else if (String_.Eq(cmd_key, Wiki_cmd_dump_file)) return Wiki_cmd_dump_file_make(m);
else throw Exc_.new_unhandled(cmd_key);
else throw Err_.new_unhandled(cmd_key);
}
Gfo_thread_cmd Wiki_cmd_dump_file_make(GfoMsg m) {
Xoi_cmd_dumpfile dumpfile = new Xoi_cmd_dumpfile().Parse_msg(m);

View File

@@ -74,7 +74,7 @@ class Xoi_cmd_wiki_unzip extends Gfo_thread_cmd_unzip implements Gfo_thread_cmd
case Gfui_dlg_msg_.Btn_yes: Io_mgr.I.DeleteFil(trg); break;
case Gfui_dlg_msg_.Btn_no: return Gfo_thread_cmd_.Init_cancel_step;
case Gfui_dlg_msg_.Btn_cancel: return Gfo_thread_cmd_.Init_cancel_all;
default: throw Exc_.new_unhandled(rslt);
default: throw Err_.new_unhandled(rslt);
}
}
return Gfo_thread_cmd_.Init_ok;

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import org.junit.*;
import gplx.core.consoles.*;
import gplx.brys.*; import gplx.core.threads.*; import gplx.xowa.wikis.*; import gplx.xowa.setup.maints.*; import gplx.xowa.xtns.wdatas.imports.*;
public class Xoi_cmd_wiki_tst {
@Test public void Run() { // MAINT
@@ -118,7 +119,7 @@ public class Xoi_cmd_wiki_tst {
api.Build_cfg(bfr, wiki);
}
catch (Exception e) {
ConsoleAdp._.WriteLine(Err_.Message_gplx_brief(e));
Console_adp__sys.I.Write_str_w_nl(Err_.Message_gplx_full(e));
}
}
bfr.Add_str_a7("app.bldr.wiki_cfg_bldr.run;").Add_byte_nl();

View File

@@ -83,13 +83,13 @@ public class Xoi_dump_mgr implements GfoInvkAble {
switch (v) {
case Xoi_dump_mgr.Wiki_storage_type_xdat : return "xdat";
case Xoi_dump_mgr.Wiki_storage_type_sqlite : return "sqlite";
default : throw Exc_.new_unhandled(v);
default : throw Err_.new_unhandled(v);
}
}
public static byte Wiki_storage_type_parse(String v) {
if (String_.Eq(v, "xdat")) return Xoi_dump_mgr.Wiki_storage_type_xdat;
else if (String_.Eq(v, "sqlite")) return Xoi_dump_mgr.Wiki_storage_type_sqlite;
else throw Exc_.new_unhandled(v);
else throw Err_.new_unhandled(v);
}
private static final KeyVal[] Options_search_version_list = KeyVal_.Ary(KeyVal_.new_("1"), KeyVal_.new_("2"));
public static String Options_search_version_str(byte v) {return Byte_.Xto_str(v);}

View File

@@ -58,9 +58,9 @@ public class Xow_cfg_wiki_core {
switch (b) {
case Byte_ascii.Pipe:
switch (fld_idx) {
case 0: cur_id = Bry_.Xto_int_or(src, fld_bgn, pos, Int_.MinValue); if (cur_id == Int_.MinValue) throw Exc_.new_("failed to load id", "id", String_.new_u8(src, fld_bgn, pos)); break;
case 1: cur_case_match = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.Max_value_127); if (cur_id == Byte_.Max_value_127) throw Exc_.new_("failed to load match", "id", String_.new_u8(src, fld_bgn, pos)); break;
default: throw Exc_.new_unhandled(fld_idx);
case 0: cur_id = Bry_.Xto_int_or(src, fld_bgn, pos, Int_.MinValue); if (cur_id == Int_.MinValue) throw Err_.new_wo_type("failed to load id", "id", String_.new_u8(src, fld_bgn, pos)); break;
case 1: cur_case_match = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.Max_value_127); if (cur_id == Byte_.Max_value_127) throw Err_.new_wo_type("failed to load match", "id", String_.new_u8(src, fld_bgn, pos)); break;
default: throw Err_.new_unhandled(fld_idx);
}
fld_bgn = pos + 1;
++fld_idx;