123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125openCommontypesubsystem=SubSystemofstringtypedir=Dirofstringletstring_of_subsystem(SubSystems)=sletstring_of_dir(Dirs)=stypetree_reorganization=(subsystem*dirlist)listletdir_to_dirfinal(Dirs)=Str.global_replace(Str.regexp"/")"___"s(*
let dirfinal_of_dir s =
Dir (Str.global_replace (Str.regexp "___") "/" s)
*)letall_subsystemreorg=reorg|>List.mapfst|>List.mapstring_of_subsystemletall_dirsreorg=reorg|>List.mapsnd|>List.concat|>List.mapstring_of_dirletreverse_indexreorg=letres=ref[]inreorg|>List.iter(fun(SubSystems1,dirs)->dirs|>List.iter(fun(Dirs2)->push(Dirs2,SubSystems1)res;););List.rev!reslet(load_tree_reorganization:Common.filename->tree_reorganization)=funfile->letxs=Simple_format.title_colon_elems_space_separatedfileinxs|>List.map(fun(title,elems)->SubSystemtitle,elems|>List.map(funs->Dirs))letdebug_source_tree=falseletchange_organization_dirs_to_subsystemsreorgbasedir=letcmds=ifdebug_source_treethenpr2selseCommon.command2sinreorg|>List.iter(fun(SubSystemsub,dirs)->ifnotdebug_source_treethenCommon2.mkdir(spf"%s/%s"basedirsub);dirs|>List.iter(fun(Dirdir)->letdir'=dir_to_dirfinal(Dirdir)incmd(spf"mv %s/%s %s/%s/%s"basedirdirbasedirsubdir')););()letchange_organization_subsystems_to_dirsreorgbasedir=letcmds=ifdebug_source_treethenpr2selseCommon.command2sinreorg|>List.iter(fun(SubSystemsub,dirs)->dirs|>List.iter(fun(Dirdir)->letdir'=dir_to_dirfinal(Dirdir)incmd(spf"mv %s/%s/%s %s/%s"basedirsubdir'basedirdir));ifnotdebug_source_treethenUnix.rmdir(spf"%s/%s"basedirsub););()let(change_organization:tree_reorganization->Common.filename(* dir *)->unit)=funreorgdir->pr2_genreorg;pr2_gendir;letsubsystem_bools=all_subsystemreorg|>List.map(funs->(Sys.file_exists(Filename.concatdirs)))inletdirs_bools=all_dirsreorg|>List.map(funs->(Sys.file_exists(Filename.concatdirs)))inmatch()with|_whenCommon2.and_listsubsystem_bools->assert(not(Common2.or_listdirs_bools));change_organization_subsystems_to_dirsreorgdir;|_whenCommon2.and_listdirs_bools->assert(not(Common2.or_listsubsystem_bools));change_organization_dirs_to_subsystemsreorgdir;|_->failwith"have a mix of subsystem and dirs, wierd"letsubsystem_of_dir2(Dirdir)reorg=letindex=reverse_indexreorginletdirsplit=Common.split"/"dirinletindex=index|>List.map(fun(Dird,sub)->Common.split"/"d,sub)intryindex|>List.find(fun(dirsplit2,_sub)->letlen=List.lengthdirsplit2inCommon2.take_safelendirsplit=dirsplit2)|>sndwithNot_found->pr2(spf"Cant find %s in reorganization information"dir);raiseNot_foundletsubsystem_of_dirab=Common.profile_code"subsystem_of_dir"(fun()->subsystem_of_dir2ab)