Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handling for more file fields in GetAppmenus #12

Merged
merged 2 commits into from
Aug 28, 2019

Conversation

marmarta
Copy link
Member

@marmarta marmarta commented Jun 5, 2019

Adding the optional --file-field parameter. It changes to output format
to '|'-separated one, and outputs not only file name and app name, but
also whatever fields from the file the user has requested. Used by
GUI VM settings.

references QubesOS/qubes-issues#5076

marmarta added a commit to marmarta/qubes-manager that referenced this pull request Jun 5, 2019
The 'Comment' field will not be displayed as a tooltip in VM settings.
Requires QubesOS/qubes-desktop-linux-common#12

references QubesOS/qubes-issues#5076
marmarta added a commit to marmarta/qubes-manager that referenced this pull request Jun 5, 2019
The 'Comment' field will now be displayed as a tooltip in VM settings.
Requires QubesOS/qubes-desktop-linux-common#12

references QubesOS/qubes-issues#5076
if fields:
for field in fields:
if line.startswith(field + '=') or\
line.startswith(field + ' ='):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space handling around = looks wrong, especially since partition() call below doesn't do that. Better use line.split('=', 1) and strip spaces from result

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a fix

else:
for result in appmenus.get_available(
vm, fields=args.fields):
print(' | '.join(result))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the separate one character. Multi-character field separators may lead to various corner cases (for example how to interpret a | | b).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a fix

marmarta added a commit to marmarta/qubes-manager that referenced this pull request Jun 10, 2019
The 'Comment' field will now be displayed as a tooltip in VM settings.
Requires QubesOS/qubes-desktop-linux-common#12

references QubesOS/qubes-issues#5076
break
if fields:
for field in fields:
if line.split('=', 1)[0].strip().startswith(field):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for startswith() instead of simple comparison? It will match other fields with common prefix. If that's for handling languages (like Comment[de]), I'd suggest printing them only when explicitly requested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a fix

for field in fields:
if line.split('=', 1)[0].strip().startswith(field):
field_values[field] = \
line.partition(field + '=')[2].strip()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here you'll drop other field anyway. And also, this method of splitting fields is inconsistent with the if - this one will fail if there is a space before = (not a problem in practice, as the code writing it doesn't put one here, but better fix it anyway).
IMO better to split it only once and save to same variables, to be sure it's handled consistently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a fix

@@ -575,6 +584,9 @@ def appmenus_update(self, vm, force=False):
help='required pledge for --get-available')
parser.add_argument('domains', metavar='VMNAME', nargs='+',
help='VMs on which perform requested actions')
parser.add_argument('--file-field', action='append', dest='fields',
help='File field to append to output for --get-available; can be used'
' multiple times for multiple fields')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add info that this option change output format too. Preferably in manual page, if there would be one... But for now a note here would do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a manpage

Adding the optional --file-field parameter. It changes to output format
to '|'-separated one, and outputs not only file name and app name, but
also whatever fields from the file the user has requested. Used by
GUI VM settings.

references QubesOS/qubes-issues#5076
A simple man page that describes all the available options with a bit
more detail than --help option.
@marmarek marmarek merged commit c532de9 into QubesOS:master Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants