mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.4.1'
This commit is contained in:
60
400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl_.java
Normal file
60
400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl_.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xob_io_utl_ {
|
||||
public static void Delete_sql_files(Io_url wiki_dir, String sql_file_name) {
|
||||
Delete_by_wildcard(wiki_dir, sql_file_name + ".sql", ".gz", ".sql");
|
||||
}
|
||||
public static void Delete_by_wildcard(Io_url dir, String name_pattern, String... ext_ary) {
|
||||
List_adp list = Find_by_wildcard(Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry(), name_pattern, ext_ary);
|
||||
int len = list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Io_url url = (Io_url)list.Get_at(i);
|
||||
Io_mgr.Instance.DeleteFil(url);
|
||||
}
|
||||
}
|
||||
public static Io_url Find_nth_by_wildcard_or_null(Io_url dir, String name_pattern, String... ext_ary) {
|
||||
return Find_nth_by_wildcard_or_null(Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry(), name_pattern, ext_ary);
|
||||
}
|
||||
public static Io_url Find_nth_by_wildcard_or_null(Io_url[] fil_ary, String name_pattern, String... ext_ary) {
|
||||
List_adp list = Find_by_wildcard(fil_ary, name_pattern, ext_ary);
|
||||
int list_len = list.Len();
|
||||
return list_len == 0 ? null : (Io_url)list.Get_at(list_len - 1);
|
||||
}
|
||||
public static List_adp Find_by_wildcard(Io_url[] fil_ary, String name_pattern, String... ext_ary) {
|
||||
List_adp rv = List_adp_.New();
|
||||
|
||||
// create ext_hash
|
||||
Ordered_hash ext_hash = Ordered_hash_.New();
|
||||
for (String ext : ext_ary)
|
||||
ext_hash.Add(ext, ext);
|
||||
|
||||
// iterate fil_ary
|
||||
for (Io_url fil : fil_ary) {
|
||||
// file matches pattern
|
||||
if ( name_pattern == Pattern__wilcard // empty String means match anything
|
||||
|| String_.Has(fil.NameAndExt(), name_pattern)) { // name has name_pattern; EX: "enwiki-latest-pages-articles-current.xml" and "pagelinks"
|
||||
if ( ext_hash.Len() == 0 // empty hash means match any ext
|
||||
|| ext_hash.Has(fil.Ext())) // ext exists in hash
|
||||
rv.Add(fil);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final String Pattern__wilcard = String_.Empty;
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java
Normal file
43
400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xob_io_utl__tst {
|
||||
private final Xob_io_utl__fxt fxt = new Xob_io_utl__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b", String_.Ary(".txt"), "b.txt");
|
||||
}
|
||||
@Test public void Include__ext() {// PURPOSE: handle calls like "a.sql", ".sql", ".gz"
|
||||
fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b.txt", String_.Ary(".txt"), "b.txt");
|
||||
}
|
||||
@Test public void Dupe__pick_last() {
|
||||
fxt.Test__match(String_.Ary("b0.txt", "b1.txt", "b2.txt"), "b", String_.Ary(".txt"), "b2.txt");
|
||||
}
|
||||
@Test public void Ext() {
|
||||
fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".xml", ".bz2"), "b.xml");
|
||||
}
|
||||
@Test public void Ext__dupes() {
|
||||
fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".txt", ".xml"), "b.xml");
|
||||
}
|
||||
}
|
||||
class Xob_io_utl__fxt {
|
||||
public void Test__match(String[] path_ary, String name_pattern, String[] ext_ary, String expd) {
|
||||
Io_url actl = Xob_io_utl_.Find_nth_by_wildcard_or_null(Io_url_.Ary(path_ary), name_pattern, ext_ary);
|
||||
Gftest.Eq__str(expd, actl == null ? "<<NULL>>" : actl.Raw());
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public abstract class Xob_sql_dump_base extends Xob_itm_dump_base implements Xob
|
||||
this.Init_dump(this.Cmd_key());
|
||||
make_url_gen = Io_url_gen_.dir_(temp_dir.GenSubDir("make"));
|
||||
if (src_fil == null) {
|
||||
src_fil = Xotdb_fsys_mgr.Find_file_or_null(wiki.Fsys_mgr().Root_dir(), "*" + Sql_file_name() + "*", ".gz", ".sql");
|
||||
src_fil = Xob_io_utl_.Find_nth_by_wildcard_or_null(wiki.Fsys_mgr().Root_dir(), Sql_file_name() + ".sql", ".gz", ".sql");
|
||||
if (src_fil == null) {
|
||||
String msg = String_.Format(".sql file not found in dir.\nPlease download the file for your wiki from dumps.wikimedia.org.\nfile={0} dir={1}", Sql_file_name(), wiki.Fsys_mgr().Root_dir());
|
||||
app.Usr_dlg().Warn_many("", "", msg);
|
||||
|
||||
Reference in New Issue
Block a user