Ticket #66 (assigned task)
Introduce a python func to compute a version "weigth" in order to sort software on their versions
| Reported by: | nrueff | Owned by: | nrueff |
|---|---|---|---|
| Priority: | Low | Milestone: | 1.4.0 |
| Component: | python-mmc-glpi | Version: | |
| Severity: | Major | Keywords: | |
| Cc: |
Description
Taken from dpkg --compare-versions:
static int verrevcmp(const char *val, const char *ref) {
if (!val) val= "";
if (!ref) ref= "";
while (*val || *ref) {
int first_diff= 0;
while ( (*val && !cisdigit(*val)) || (*ref && !cisdigit(*ref)) ) {
int vc= order(*val), rc= order(*ref);
if (vc != rc) return vc - rc;
val++; ref++;
}
while ( *val == '0' ) val++;
while ( *ref == '0' ) ref++;
while (cisdigit(*val) && cisdigit(*ref)) {
if (!first_diff) first_diff= *val - *ref;
val++; ref++;
}
if (cisdigit(*val)) return 1;
if (cisdigit(*ref)) return -1;
if (first_diff) return first_diff;
}
return 0;
}
--compare-versions ver1 op ver2
Compare version numbers, where op is a binary operator. dpkg returns success (zero result) if the specified condition is satisfied, and failure (nonzero result) otherwise. There are two groups of operators, which differ in how they treat an empty ver1 or ver2. These treat an empty version as earlier than any version: lt le eq ne ge gt. These treat an empty version as later than any ver-sion: lt-nl le-nl ge-nl gt-nl. These are provided only for compatibility with control file syntax: < << <= = >= >> >.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

