inv-query¶
Synopsis¶
sr inv-query [-h] [--codes] [--paths] [-v] <query>
Description¶
Run a query on the inventory.
Making Queries¶
Currently, there are 3 types of expressions: equality/match, membership
and function. The equality/match expression takes the form
KEY (':' | '=' | 'is') VALUE. The membership expression takes the form
KEY 'in' '{' VALUE (',' VALUE)* '}'. The function expression takes the
form FUNCTION 'of' EXPR, where EXPR is another valid expression.
Supported keys¶
- Code
Match on a part code.
Keys: codeValues: a valid SR part code, with or without the srprefixExample: code:srEEN- Serial
Match on a serial number.
Keys: serialValues: a valid serial number Example: serial:D851F850- Condition
Match on the condition of a part/assembly. An assembly is considered
workingif and only if all expected sub-parts are consideredworking. If any sub-part isbrokenor missing, the assembly isbroken. If any sub-part isunknownand the assembly is notbrokenthen the assembly isunknown.Keys: condition,condValues: working,unknown,brokenExample: condition is working- Labelled
Match based on how labelled a part is.
Keys: labelledValues: true,falseExample: labelled=true- Type or name of part
Match on the name of a part/assembly. Python’s
fnmatchis used, and it uses glob-like syntax. Basic usage: ‘*’ matches any character, any number of times;?matches a single character;[ab]matches one of the charactersaorb.Keys: typeValues: a glob-like pattern Examples: type:power*, for all parts whose name begins with ‘power’- Path
Match on the path to the part in the inventory. Python’s
fnmatchis used here too, but with an implicit*at the end. This makes path searching more intuitive.Keys: pathValues: a valid glob-like pattern Example: path:vault, for all parts under any path, relative to the inventory root, that begins with ‘vault’- Assembly
Match based on whether a part/assembly is an assembly or not.
Keys: assyValues: true,falseExample: assy:true
Logic¶
AND, OR, and NOT are all supported. NOT may be abreviated to
!. When two expressions appear side-by-side with no operator (AND, or
OR) between them, AND is assumed, e.g. a b is equivalent to
a AND b. These keywords are not case insensitive.
One may also use parenthetic expressions.
Function Expressions¶
Function expressions currently allow one to map the list of matches (from
the input expression) using some named function. The current functions are:
parent, siblings, children, and descendants. For example,
parent of type:power-board-sr13.f will return the parent nodes of sr13
power boards. (Note that this particular example doesn’t guarantee the
parents are assemblies, they could be boxes for example. One can fix this
by adding assy:true.) Function expressions bind tighter than AND, so
parent of type:power-board-sr13.f AND assy:true, with parentheses for
clarity, means (parent of type:power-board-sr13.f) AND assy:true.
Examples¶
cond:working- returns all working parts and assemblies.type is *power*- returns parts that match that glob pattern (power boards and assys, power supplies, etc…).!path:vault- returns items not under paths starting withvault.path:vault !cond:working- returns the things in the vault that are notworking(note the implicitAND).cond:working AND (path:bees OR path:face)- returns working things inbees*or inface*. This could be simplified with the membership syntax:cond:working AND path in {bees*, face*}type in {motor-board-sr11.f, motor-board-sr13.f}- returns all of our motor boards. In this case, a glob pattern could be used to shorten it:type:motor-board-sr1[13].f.descendants of code:srBOX and cond:broken- return all the broken things in srBOX.siblings of code:srABC- things at the same level in the hierarchy as srABC.
Options¶
| --help, -h | Display help and exit. |
| --codes | Display the results as a list of asset codes. |
| --paths | Display the results as a list of paths. |
| -v | Enable verbose mode. |
Examples¶
$ sr inv-query code:N1V36
/.../teams/2015/crb/box-18l-rub-sr0G64/webcam-logitech-c270-srN1V36