Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 932750 - Add helper methods to GaiaData to get and set Gecko prefs #13644

Merged
merged 1 commit into from Nov 19, 2013
Merged

Bug 932750 - Add helper methods to GaiaData to get and set Gecko prefs #13644

merged 1 commit into from Nov 19, 2013

Conversation

bobsilverberg
Copy link
Contributor

Also fixed a couple of PEP8 issues.

@@ -183,6 +183,12 @@ def set_setting(self, name, value):
result = self.marionette.execute_async_script('return GaiaDataLayer.setSetting("%s", %s)' % (name, value), special_powers=True)
assert result, "Unable to change setting with name '%s' to '%s'" % (name, value)

def get_pref(self, datatype, name):
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than passing the type, can we use type to infer it? http://docs.python.org/2/library/functions.html#type

Copy link

Choose a reason for hiding this comment

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

that would be nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a couple of issues with this:

  1. We are passing the datatype as expected for the JS function, so boolean is actually bool and interger/numeric is actually int. I did this to avoid having to have the translation logic in the get_pref method.
  2. We are passing exactly what we want passed to the JS method as the value, so if I want to pass true, I pass 'true' as opposed to the Python True, so I'm not sure if type inference would even work in these situations.

I might be able to get it to work, but it would mean a lot more code in get_pref, so I prefer (pun inetnded) to keep things simple and just have the consumer pass the expected datatype.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, my comment was on the wrong method anyway, it only makes sense to do this on set_pref... I see your points and in that case would prefer we map the JavaScript methods, and have get_int_pref, set_int_pref, etc. Passing the types as string arguments just doesn't seem safe to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to avoid that at first, but now I see it makes perfect sense. If you're going to have to pass the datatype anyway, why not just call the correct method? I will fix it, and add char too.

@bebef1987
Copy link
Contributor

@bobsilverberg can you add some dock about prefs and what's the diff between setting and prefs

@bobsilverberg
Copy link
Contributor Author

I updated the unit tests to use a unique pref which we can set and then get, and also added some docs to the new methods.

@bobsilverberg
Copy link
Contributor Author

I've updated the PR to include separate methods for Bool, Int and Char.

@AndreiH
Copy link

AndreiH commented Nov 15, 2013

tests pass both on device and desktop
and code lgtm 👍

@bobsilverberg
Copy link
Contributor Author

I have updated this yet again. Sorry folks.

@bebef1987
Copy link
Contributor

I feel like having separate methods for the data types might be misleading...

How about simple get / set methods and the user should specify the data type?

@bebef1987
Copy link
Contributor

disregard my previous comment (Bad ideea)

zacc pushed a commit that referenced this pull request Nov 19, 2013
Bug 932750 - Add helper methods to GaiaData to get and set Gecko prefs
@zacc zacc merged commit 42de07a into mozilla-b2g:master Nov 19, 2013
@bobsilverberg bobsilverberg deleted the gecko_prefs branch November 28, 2013 02:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants