ringgono / python-for-android

Automatically exported from code.google.com/p/python-for-android
Apache License 2.0
0 stars 0 forks source link

Missing module grp #13

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Setup a terminal with Python env variables set and python in path.
1.Download Mercurial source to sdcard and extract.
2.CD to source directory and run "python ./setup.py --pure build" to build a 
pure python version of Mercurial. (Note: fails while building extensions 
because of missing Makefile in 
"/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/config".
3.Manually copy modules from build directory into a dir in $PYTHONPATH.
4.In a directory you want to version control type "hg init" (works), type "hg 
status" (works), type "hg commit" (error: no module named grp).
5.Complain about missing grp module at pythonforandroid!

What is the expected output? What do you see instead?
Expected Mercurial to ask for a commit message.

What version of the product are you using? On what operating system?
PY4A r16, Python 2.6.2 (r262:71600, Mar 20 2011, 16:54:21) on linux-armv71

Please provide any additional information below.

I'm trying to get Mercurial --pure to run on android, but when I try to commit 
it complains about a missing a module. It would be very handy for me to sync my 
repo back and forth with my phone for testing and desktop editing!
I feel like I'm very close to having this working, but I don't have an Android 
cross-compiler environment setup to build this one module. It would be great if 
someone with such a setup made a full build of Mercurial too...

Original issue reported on code.google.com by kitsu...@gmail.com on 16 May 2011 at 10:53

GoogleCodeExporter commented 8 years ago
Hi there, sorry but this will never work. Android API doesn't provide with grp 
support on the base libraries (there's no group/user management in bionic)

You will have to hack Mercurial or use a different source manager.

Original comment by naranjo....@gmail.com on 17 May 2011 at 1:04

GoogleCodeExporter commented 8 years ago

Original comment by naranjo....@gmail.com on 17 May 2011 at 1:04

GoogleCodeExporter commented 8 years ago
I see. I guess that makes sense. I'll see if I can hack a fake replacement 
then. I'm not sure what hg is using the module for, but it can't be very 
important on a single user system.

Original comment by kitsu...@gmail.com on 17 May 2011 at 3:35

GoogleCodeExporter commented 8 years ago
Just for anyone who finds this, I did get hg working somewhat after some 
hacking.
Mercurial is checking the user/group ownership of files against its own trusted 
list (in Mercurial/ui.py). On Linux the code it uses for the check is in 
'$PYTHON_PATH/Mercurial/posix.py'. It first checks if user isowner(file) before 
checking groups etc. By adding a try block that imports android and returns 
True to the top of the function you can short-circuit all the other tests.

I also built a dummy module replacing grp, but with the above change I think it 
could have been empty and still worked.

I still had a problem 'commit'ing but it looks like now it's just a problem 
finding an editor(did you know hg has a --traceback flag?). Using the -m 
MESSAGE flag let me commit and push successfully pushed my changeset to 
bitbucket!

Original comment by kitsu...@gmail.com on 17 May 2011 at 10:03

GoogleCodeExporter commented 8 years ago
Can you provide your Mercurial/ui.py changes so I can ignore grp module checks?

Original comment by yuk...@gmail.com on 23 Aug 2012 at 8:10

GoogleCodeExporter commented 8 years ago
for comment 5 above, try providing an empty grp.py file instead. I.e. Leave the 
Mercurial code alone.

Original comment by clac...@gmail.com on 24 Aug 2012 at 1:17

GoogleCodeExporter commented 8 years ago
Took me a while to re-find it.
In file ui.py from line 41:
def _is_trusted(self, fp, f):
    try:
        import android
        return True
    except ImportError:
        pass
    ...

In file posix.py from line 10
import os, sys, errno, stat, getpass, pwd
try:
    import android
except ImportError:
    import grp

The first skips the grp check, the second avoids the import exception for 
non-existent grp module.

Original comment by kitsu...@gmail.com on 25 Aug 2012 at 4:41

GoogleCodeExporter commented 8 years ago
Which files did you copy over manually? Is it obvious? In 
mercurial-2.x.x/mercurial I see several .c files as well as folders. There is 
also mercurial-2.x.x/pure which had .py versions. Soobvipusly replacing those 
does the trick. But any others? Thx. PS see my post on 
poquitopicante.blogspot.com on installing distribute.

Original comment by bwanama...@gmail.com on 5 Apr 2013 at 9:37

GoogleCodeExporter commented 8 years ago
* I used the blank grp.py module, that worked fine. I actually put it in my 
scripts folder - ha!
* I copied the entire mercurial/ folder into site-packages. I already had add 
site-packages to path by using sitecustomize.py in 
com.googlecode.pythonforandroid/extras/python/.
* The actual commit I used was #5b7175377bab 
(http://selenic.com/hg/rev/5b7175377bab) which is tagged as 2.5.2 stable.
* I copied everything from mercurial/pure/ into mercurial/, and I left the *.c 
files (base85.c, bdiff.c, diffhelpers.c, mpatch.c, osutil.c and parsers.c). The 
__init__.py files are both empty so it makes no difference. (note: I tried 
putting `from pure import *` in mercurial/__init__.py and `__all__=['base85', 
'bdiff', 'diffhelpers', 'mpatch', 'osutil', 'parsers'] in 
mercurial/pure/__init__.py, but that did not work)
* I also copied hgext/ to site-packages
* I copied hg to $EXTERNAL_STORAGE/sl4a/scripts and renamed it hg.py so it 
shows in the sl4a app script browser. Running it returns the help. yay!
* using standalone python script called python.sh and shell interpreter, I can 
also do hg init  

    sh python.sh hg.py init <target>  

* clone gives me issues in mercurial/util.py (780) calls copymode in posix.py 
(122) which uses os.chmod, but I am sdcard mounted with fuse fs and I can't 
change permissions - so I add:  

    try:
        os.chmod(...)
    except OSError:
        print 'blah'  

to pass it. The same exact thing happens in journal.py (817) which calls 
transaction.py (61). Again in util.py (856) and again in setflags again 
posix.py (104) and (109). I use the same try-except block to pass the errors. 
This will probably cause issues later. There is another os.chmod() in posix 
near line 159, but it already has a try-except block around it and if it fails 
it doesn't care.
* I can clone remote repositories now. Now pushing will be another matter.
* use hg --traceback <command> to troubleshoot issues.

Original comment by bwanama...@gmail.com on 9 Apr 2013 at 12:00

GoogleCodeExporter commented 8 years ago
btw: if you don't want to deal with the stoopid sdcard fs, and you do NOT have 
root, just create a folder called files in 
/data/data/com.googlecode.android_scripting/ and put your repos there. As long 
as you use the sl4a shell interpreter you always have full permissions there 
because you are the owner of that folder. You can also make executables there, 
if you should so desire, e.g.: `chmod 755 <file>` without root. true.

Original comment by bwanama...@gmail.com on 9 Apr 2013 at 12:04