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

Add append/remove subcommands to bin/omero config #1905

Closed
wants to merge 16 commits into from

Conversation

sbesson
Copy link
Member

@sbesson sbesson commented Dec 16, 2013

This PR addresses https://trac.openmicroscopy.org.uk/ome/ticket/11201

Changes included are:

  • addition of bin/omero config append and bin/omero config remove so that configuration using lists of strings can easily be manipulated, e.g.

    bin/omero config append omero.web.apps webfigure
    bin/omero config append omero.web.apps webtagging
    …
    bin/omero config remove omero.web.apps webfigure
    
  • addition of corresponding unit tests under test_prefs.py

/cc @dpwrussell, @will-moore, @manics

append = parser.add(
sub, self.append, "Append value to a key in the current profile.")
remove = parser.add(
sub, self.remove, "Append value to a key in the current profile.")
Copy link
Member

Choose a reason for hiding this comment

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

Should say "remove" instead of "append"

@sbesson
Copy link
Member Author

sbesson commented Dec 17, 2013

Last commits should fix the help/descriptions across all bin/omero config subcommands so that

  • bin/omero config -h and bin/omero config <command> -h both display the subcommand description
  • NAME, KEY, and value arguments have a proper description

load.set_defaults(func=self.load)
load = parser.add(
sub, self.load,
"Read into current profile from a file or standard in")
Copy link
Member

Choose a reason for hiding this comment

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

"standard input" perhaps, may as well expand both if at all

@joshmoore
Copy link
Member

@knabar : do you want to take an initial look at this?

@knabar
Copy link
Member

knabar commented Jan 15, 2014

Types are handled inconsistently:

$ omero config set x [1]
$ omero config append x 2
$ omero config get x
[1, '2']
$ omero config append x "'3'"
[1, '2', "'3'"]

Should values passed to append and remove be interpreted as JSON, just like values passed to set and get?

@sbesson
Copy link
Member Author

sbesson commented Jan 16, 2014

@knabar: agreed. There is a discrepancy between set/get and append/remove subcommands at the moment. My initial goal was to allow simple commands such as

bin/omero config append omero.web.apps omero.searcher

to be correctly interpreted. I will add commits to unify the behaviour with the existing config subcommands.

@sbesson
Copy link
Member Author

sbesson commented Jan 23, 2014

@knabar: fixed in 91fafda

@knabar
Copy link
Member

knabar commented Jan 23, 2014

Values passed to append still seem to always be interpreted as strings, even when they are not quoted.

$ omero config set x 1
$ omero config get x
[1]
$ omero config append x 2
[1, "2"]     <-- expected [1, 2]
$ omero config append x '"3"'
[1, "2", "\"3\""]    <-- expected [1, 2, "3"]

@sbesson
Copy link
Member Author

sbesson commented Jan 23, 2014

With the latest change, I now have

$ bin/omero config --source ~/config.xml set x '["1"]'
$ bin/omero config --source ~/config.xml get x
["1"]
$ bin/omero config --source ~/config.xml append x 2
$ bin/omero config --source ~/config.xml append x "3"
$ bin/omero config --source ~/config.xml append x '"4"'
$ bin/omero config --source ~/config.xml get x
["1", 2, 3, "4"]

@knabar
Copy link
Member

knabar commented Jan 23, 2014

Works as expected now.

$ omero config set x [1]
$ omero config append x [2]
$ omero config get x
[1, [2]]
$ omero config set x [1]
$ omero config append x 2
$ omero config append x '"3"'
$ omero config get x
[1, 2, "3"]
$ omero config set x '[{"a":"b"}]'
$ omero config append x '{"c":99}'
$ omero config get x
[{"a": "b"}, {"c": 99}]

@sbesson
Copy link
Member Author

sbesson commented Jan 23, 2014

OK here's the next question for you @knabar

bin/omero config append x 1
bin/omero config append x 1
bin/omero config remove x 1

Are we expecting x to be unset or [1] (current behaviour)?

@knabar
Copy link
Member

knabar commented Jan 23, 2014

Two issues here:

  • I think remove should always only remove the first matching element
  • Once the last element is removed, should it be an empty list (my vote) or become unset?

