Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file criteria.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(**************************************************************************************)(* Copyright (C) 2009 Pietro Abate <pietro.abate@pps.jussieu.fr> *)(* Copyright (C) 2009 Mancoosi Project *)(* *)(* This library is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as *)(* published by the Free Software Foundation, either version 3 of the *)(* License, or (at your option) any later version. A special linking *)(* exception to the GNU Lesser General Public License applies to this *)(* library, see the COPYING file for more information. *)(**************************************************************************************)openExtLibopenCriteria_typesmodulePcre=Re_pcreincludeUtil.Logging(structletlabel="dose_common.criteria"end)letlexbuf_wrappertype_parserv=Format822.lexbuf_wrappertype_parserCriteria_lexer.tokenvletparse_criteriav=lexbuf_wrapperCriteria_parser.criteria_topv(* Cudf field names are much more restrictive than deb822 field names which
is why the deb822 field name has to be sanitized.
The first eight hex chars of the md5sum of the fieldname, the match type
and the search string are appended because:
- sanitizing deb822 field names might make them not unique anymore
- regexp may contain mostly special characters that would otherwise all
be deleted, creating a non-unique field name
- regexp might be very long but cutting of the regex might make the
result non-unique
- a hash solves all these problems because it contains only valid
characters while being unique for any input (minus unlikely collisions)
Cudf properties are identifiers as per cudf spec and must start with
a lowercase latin letter, followed by lowercase latin letters, dashes
or arabic numerals and must be of length one or greater.
We restrict ourselves to US ASCII characters because checking for
latin characters would be hard. We also ignore the length restriction
and the special restriction for the beginning of a property because
our new field below automatically has a sufficient length and starts
with a lowercase latin character because of the "x-" prefix *)letinvalidchars=Pcre.regexp"[^0-9a-z-]"(* replace all possibly illegal letters by a dash
Get the first eight hex digits of the md5sum of the fieldname, the match
type and the search string.
*)letmakefield?(sep="=")fieldnameregex=letregexhash=lets=fieldname^sep^regexinString.sub(Digest.to_hex(Digest.strings))08inletsanitizes=lets=String.lowercasesinPcre.substitute~rex:invalidchars~subst:(fun_->"-")sinPrintf.sprintf"x-%s-%s"(sanitizefieldname)regexhashletis_misc2012=function|"mccs-cbc"|"mccs-lpsolve"->false|"aspcud"|"packup"->true|_->true(* we assume true by default *)letto_string?(solver="dumb")criteria=letpr=Printf.sprintfinletstring_of_set=function|Solution->"solution"|Changed->"changed"|New->"new"|Removed->"removed"|Up->"up"|Down->"down"inifis_misc2012solverthenletl=List.map(funpred->let(pred,crit)=matchpredwithMaximizes->("+",s)|Minimizes->("-",s)inletcritstr=matchcritwith|Count(set,None)->pr"count(%s)"(string_of_setset)|Count(set,Some(field,r))->let(sep,r)=matchrwithExactMatchr->("=",r)|Regexpr->("~",r)inpr"sum(%s,%s)"(string_of_setset)(makefield~sepfieldr)|Sum(set,attr)->pr"sum(%s,%s)"(string_of_setset)attr|Unsatrecset->pr"unsat_recommends(%s)"(string_of_setset)|Aligned(set,attr1,attr2)->pr"aligned(%s,%s,%s)"(string_of_setset)attr1attr2|NotUptodateset->pr"notuptodate(%s)"(string_of_setset)inpred^critstr)criteriainString.concat","lelsefatal"Solver Specific Optimizations (%s) are not recognized."solver(* compile the regex so that this doesn't need to be done later *)(* TODO: the regex should probably be multiline? *)letiterf=List.iter(function|Minimize(Count(_,Some(fieldname,regex)))|Maximize(Count(_,Some(fieldname,regex)))->let(regexstring,sep,compiled_re)=matchregexwith|Regexpr->(r,"~",Some(Pcre.regexpr))|ExactMatchr->(r,"=",None)inletcudffieldname=makefield~sepfieldnameregexstringinf(cudffieldname,fieldname,regexstring,compiled_re)|_->())letdefault_criteria=letminnew=Minimize(Count(New,None))inletminrem=Minimize(Count(Removed,None))inletminupto=Minimize(NotUptodateSolution)inletminch=Minimize(Count(Changed,None))inletminunsat=Minimize(UnsatrecSolution)in[("upgrade",[minnew;minrem;minupto]);("dist-upgrade",[minupto;minnew]);("install",[minrem;minch]);("remove",[minrem;minch]);("paranoid",[minrem;minch]);("trendy",[minrem;minupto;minunsat;minnew])]