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

tzlocal.get_localzone fails on Termux #55

Merged
merged 2 commits into from
May 31, 2019
Merged

Conversation

jean
Copy link
Contributor

@jean jean commented Apr 10, 2018

https://termux.com/ offers a full Linux userland on Android without rooting.
However the Android version of Linux is a bit "special". It doesn't have /etc/localtime.
Using tzlocal 1.5.1:

$ python
Python 2.7.14 (default, Jan  7 2018, 04:01:39)
[GCC 4.2.1 Compatible Android Clang 5.0.300080 ] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tzlocal
>>> tzlocal.get_localzone()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/data/com.termux/files/home/git/trellowarrior/lib/python2.7/site-packages/tzlocal/unix.py", line 131, in get_localzone
    _cache_tz = _get_localzone()
  File "/data/data/com.termux/files/home/git/trellowarrior/lib/python2.7/site-packages/tzlocal/unix.py", line 125, in _get_localzone
    raise pytz.UnknownTimeZoneError('Can not find any timezone configuration')
pytz.exceptions.UnknownTimeZoneError: 'Can not find any timezone configuration'

In this environment, this works to get the timezone (that's calling /system/bin/getprop):

$ getprop persist.sys.timezone
Asia/Manila

Termux has a wrapper for getprop:

```
unset LD_LIBRARY_PATH LD_PRELOAD
PATH=$PATH:/system/bin exec /system/bin/getprop "$@"
```

I couldn't figure out how to mimic that wrapper using Python's `subprocess`.
With this fix, `tzlocal` work under Termux:

```
$ python
Python 3.6.4 (default, Jan  7 2018, 03:53:53)
[GCC 4.2.1 Compatible Android Clang 5.0.300080 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tzlocal
>>> tzlocal.get_localzone()
<DstTzInfo 'Asia/Manila' LMT+8:04:00 STD>
```
Copy link
Owner

@regebro regebro left a comment

Choose a reason for hiding this comment

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

Well, why not. :-)

Could you add yourself to the contributors in README.txt, and add this change to CHANGES.txt?

I can't come up with a good way to test it, though.

@jean
Copy link
Contributor Author

jean commented Apr 11, 2018

Done :-)
I'll ask the Termux crowd if they have suggestions for testing.

@jean
Copy link
Contributor Author

jean commented Apr 22, 2018

@regebro beep (I haven't heard anything useful for testing)

@regebro
Copy link
Owner

regebro commented Aug 15, 2018

Merged

@regebro regebro closed this Aug 15, 2018
@alensiljak
Copy link

alensiljak commented Nov 20, 2018

In which version is this supposed to be released? I have tzlocal 1.5.1 as the latest on Termux and still getting the UnknownTimeZoneError. Thanks!
Edit: I see that it has been merged after 1.5.1 so hopefully one of the later versions gets published soon enough.

@regebro
Copy link
Owner

regebro commented Nov 21, 2018

It's not, because I could not get much information. So in short, at the moment, Android isn't supported.
Since we now have had people who want to use it on Android, perhaps it's time to support it. But it would be good if we could get an actual Android developer to help, I've never done anything with it.

@regebro regebro reopened this Nov 21, 2018
@alensiljak
Copy link

Sebastien, the author of piecash, was kind enough to provide a workaround which includes manually setting the TZ variable in the bash profile. That can be used for the moment.

I am not an Android developer per se but I'm trying out crazy things, like distributing a Flask web app through Pypi to an Android phone and running it there in Termux. So, if I can help in any way, I certainly would.

@regebro regebro merged commit 37b49de into regebro:master May 31, 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.

None yet

3 participants