[Pkg-ocaml-maint-commits] r3927 - /trunk/projects/dh-make-ocaml/trunk/opkg-inject
gildor at users.alioth.debian.org
gildor at users.alioth.debian.org
Thu Jul 5 21:00:44 UTC 2007
Author: gildor
Date: Thu Jul 5 21:00:44 2007
New Revision: 3927
URL: http://svn.debian.org/wsvn/?sc=1&rev=3927
Log:
* Add an old script -- maybe useful
Added:
trunk/projects/dh-make-ocaml/trunk/opkg-inject (with props)
Added: trunk/projects/dh-make-ocaml/trunk/opkg-inject
URL: http://svn.debian.org/wsvn/trunk/projects/dh-make-ocaml/trunk/opkg-inject?rev=3927&op=file
==============================================================================
--- trunk/projects/dh-make-ocaml/trunk/opkg-inject (added)
+++ trunk/projects/dh-make-ocaml/trunk/opkg-inject Thu Jul 5 21:00:44 2007
@@ -1,0 +1,230 @@
+#!/usr/bin/ocamlrun /usr/bin/ocaml
+
+#use "topfind";;
+#require "str";;
+#require "unix";;
+
+let get_source_version base_dir =
+ let spaces = "[ \\t]"
+ in
+ let str_blank = Str.regexp ("^"^spaces^"*$")
+ in
+ let str_version = Str.regexp (
+ "^"^spaces^"*"^
+ "\\([a-z0-9\\+\\.\\-]*\\)"^
+ spaces^"*"^
+ "(\\([a-z0-9\\+\\.\\-]*\\)).*$"
+ )
+ in
+ let rec extract_information fd =
+ let line = input_line fd
+ in
+ if Str.string_match str_blank line 0 then
+ extract_information fd
+ else if Str.string_match str_version line 0 then
+ ((Str.matched_group 1 line), (Str.matched_group 2 line))
+ else
+ raise Not_found
+ in
+ let fd =
+ (* print_endline ("Examining "^(Filename.concat base_dir "debian/changelog")); *)
+ open_in (Filename.concat base_dir "debian/changelog")
+ in
+ let (package,version) = extract_information fd
+ in
+ close_in fd;
+ (package,version)
+
+let get_package_version base_dir =
+ let (source,version) = get_source_version base_dir
+ in
+ let str_package = Str.regexp (
+ "^Package:[ \\t]*\\([a-z0-9\\+\\.\\-]*\\).*$"
+ )
+ in
+ let rec extract_information fd =
+ try
+ let line = input_line fd
+ in
+ if Str.string_match str_package line 0 then
+ begin
+ let str = Str.matched_group 1 line
+ in
+ str :: (extract_information fd)
+ end
+ else
+ begin
+ (extract_information fd)
+ end
+ with End_of_file ->
+ []
+ in
+ let fd =
+ (*print_endline ("Examining "^(Filename.concat base_dir "debian/control"));*)
+ open_in (Filename.concat base_dir "debian/control")
+ in
+ let package = extract_information fd
+ in
+ close_in fd;
+ (package,version)
+
+type find = NotAtAll | Package | Version
+
+let get_dpkg_source_version dpkg_file package =
+ let str_version = Str.regexp (
+ "^Version:[ \\t]*\\([a-z0-9\\+\\.\\-]*\\)"
+ )
+ in
+ let str_package = Str.regexp (
+ "^Package:[ \\t]*"^( Str.quote package )
+ )
+ in
+ let result = ref "(not_found)"
+ in
+ let find = ref NotAtAll
+ in
+ let rec find_version_information fd =
+ try
+ while !find <> Version do
+ let line = input_line fd
+ in
+ if !find = Package && Str.string_match str_version line 0 then
+ begin
+ result := Str.matched_group 1 line;
+ find := Version
+ end
+ else if !find = NotAtAll && Str.string_match str_package line 0 then
+ begin
+ find := Package
+ end
+ else
+ ()
+ done;
+ !result
+ with End_of_file ->
+ !result
+ in
+ let fd =
+ (*print_endline ("dpkg-query --print-avail "^package);*)
+ open_in dpkg_file
+ in
+ let version = find_version_information fd
+ in
+ close_in fd;
+ version
+
+let get_svn_info_base_svn base_dir =
+ let str_url = Str.regexp (
+ "^URL: \\(.*\\)$"
+ )
+ in
+ let rec extract_information fd =
+ try
+ let line = input_line fd
+ in
+ if Str.string_match str_url line 0 then
+ Str.matched_group 1 line
+ else
+ extract_information fd
+ with End_of_file ->
+ raise Not_found
+ in
+ let fd =
+ (*print_endline ("svn info "^base_dir);*)
+ Unix.open_process_in ("svn info "^base_dir)
+ in
+ let base_svn = extract_information fd
+ in
+ ignore(Unix.close_process_in fd);
+ base_svn
+
+let get_svn_tags base_dir =
+ let base_svn = get_svn_info_base_svn base_dir
+ in
+ let rec extract_information fd =
+ try
+ let line = input_line fd
+ in
+ line :: (extract_information fd)
+ with End_of_file ->
+ []
+ in
+ let fd =
+ (*print_endline ("svn list "^base_svn^"/../tags");*)
+ Unix.open_process_in ("svn list "^base_svn^"/../tags")
+ in
+ let tags = extract_information fd
+ in
+ ignore(Unix.close_process_in fd);
+ tags
+
+type action = CheckTags | Inject
+
+let doit action base_svn dpkg_file base_dir =
+ try
+ match action with
+ Inject ->
+ begin
+ let (source,version) = get_source_version base_dir
+ in
+ ignore (Sys.command ("svn import "^(base_dir)^" "^(base_svn)^"/"^source^"/trunk"));
+ ignore (Sys.command ("svn mkdir "^(base_svn)^"/"^source^"/tags"))
+ end
+ | CheckTags ->
+ begin
+ if dpkg_file <> "" then
+ let (source,version) = get_source_version base_dir
+ in
+ let main_version = get_dpkg_source_version dpkg_file source
+ in
+ let tags = get_svn_tags base_dir
+ in
+ print_string (source^" : ");
+ begin
+ if List.mem (main_version^"/") tags then
+ print_string ("Version "^main_version^" in the repository is tagged.")
+ else
+ print_string ("Tags on current version "^main_version^" is not tagged ( [ "
+ ^(String.concat " ; " tags)
+ ^" ] ).")
+ end;
+ begin
+ if main_version <> version then
+ print_string ("Source version "^version^" is not in the repository")
+ else
+ print_string ("Source version is in the repository")
+ end;
+ print_newline ()
+ else
+ failwith "No dpkg file given"
+ end
+ with Sys_error s ->
+ print_endline s
+
+let _ =
+ let action = ref CheckTags
+ in
+ let base_svn = ref "svn+ssh://pkg-ocaml-maint.alioth.debian.org/svn/pkg-ocaml-maint/packages"
+ in
+ let base_dir = ref []
+ in
+ let dpkg_file = ref ""
+ in
+ let _ = Arg.parse [
+ ("--action", Arg.Symbol(
+ ["inject";"check-tags"],
+ ( fun symb ->
+ match symb with
+ "inject" -> action := Inject
+ | "check-tags" -> action := CheckTags
+ | _ -> ()
+ )), "Choose action to perfom (inject,check-tags)");
+ ("--base-svn", Arg.Set_string base_svn, "Base svn to use when injecting package");
+ ("--dpkg-file", Arg.Set_string dpkg_file, "File to search for source version")
+ ]
+ ( fun s -> base_dir := s :: !base_dir )
+ "Opkg by Sylvain Le Gall -- Version 0.1"
+ in
+ List.iter (doit !action !base_svn !dpkg_file) !base_dir;
+ print_newline ()
+
Propchange: trunk/projects/dh-make-ocaml/trunk/opkg-inject
------------------------------------------------------------------------------
svn:executable = *
More information about the Pkg-ocaml-maint-commits
mailing list