pulp/pulp_rpm — pull request #176 by jdob (2013-04-10 14:28:11+00:00)
Title: CLI changes for sort index fields

The first two entries are the tech reference guide changes so Katello knows how to generate and use the sort index fields.

The rest is kinda tricky to read. Let me start with a general approach.

The CriteriaCommand has methods split out for handling each sort of parsing it needs to do. One is the _parse_key_value method that splits apart an argument like "--match name=foo" into a tuple of "name" and "foo". That provided a great hook for me to intercept any uses of the word "version", replace it with "version_sort_index" and encode the specified value. Same for release.

So what's happening is that the user types:

--match version=3.10

And in the RPM/SRPM commands, the _parse_key_value is overridden to translate the returned tuple into:

(version_sort_index, 01-3.02-10)

The user never has to know about the sort indexes or the encoding, but underneath the covers the behavior is correct.

A similar hook exists for sorting, the _parse_sort method. The same premise applies, it's just a bit simpler. We don't even need to encode the value, simply translate the attribute name. So:

--sort release,ascending

becomes:

(release_sort_index, ascending)

The two methods that do that are in criteria_utils (with test_criteria_utils), which is ultimately the real meat of this pull request.

The rest of the changes are to introduce a subclass layer below our standard commands that overrides _parse_key_value and _parse_sort and calls out to the ones in criteria_utils. This is only done for RPM/SRPM ones, intentionally not for things like distribution and errata. The implementation varied slightly due to some minor differences in the standard commands, but conceptually the approach is the same.

Below is a screenshot of the changes:

= Before =
```
$ pulp-admin rpm repo content rpm --repo-id vtest --fields name,version --sort version, ascending
Name: foo
Version: 3.1

Name: foo
Version: 3.10

Name: foo
Version: 3.11

Name: foo
Version: 3.9
```

= After =
```
$ pulp-admin rpm repo content rpm --repo-id vtest --fields name,version --sort version,ascending
Name: foo
Version: 3.1

Name: foo
Version: 3.9

Name: foo
Version: 3.10

Name: foo
Version: 3.11
```