mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.6.4.1'
This commit is contained in:
@@ -17,10 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.addons.bldrs.infos.*;
|
||||
public class Xobc_task_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xobc_task_special.Prototype
|
||||
, Xobc_info_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
|
||||
@@ -19,9 +19,10 @@ package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; impo
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*;
|
||||
public class Xobc_task_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
private Xoa_app app;
|
||||
public void Init_by_app(Xoa_app app) {this.app = app;}
|
||||
public String Exec(Json_nde data) {
|
||||
Xobc_task_mgr task_mgr = Xobc_task_special.Task_mgr;
|
||||
Xobc_task_mgr task_mgr = Xobc_task_special.Task_mgr(app);
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
|
||||
@@ -36,7 +36,6 @@ class Xobc_task_html extends Xow_special_wtr__base {
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xobc.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_htm_frag(addon_dir.GenSubFil_nest("bin", "xobc.row.mustache.html"), "xobc.row"));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.log.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.ajax.listener.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.app.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", Get_app_js_file(app))));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("js", "xo.elem.js")));
|
||||
|
||||
@@ -18,16 +18,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xobc_task_special implements Xow_special_page {
|
||||
public static Xobc_task_mgr Task_mgr;
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
// init task_mgr
|
||||
page.Html_data().Cbk_enabled_(true); // apply cbk_enabled early to capture logging statements
|
||||
Xoa_app app = wiki.App();
|
||||
if (Task_mgr == null) Task_mgr = New_task_mgr(app);
|
||||
Task_mgr.Load_or_init();
|
||||
if (task_mgr == null) task_mgr = New_task_mgr(app);
|
||||
task_mgr.Load_or_init();
|
||||
|
||||
new Xobc_task_html().Bld_page_by_mustache(app, page, this);
|
||||
}
|
||||
public static Xobc_task_mgr Task_mgr(Xoa_app app) {
|
||||
if (task_mgr == null) {
|
||||
task_mgr = New_task_mgr(app);
|
||||
}
|
||||
return task_mgr;
|
||||
} private static Xobc_task_mgr task_mgr;
|
||||
private static Xobc_task_mgr New_task_mgr(Xoa_app app) {
|
||||
Io_url data_db_url = app.Fsys_mgr().Bin_addon_dir().GenSubFil_nest("bldr", "central", "bldr_central.data_db.xowa");
|
||||
app.User().User_db_mgr().Init_site_mgr();
|
||||
|
||||
@@ -54,14 +54,4 @@ public class Xobc_data_db {
|
||||
tbl__import_step.Delete(step_id);
|
||||
}
|
||||
}
|
||||
private final gplx.core.lists.hashs.Hash_adp__int host_hash = new gplx.core.lists.hashs.Hash_adp__int();
|
||||
public String Bld_src_http_url(gplx.core.brys.evals.Bry_eval_mgr eval_mgr, int host_id, String file_name) {
|
||||
Xobc_host_regy_itm host_itm = (Xobc_host_regy_itm)host_hash.Get_by_or_null(host_id);
|
||||
if (host_itm == null) {
|
||||
host_itm = tbl__host_regy.Select(host_id);
|
||||
host_hash.Add(host_id, host_itm);
|
||||
}
|
||||
String host_dir = String_.new_u8(eval_mgr.Eval(Bry_.new_u8(host_itm.Host_data_dir())));
|
||||
return String_.Format("http://{0}/{1}/{2}", host_itm.Host_domain(), host_dir, file_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,16 @@ public class Xobc_step_map_tbl implements Db_tbl {
|
||||
} finally {rdr.Rls();}
|
||||
throw Err_.new_("", "xobc:could not find next sort", "task_id", task_id);
|
||||
}
|
||||
public List_adp Select_all(int task_id) {
|
||||
List_adp rv = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id).Crt_int(fld_task_id, task_id).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
rv.Add(rdr.Read_int("step_id"));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return rv;
|
||||
}
|
||||
public void Insert(int sm_id, int task_id, int step_id, int step_seqn) {
|
||||
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
insert_stmt.Clear().Val_int(fld_sm_id, sm_id).Val_int(fld_task_id, task_id).Val_int(fld_step_id, step_id).Val_int(fld_step_seqn, step_seqn)
|
||||
|
||||
@@ -56,6 +56,11 @@ public class Xobc_task_regy_tbl implements Db_tbl {
|
||||
try {return rdr.Move_next() ? rdr.Read_int(fld_task_id) : -1;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public String Select_key_by_id_or_null(int id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_task_id).Crt_int(fld_task_id, id).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? rdr.Read_str(fld_task_key) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Insert(int task_id, int task_seqn, int step_count, String task_key, String task_name) {
|
||||
if (insert_stmt == null) insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
insert_stmt.Clear().Val_int(fld_task_id, task_id).Val_int(fld_task_seqn, task_seqn).Val_int(fld_step_count, step_count)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*;
|
||||
import gplx.core.brys.evals.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Host_eval_itm {
|
||||
private final Bry_eval_mgr mgr = Bry_eval_mgr.Dflt();
|
||||
private final Host_eval_wkr wkr = new Host_eval_wkr();
|
||||
private final Hash_adp host_hash = Hash_adp_.New();
|
||||
public Host_eval_itm() {
|
||||
mgr.Add_many(wkr);
|
||||
}
|
||||
public byte[] Eval_dir_name(Xow_domain_itm domain_itm) {
|
||||
wkr.Domain_itm_(domain_itm);
|
||||
return mgr.Eval(Bry_.new_u8("Xowa_~{host_regy|wiki_abrv}_latest"));
|
||||
}
|
||||
public String Eval_src_fil(Xobc_data_db data_db, int host_id, Xow_domain_itm domain, String file_name) {
|
||||
return Eval_src_dir(data_db, host_id, domain) + file_name;
|
||||
}
|
||||
public String Eval_src_dir(Xobc_data_db data_db, int host_id, Xow_domain_itm domain) {
|
||||
Xobc_host_regy_itm host_itm = (Xobc_host_regy_itm)host_hash.Get_by(host_id);
|
||||
if (host_itm == null) {
|
||||
host_itm = data_db.Tbl__host_regy().Select(host_id);
|
||||
host_hash.Add(host_id, host_itm);
|
||||
}
|
||||
wkr.Domain_itm_(domain);
|
||||
String host_dir = String_.new_u8(mgr.Eval(Bry_.new_u8(host_itm.Host_data_dir())));
|
||||
return String_.Format("http://{0}/{1}/", host_itm.Host_domain(), host_dir);
|
||||
}
|
||||
}
|
||||
@@ -15,18 +15,23 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.brys.evals.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Bry_eval_wkr__host_regy implements Bry_eval_wkr {
|
||||
public class Host_eval_wkr implements Bry_eval_wkr {
|
||||
private Xow_domain_itm domain_itm;
|
||||
public String Key() {return "host_regy";}
|
||||
public Bry_eval_wkr__host_regy Domain_itm_(Xow_domain_itm domain_itm) {this.domain_itm = domain_itm; return this;}
|
||||
public Host_eval_wkr Domain_itm_(Xow_domain_itm domain_itm) {this.domain_itm = domain_itm; return this;}
|
||||
public void Resolve(Bry_bfr rv, byte[] src, int args_bgn, int args_end) {
|
||||
// EX: "~{host_regy|wiki_abrv}" -> "enwiki"
|
||||
int type = hash.Get_as_byte_or(src, args_bgn, args_end, Byte_.Max_value_127);
|
||||
switch (type) {
|
||||
case Type__wiki_abrv: rv.Add(domain_itm.Abrv_wm()); break;
|
||||
case Type__wiki_abrv:
|
||||
byte[] lang_key = domain_itm.Lang_orig_key();
|
||||
if (lang_key == Bry_.Empty) lang_key = Bry_.new_a7("en"); // handle species
|
||||
rv.Add(lang_key);
|
||||
rv.Add_str_a7("wiki");
|
||||
break;
|
||||
default: throw Err_.new_unhandled_default(type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Host_eval_wkr__tst {
|
||||
private final Host_eval_wkr__fxt fxt = new Host_eval_wkr__fxt();
|
||||
@Test public void En_w() {fxt.Test__resolve_quick("en.wikipedia.org" , "Xowa_enwiki_latest");}
|
||||
@Test public void Fr_d() {fxt.Test__resolve_quick("fr.wiktionary.org" , "Xowa_frwiki_latest");}
|
||||
@Test public void Species() {fxt.Test__resolve_quick("species.wikimedia.org" , "Xowa_enwiki_latest");}
|
||||
}
|
||||
class Host_eval_wkr__fxt {
|
||||
public void Test__resolve_quick(String domain_str, String expd) {
|
||||
Host_eval_itm eval_itm = new Host_eval_itm();
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
|
||||
Gftest.Eq__bry(Bry_.new_u8(expd), eval_itm.Eval_dir_name(domain_itm));
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.addons.bldrs.centrals.steps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.core.brys.evals.*; import gplx.core.primitives.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.tasks.*; import gplx.xowa.addons.bldrs.centrals.cmds.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.utils.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.hosts.*;
|
||||
import gplx.xowa.addons.bldrs.exports.merges.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xobc_step_factory {
|
||||
private final Xobc_task_mgr task_mgr;
|
||||
private final Xobc_data_db data_db;
|
||||
private final Bry_eval_mgr eval_mgr = Bry_eval_mgr.Dflt(), eval_mgr__host_regy = Bry_eval_mgr.Dflt();
|
||||
private final Bry_eval_wkr__host_regy eval_wkr__host_regy = new Bry_eval_wkr__host_regy();
|
||||
private final Bry_eval_mgr eval_mgr = Bry_eval_mgr.Dflt(); private final Host_eval_itm host_eval = new Host_eval_itm();
|
||||
private final Host_eval_wkr eval_wkr__host_regy = new Host_eval_wkr();
|
||||
public Xobc_step_factory(Xobc_task_mgr task_mgr, Xobc_data_db data_db, Io_url wiki_dir) {
|
||||
this.task_mgr = task_mgr;
|
||||
this.data_db = data_db;
|
||||
eval_mgr.Add_many(new Bry_eval_wkr__builder_central(wiki_dir));
|
||||
eval_mgr__host_regy.Add_many(eval_wkr__host_regy);
|
||||
}
|
||||
public void Load(Xobc_task_itm task, int step_id, int cmd_idx) {
|
||||
int step_type = data_db.Tbl__step_regy().Select_type(step_id);
|
||||
@@ -57,7 +56,7 @@ public class Xobc_step_factory {
|
||||
String file_name = import_itm.Import_name;
|
||||
step_name.Val_(file_name);
|
||||
eval_wkr__host_regy.Domain_itm_(domain_itm);
|
||||
String src_http_url = data_db.Bld_src_http_url(eval_mgr__host_regy, import_itm.Host_id, file_name);
|
||||
String src_http_url = host_eval.Eval_src_fil(data_db, import_itm.Host_id, domain_itm, file_name);
|
||||
Io_url zip_file_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__download_fil, wiki_domain, file_name));
|
||||
Io_url unzip_dir_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__unzip_dir, wiki_domain, file_name));
|
||||
Io_url wiki_dir_url = Eval_url(Bry_eval_wkr__builder_central.Make_str(Bry_eval_wkr__builder_central.Type__wiki_dir, wiki_domain, file_name));
|
||||
|
||||
@@ -18,11 +18,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Pack_file_bldr_cmd extends Xob_cmd__base {
|
||||
private Io_url deploy_dir;
|
||||
public Pack_file_bldr_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
@Override public void Cmd_run() {
|
||||
new Pack_file_mgr().Exec(wiki);
|
||||
new Pack_file_mgr().Exec(wiki, deploy_dir);
|
||||
}
|
||||
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__deploy_dir_)) deploy_dir = m.ReadIoUrl("v");
|
||||
else return super.Invk (ctx, ikey, k, m);
|
||||
return this;
|
||||
}
|
||||
private static final String Invk__deploy_dir_ = "deploy_dir_";
|
||||
|
||||
public static final String BLDR_CMD_KEY = "bldr.export.pack.file";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Pack_file_bldr_cmd(null, null);
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
|
||||
import gplx.core.progs.*; import gplx.core.ios.zips.*; import gplx.core.ios.streams.*; import gplx.core.security.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.fsdb.*; import gplx.fsdb.meta.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.steps.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.hosts.*;
|
||||
class Pack_file_mgr {
|
||||
public void Exec(Xowe_wiki wiki) {
|
||||
public void Exec(Xowe_wiki wiki, Io_url deploy_dir) {
|
||||
// init
|
||||
wiki.Init_assert();
|
||||
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
|
||||
@@ -53,6 +53,24 @@ class Pack_file_mgr {
|
||||
Make_task(tmp_bfr, wiki, wiki_date, bc_db, hash, "html", Xobc_import_type.Tid__wiki__core, Xobc_import_type.Tid__wiki__srch, Xobc_import_type.Tid__wiki__html);
|
||||
Make_task(tmp_bfr, wiki, wiki_date, bc_db, hash, "file", Xobc_import_type.Tid__file__core, Xobc_import_type.Tid__file__data);
|
||||
bc_conn.Txn_end();
|
||||
|
||||
// deploy
|
||||
if (deploy_dir != null) {
|
||||
Host_eval_itm host_eval = new Host_eval_itm();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Pack_list list = (Pack_list)hash.Get_at(i);
|
||||
int list_len = list.Len();
|
||||
for (int j = 0; j < list_len; ++j) {
|
||||
Pack_itm itm = (Pack_itm)list.Get_at(j);
|
||||
byte[] owner_dir = host_eval.Eval_dir_name(wiki.Domain_itm());
|
||||
Io_url src_url = itm.Zip_url();
|
||||
Io_url trg_url = deploy_dir.GenSubFil_nest(String_.new_u8(owner_dir), src_url.NameAndExt());
|
||||
Io_mgr.Instance.MoveFil_args(src_url, trg_url, true).Exec();
|
||||
}
|
||||
}
|
||||
Io_mgr.Instance.Delete_dir_empty(pack_dir);
|
||||
}
|
||||
}
|
||||
private static void Make_task(Bry_bfr tmp_bfr, Xow_wiki wiki, String wiki_date, Xobc_data_db bc_db, Pack_hash hash, String task_type, int... list_tids) {
|
||||
// get packs
|
||||
@@ -86,12 +104,15 @@ class Pack_file_mgr {
|
||||
}
|
||||
}
|
||||
public static String Build_task_name(Bry_bfr tmp_bfr, Xow_wiki wiki, String wiki_date, String task_type, long raw_len) {// Simple Wikipedia - Articles (2016-06) [420.31 MB]
|
||||
byte[] lang_name = gplx.xowa.langs.Xol_lang_stub_.Get_by_key_or_null(wiki.Domain_itm().Lang_orig_key()).Canonical_name(); // EX: Deutsch
|
||||
byte[] wiki_name = wiki.Domain_itm().Domain_type().Display_bry(); // EX: Wikipedia
|
||||
byte[] lang_key = wiki.Domain_itm().Lang_orig_key();
|
||||
byte[] lang_name = Bry_.Len_eq_0(lang_key) // species.wikimedia.org and other wikimedia wikis have no lang;
|
||||
? Bry_.Empty
|
||||
: Bry_.Add(gplx.xowa.langs.Xol_lang_stub_.Get_by_key_or_null(lang_key).Canonical_name(), Byte_ascii.Space); // EX: "Deutsch "
|
||||
byte[] wiki_name = wiki.Domain_itm().Domain_type().Display_bry(); // EX: Wikipedia
|
||||
String type_name = String_.Eq(task_type, "html") ? "Articles" : "Images";
|
||||
wiki_date = String_.Replace(wiki_date, ".", "-");
|
||||
String file_size = gplx.core.ios.Io_size_.To_str_new(tmp_bfr, raw_len, 2);
|
||||
return String_.Format("{0} {1} - {2} ({3}) [{4}]", lang_name, wiki_name, type_name, wiki_date, file_size);
|
||||
return String_.Format("{0}{1} - {2} ({3}) [{4}]", lang_name, wiki_name, type_name, wiki_date, file_size);
|
||||
}
|
||||
private static void Make_pack(Xowe_wiki wiki, Io_url wiki_dir, byte[] wiki_abrv, String wiki_date, Xobc_data_db bc_db, Hash_algo hash_algo, Bry_bfr tmp_bfr, Pack_itm itm, int task_id) {
|
||||
// hash raws
|
||||
|
||||
51
400_xowa/src/gplx/xowa/addons/bldrs/infos/Xobc_info_doc.java
Normal file
51
400_xowa/src/gplx/xowa/addons/bldrs/infos/Xobc_info_doc.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
class Xobc_info_doc implements Mustache_doc_itm {
|
||||
private final byte[] wiki_domain, task_size;
|
||||
private final String wiki_dir, torrent_fil;
|
||||
private final Mustache_doc_itm[] urls;
|
||||
public Xobc_info_doc(byte[] wiki_domain, String wiki_dir, byte[] task_size, String torrent_fil, Mustache_doc_itm[] urls) {
|
||||
this.wiki_domain = wiki_domain; this.wiki_dir = wiki_dir; this.task_size = task_size; this.torrent_fil = torrent_fil; this.urls = urls;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "wiki_domain")) bfr.Add_bry(wiki_domain);
|
||||
else if (String_.Eq(key, "wiki_dir")) bfr.Add_str_u8(wiki_dir);
|
||||
else if (String_.Eq(key, "task_size")) bfr.Add_bry(task_size);
|
||||
else if (String_.Eq(key, "torrent_fil")) bfr.Add_str_u8(torrent_fil);
|
||||
return false;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "urls")) return urls;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
class Xobc_info_url implements Mustache_doc_itm {
|
||||
private final String url; private final byte[] size;
|
||||
public Xobc_info_url(String url, byte[] size) {
|
||||
this.url = url; this.size = size;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "url")) bfr.Add_str_u8(url);
|
||||
else if (String_.Eq(key, "size")) bfr.Add_bry(size);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {return Mustache_doc_itm_.Ary__empty;}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.*; import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.hosts.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.core.ios.*;
|
||||
class Xobc_info_html extends Xow_special_wtr__base {
|
||||
private final Xobc_task_mgr task_mgr;
|
||||
private final int task_id;
|
||||
public Xobc_info_html(Xobc_task_mgr task_mgr, int task_id) {this.task_mgr = task_mgr; this.task_id = task_id;}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "bldr", "info");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xobc_info.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
// get steps for task
|
||||
Xobc_data_db data_db = task_mgr.Data_db();
|
||||
List_adp list = data_db.Tbl__step_map().Select_all(task_id);
|
||||
|
||||
// get underlying files
|
||||
Host_eval_itm host_eval = new Host_eval_itm();
|
||||
int len = list.Len();
|
||||
Xobc_info_url[] step_urls = new Xobc_info_url[len];
|
||||
Xow_domain_itm wiki_domain = null;
|
||||
int host_id = -1;
|
||||
long total_size = 0;
|
||||
Bry_bfr tmp_size_bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int step_id = (int)list.Get_at(i);
|
||||
Xobc_import_step_itm step_itm = data_db.Tbl__import_step().Select_one(step_id);
|
||||
if (i == 0) {
|
||||
wiki_domain = Xow_abrv_xo_.To_itm(step_itm.Wiki_abrv()); // ASSUME: 1st step's wiki is same for all steps
|
||||
host_id = step_itm.Host_id; // ASSUME: 1st step's host_id is same for all steps
|
||||
}
|
||||
String src_fil = host_eval.Eval_src_fil(data_db, host_id, wiki_domain, step_itm.Import_name);
|
||||
Io_size_.To_bfr_new(tmp_size_bfr, step_itm.Import_size_zip, 2);
|
||||
total_size += step_itm.Import_size_raw;
|
||||
Xobc_info_url step_url = new Xobc_info_url(src_fil, tmp_size_bfr.To_bry_and_clear());
|
||||
step_urls[i] = step_url;
|
||||
}
|
||||
|
||||
// get wiki data, total_size
|
||||
host_eval.Eval_dir_name(wiki_domain);
|
||||
Io_url trg_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(wiki_domain.Domain_str());
|
||||
Io_size_.To_bfr_new(tmp_size_bfr, total_size, 2);
|
||||
byte[] total_size_bry = tmp_size_bfr.To_bry_and_clear();
|
||||
|
||||
// get torrent
|
||||
String torrent_fil = null;
|
||||
String key = data_db.Tbl__task_regy().Select_key_by_id_or_null(task_id);
|
||||
if (key == null) torrent_fil = "failed to get torrent for " + Int_.To_str(task_id);
|
||||
else {// convert task_key to name; en.wikipedia.org|2016.06|html
|
||||
String src_dir = host_eval.Eval_src_dir(data_db, host_id, wiki_domain);
|
||||
String[] ary = String_.Split(key, "|");
|
||||
ary[0] = String_.new_u8(wiki_domain.Abrv_wm());
|
||||
torrent_fil = String_.Format("{0}/Xowa_{1}_{2}_{3}.torrent", src_dir, ary[0], ary[1], ary[2]); // EX: http://archive.org/download/Xowa_enwiki_latest/Xowa_enwiktionary_2016-06_core.zip
|
||||
}
|
||||
|
||||
return new Xobc_info_doc
|
||||
( wiki_domain.Domain_bry()
|
||||
, trg_dir.Raw()
|
||||
, total_size_bry
|
||||
, torrent_fil
|
||||
, step_urls
|
||||
);
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xobc_info.css")));
|
||||
}
|
||||
@Override protected void Handle_invalid(Xoa_app app, Xoa_page page, Xow_special_page special) {
|
||||
new Xopage_html_data(special.Special__meta().Display_ttl(), Bry_.new_u8("task has been deleted")).Apply(page);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.*;
|
||||
public class Xobc_info_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
|
||||
int task_id = url_args.Read_int_or("task_id", -1);
|
||||
if (task_id == -1) return;
|
||||
|
||||
new Xobc_info_html(Xobc_task_special.Task_mgr(wiki.App()), task_id).Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
|
||||
Xobc_info_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xobc_info_special(Xow_special_meta.New_xo("XowaDownloadCentralInfo", "Download Central Task Info"));
|
||||
}
|
||||
Reference in New Issue
Block a user