txt publish <id>; file and convert to standard dirs
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@6 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
2
cli/dune
2
cli/dune
@@ -1,5 +1,5 @@
|
||||
(executable
|
||||
(name txt)
|
||||
(public_name txt)
|
||||
(modules txt authors convert conversion file index last listing new topics html atom gemini pull)
|
||||
(modules txt authors convert conversion file index last listing new topics html atom gemini publish pull)
|
||||
(libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner))
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
let split_filetypes files =
|
||||
let acc (dirs, files) x = if Sys.is_directory x
|
||||
then (x::dirs, files) else (dirs, x::files) in
|
||||
List.fold_left acc ([],[]) files
|
||||
|
||||
open Logarion
|
||||
let file files =
|
||||
let dirs, files = split_filetypes files in
|
||||
let dirs, files = File_store.split_filetypes files in
|
||||
let _link_as_named dir file = Unix.link file (Filename.concat dir file) in
|
||||
let link_with_id dir file =
|
||||
match File_store.to_text file with Error s -> prerr_endline s
|
||||
@@ -14,7 +9,7 @@ let file files =
|
||||
List.iter (fun d -> List.iter (link d) files) dirs
|
||||
|
||||
let unfile files =
|
||||
let dirs, files = split_filetypes files in
|
||||
let dirs, files = File_store.split_filetypes files in
|
||||
let unlink dir file = try Unix.unlink (Filename.concat dir file)
|
||||
with Unix.(Unix_error(ENOENT,_,_))-> () in
|
||||
List.iter (fun d -> List.iter (unlink d) files) dirs
|
||||
|
||||
30
cli/publish.ml
Normal file
30
cli/publish.ml
Normal file
@@ -0,0 +1,30 @@
|
||||
let targets () =
|
||||
let home =
|
||||
try Sys.getenv "txtpubdir" with Not_found ->
|
||||
try Sys.getenv "HOME" with Not_found -> ""
|
||||
in
|
||||
List.filter
|
||||
(fun x -> try Sys.is_directory (snd x) with Sys_error _ -> false)
|
||||
[
|
||||
"htm", home ^ "/public/html";
|
||||
"gmi", home ^ "/public/gemini";
|
||||
"", home ^ "/public/gopher";
|
||||
]
|
||||
|
||||
open Logarion
|
||||
let publish ids =
|
||||
let predicate t = List.mem t.Text.id ids in
|
||||
let targets = targets () in
|
||||
let pub_dirs = List.map (fun x -> snd x) targets in
|
||||
try File_store.iter ~predicate (fun (_t, p) -> File.file ((List.hd p)::pub_dirs))
|
||||
with Unix.Unix_error (Unix.EEXIST, _, _) -> ();
|
||||
List.iter (fun t ->
|
||||
Index.((load (snd t)) false None None None None);
|
||||
Convert.convert_dir (fst t) false (snd t))
|
||||
targets
|
||||
|
||||
open Cmdliner
|
||||
let term =
|
||||
let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
|
||||
let doc = "convert texts into standart public dirs public_{html,gemini,gopher} if they exists" in
|
||||
Term.(const publish $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
|
||||
@@ -14,6 +14,7 @@ let () = match Term.eval_choice default_cmd [
|
||||
Last.term;
|
||||
Listing.term;
|
||||
New.term;
|
||||
Publish.term;
|
||||
Pull.term;
|
||||
Topics.term;
|
||||
] with `Error _ -> exit 1 | _ -> exit 0
|
||||
|
||||
Reference in New Issue
Block a user