@manics
Copy link
Member

manics commented Jan 24, 2014

It depends on whether we're going to change the handling of default values in future. omero.web.ui.right_plugins is a good example:

  • unset implies '[["Acquisition",...],["Preview",...]]'
  • [] implies no tabs at all

So at present if I want to add omero_searcher to omero.web.ui.right_plugins I'll have to specify the entire list '[["Acquisition",...],["Preview",...],["Searcher",...]]',unfortunately a simple config append won't work in this situation. In the case of omero.web.apps unset implies [] anyway, so it doesn't matter, both cases work the same way. So I guess it should be []. With an RFE from me for better handling of the omero.web.ui.right_plugins default unset case.

@knabar
Copy link
Member

knabar commented Jan 24, 2014

Going to [] also keeps it symmetrical: since you cannot append to an unset value, removing the last element from a list should not go to unset. Also, you can undo any remove by running the corresponding append again (apart from the item order in the list possibly).

@sbesson
Copy link
Member Author

sbesson commented Jan 24, 2014

Note at the moment, appending to an unset value is possible as I thought the following would be not ideal:

bin/omero config set omero.web.apps []
bin/omero config append omero.web.apps '"webfigure"'

But I can revert this possibility if that's the general consensus. @will-moore: any strong feeling about the last removal discussion? If you are okay with @manics and @knabar, I can push an extra commit that sets [] as the result of the final removal.

@manics
Copy link
Member

manics commented Jan 24, 2014

Note at the moment, appending to an unset value is possible as I thought the following would be not ideal
...

Hmmm, good point. I guess the ideal situation would be for append to append to the default values if it's unset, but I imagine that's not possible without significant changes to the web config system.

@will-moore
Copy link
Member

I want to test this myself, but haven't had time to build latest server yet...
But it would be nice if you could do this (one set of quotes).

bin/omero config append omero.web.apps "webfigure"

@will-moore
Copy link
Member

I think that removing the last item should give you an empty list (not unset).
But everything changes if we could take into account the default settings.
E.g. you might want to...

# remove all the existing right plugins
omero config set omero.web.ui.right_plugins []
# add just your own
omero config append omero.web.ui.right_plugins '["Tagging"...]'
# now you want to go back to the 3 defaults (unset)
omero config set omero.web.ui.right_plugins
# now you want to add a 4th plugin to the 3 defaults
omero config append omero.web.ui.right_plugins '["Tagging"...]'

So this would be different from the 'appending to unset value' that we have now.
But that's OK I think.

@joshmoore
Copy link
Member

Hmmm, good point. I guess the ideal situation would be for append to append to the default values if it's unset, but I imagine that's not possible without significant changes to the web config system.

I've wondered if we don't want to "extend" the bin/omero config command with bin/omero web-config (or whatever) to take the existing settings into account. Certainly, what web is doing with config.xml is somewhat different from the earlier intent (since it's only used locally, not remotely)

@manics
Copy link
Member

manics commented Jan 24, 2014

👍 Would make web configuration a lot easier.

- Update corresponding unit tests
- Add test for removal of multi-defined item
@joshmoore
Copy link
Member

Sorry, previous comment was a misunderstanding. This was "No JSON object" when setting 'a'.

@joshmoore
Copy link
Member

@knabar : I assume this is feature complete in terms of #2028. Does the fact that the defaults are now being read change the requirement for remove to go to an empty list rather than unset?

@knabar
Copy link
Member

knabar commented Jan 29, 2014

@joshmoore It should probably still go to an empty list. If you remove all the default elements one by one, it would be counter-intuitive if they pop all back up once the last element is removed.

@sbesson
Copy link
Member Author

sbesson commented Jan 29, 2014

Seconding @knabar's answer. Arguably, we could simply extend Andrea's testRemoveWithDefault to remove all items and make sure the property go to an empty list.

@sbesson
Copy link
Member Author

sbesson commented Jan 30, 2014

Closing in favour of #2030

@sbesson sbesson closed this Jan 30, 2014
@sbesson sbesson deleted the 11201_config branch February 4, 2014 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants