Browse Source

first release

master 0.0.1
zapashcanon 3 years ago
parent
commit
113bc4d094
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 72
      .build.yml
  2. 3
      CHANGES.md
  3. 34
      dune-project
  4. 42
      so.opam
  5. 42
      src/common.ml
  6. 19
      src/dune
  7. 45
      src/so.ml
  8. 10
      src/soe.ml
  9. 4
      test/config
  10. 4
      test/dune
  11. 11
      test/test.ml

72
.build.yml

@ -2,14 +2,82 @@ image: debian/unstable
packages:
- opam
- ocaml
- curl
sources:
- https://git.zapashcanon.fr/zapashcanon/so
environment:
name: so
deploy: fs@zapashcanon.fr
sshopts: "-o StrictHostKeyChecking=no -q"
coverage_dst: /var/www/coverage.zapashcanon.fr
doc_dst: /var/www/doc.zapashcanon.fr
archive_dst: /var/www/fs.zapashcanon.fr/archive
secrets:
- ec1f49cd-38dc-41d9-89f4-c3b6ecd7bcad # ssh deploy key
- b5b0e36c-fe52-43c4-9103-0aa918ad175c # github token
- c9e55d80-7b6a-4ad4-81bd-921d2c3247b8 # dune release profile
- ff8575b8-7192-4e0c-9905-6d04142a4ec1 # git config
tasks:
- setup: |
opam init -y
opam update -y
opam install -y dune ocaml-xdg-basedir
opam install -y dune bisect_ppx odoc ocamlformat ocaml-xdg-basedir
- lint-format: |
cd $name
eval "$(opam env)"
ocamlformat -p ocamlformat --enable-outside-detected-project --check $(find . -name '*.ml')
- build: |
cd $name
eval "$(opam env)"
cd so
dune build @all
- test: |
cd $name
eval "$(opam env)"
dune runtest
- deploy-doc: |
cd $name
eval "$(opam env)"
dune build @doc
ssh $sshopts $deploy "mkdir -p $doc_dst/$name/"
scp $sshopts -r _build/default/_doc/_html/* $deploy:$doc_dst/$name/
- deploy-coverage: |
cd $name
eval "$(opam env)"
dune clean
BISECT_ENABLE=YES dune runtest --no-buffer --force > /dev/null
bisect-ppx-report -html _coverage/ "$(find . -name 'bisect*.out')"
ssh $sshopts $deploy "mkdir -p $coverage_dst/$name/"
scp $sshopts -r _coverage/* $deploy:$coverage_dst/$name/
- archive: |
cd $name
eval "$(opam env)"
dune clean
archive_name=${name}-dev.tar.xz
git archive -o $archive_name HEAD
ssh $sshopts $deploy "mkdir -p $archive_dst/$name/"
scp $sshopts $archive_name $deploy:$archive_dst/$name/
rm $archive_name
- release: |
cd $name
eval "$(opam env)"
git describe --exact-match || exit 0
opam install -y dune-release
tag=$(git describe --exact-match)
dune-release distrib || true
archive_name=${name}-${tag}.tbz
ls _build/${archive_name}
scp $sshopts _build/${archive_name} $deploy:$archive_dst/$name/
url="https://fs.zapashcanon.fr/archive/${name}/${archive_name}"
echo $url > _build/${name}-${tag}.url
dune-release opam pkg
opam_file=_build/${name}.${tag}/opam
line_num="$(grep -n -e 'src:' $opam_file | cut -d: -f1)"
sed -i -e "${line_num}s|^.*| src: \"${url}\"|" $opam_file
line_num=$(($line_num + 1))
sed -i -e "${line_num}d" $opam_file
sed -i -e "${line_num}d" $opam_file
cd ..
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
git clone https://github.com/Cameleo/opam-repository.git
cd $name
dune-release opam submit --no-auto-open -y

3
CHANGES.md

@ -0,0 +1,3 @@
## 0.0.1 - 2019-11-26
First release

34
dune-project

@ -1,5 +1,35 @@
(lang dune 1.11)
(lang dune 2.0)
(name so)
(explicit_js_mode)
(license ISC)
(authors "Léo Andrès <contact@ndrs.fr>")
(maintainers "Léo Andrès <contact@ndrs.fr>")
(source
(uri git://git.zapashcanon.fr/zapashcanon/so.git))
(bug_reports https://git.zapashcanon.fr/zapashcanon/so/issues)
(homepage https://git.zapashcanon.fr/zapashcanon/so)
(documentation https://doc.zapashcanon.fr/so/)
(generate_opam_files true)
(package
(name so)
(synopsis "Open file depending on their extension")
(description
"Command line tool to quickly open file depending on their extension.")
(depends
(ocaml
(>= 4.05))
(dune
(>= 2.0))
(bisect_ppx
(>= 1.4))
(ocaml-xdg-basedir
(>= 0.0.3))))

42
so.opam

@ -1,26 +1,32 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Command line tool to quickly open file depending on their extension"
version: "dev"
synopsis: "Open file depending on their extension"
description:
"Command line tool to quickly open file depending on their extension."
maintainer: ["Léo Andrès <contact@ndrs.fr>"]
authors: ["Léo Andrès <contact@ndrs.fr>"]
license: "ISC"
homepage: "https://git.zapashcanon.fr/zapashcanon/so"
doc: "https://doc.zapashcanon.fr/so/"
bug-reports: "https://git.zapashcanon.fr/zapashcanon/so/issues"
authors: "Léo Andrès (zapashcanon) <leo@ndrs.fr>"
maintainer: "Léo Andrès (zapashcanon) <leo@ndrs.fr>"
dev-repo: "git+https://git.zapashcanon.fr/zapashcanon/so.git"
depends: [
"ocaml"
"dune"
"ocaml-xdg-basedir"
"ocaml" {>= "4.05"}
"dune" {>= "2.0"}
"bisect_ppx" {>= "1.4"}
"ocaml-xdg-basedir" {>= "0.0.3"}
]
build: [
["dune" "build" "-p" name "-j" jobs]
["dune" "subst"] {pinned}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
description: """
Command line tool to quickly open file depending on their extension.
"""
dev-repo: "git://git.zapashcanon.fr/zapashcanon/so.git"

42
src/common.ml

@ -0,0 +1,42 @@
let error s = Format.eprintf "%s@." s ; exit 1
let check_file () =
if Array.length Sys.argv <> 2 then
error (Format.sprintf "usage: %s <file>" Sys.argv.(0)) ;
let file = Sys.argv.(1) in
if not (Sys.file_exists file) then
error (Format.sprintf "file %s doesn't exist" file) ;
file
let check_config_file () =
let config_file = XDGBaseDir.default.config_home ^ "/so/config" in
if not (Sys.file_exists config_file) then
error (Format.sprintf "config file %s doesn't exist" config_file) ;
config_file
let load_config_file config_file =
let chan = open_in config_file in
let tbl = Hashtbl.create 2048 in
( try
while true do
let line = input_line chan in
match String.split_on_char ':' line with
| [prog; exts] ->
let prog = String.trim prog in
let exts = String.split_on_char ' ' exts in
List.iter
(fun el -> if el <> "" then Hashtbl.add tbl ("." ^ el) prog)
exts
| _ ->
error (Format.sprintf "parse error in config file %s" config_file)
done
with End_of_file -> close_in chan ) ;
tbl
let find_cmd file tbl =
let ext = Filename.extension file in
match Hashtbl.find tbl ext with
| exception Not_found ->
"xdg-open"
| prog ->
prog

19
src/dune

@ -1,3 +1,20 @@
(library
(name common)
(modules common)
(libraries xdg-basedir)
(preprocess
(pps bisect_ppx -conditional)))
(executable
(public_name so)
(libraries xdg-basedir))
(modules so)
(libraries common)
(preprocess
(pps bisect_ppx -conditional)))
(executable
(public_name soe)
(modules soe)
(libraries common)
(preprocess
(pps bisect_ppx -conditional)))

45
src/so.ml

@ -1,43 +1,10 @@
let error s =
Format.eprintf "%s@." s;
exit 1
open Common
let _ =
if Array.length Sys.argv <> 2 then error (Format.sprintf "usage: %s <file>" Sys.argv.(0));
let file = Sys.argv.(1) in
if not (Sys.file_exists file) then error (Format.sprintf "file %s doesn't exist" file);
let config_file = XDGBaseDir.default.config_home ^ "/so/config" in
if not (Sys.file_exists config_file) then error (Format.sprintf "config file %s doesn't exist" config_file);
let chan = open_in config_file in
let tbl = Hashtbl.create 2048 in
begin try while true do
let line = input_line chan in
match String.split_on_char ':' line with
| prog::exts::[] ->
let prog = String.trim prog in
let exts = String.split_on_char ' ' exts in
List.iter (fun el -> if el <> "" then Hashtbl.add tbl ("." ^ el) prog) exts;
| _ -> error (Format.sprintf "parse error in config file %s" config_file)
done with End_of_file -> close_in chan
end;
let ext = Filename.extension file in
let cmd = match Hashtbl.find tbl ext with
| exception Not_found -> "xdg-open"
| prog -> prog
in
let config_file = check_config_file () in
let tbl = load_config_file config_file in
let file = check_file () in
let cmd = find_cmd file tbl in
let cmd = Format.sprintf "setsid %s %s" cmd (Filename.quote file) in
(* Format.printf "%s@." cmd; *)
ignore (Sys.command cmd);
ignore (Sys.command cmd)

10
src/soe.ml

@ -0,0 +1,10 @@
open Common
let _ =
let config_file = check_config_file () in
let tbl = load_config_file config_file in
let file = check_file () in
let cmd = find_cmd file tbl in
let cmd = Format.sprintf "setsid %s %s && exit" cmd (Filename.quote file) in
(* Format.printf "%s@." cmd; *)
ignore (Sys.command cmd)

4
test/config

@ -0,0 +1,4 @@
eog : png jpg
evince : pdf
firefox : html
mpv : mp4 avi

4
test/dune

@ -0,0 +1,4 @@
(test
(name test)
(libraries common)
(deps config))

11
test/test.ml

@ -0,0 +1,11 @@
open Common
let _ =
let tbl = load_config_file "./config" in
let file = "sava.avi" in
let cmd = find_cmd file tbl in
assert (cmd = "mpv") ;
let file = "savapas.fjeklsfhjkfhsek" in
let cmd = find_cmd file tbl in
assert (cmd = "xdg-open") ;
Format.printf "Tests are OK !@."
Loading…
Cancel
Save