issue #23

MakeHuman python API, python plugins, etc

Moderator: joepal

issue #23

Postby joepal » Wed Mar 10, 2010 9:43 am

I've been thinking about finally fixing issue 23:

http://code.google.com/p/makehuman/issues/detail?id=23

However, there are three ways one could do that, and I'd like input on which to go for before submitting anything.

The first approach is adding this line in the top of __init__() in main.py

Code: Select all
os.chdir(os.path[0])
'

Which is a quick and easy solution, but which changes the working directory. This might have unforeseen consequences if we ever want to use the makehuman binary for command line stuff like piping.

The second approach is to modify all data loading lines so that for example:

Code: Select all
self.scene3d.selectedHuman.setTexture("data/textures/texture.tif")


becomes

Code: Select all
self.scene3d.selectedHuman.setTexture(os.path[0] + "/data/textures/texture.tif")


Unfortunately, bug #23 is present in every single location where anything is loaded. It is everywhere simply assumed that working directory is the one containing the makehuman binary. Thus this'd lead to many, many code changes.

A third, slightly more beautiful approach would be to modify all file access methods in all classes so they properly take into account what the working directory is and compensate for it. Then the previous example would be:

Code: Select all
self.scene3d.selectedHuman.setTexture("texture.tif")


.. and inside setTexture(), the file would be prepended with os.path[0] + "/data/textures/". This approach would require some planning and also probably many code changes. It might also lead to unforeseen consequences if one forgets to change stuff somewhere.

In any which way, I'm currently favoring the first approach since it'd be a minimal code intervention.

Comments?
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4473
Joined: Wed Jun 04, 2008 11:20 am

Re: issue #23

Postby joepal » Tue Mar 16, 2010 4:22 pm

I changed my mind. I think this should end up in main.c instead.

Proposed patch:

Code: Select all
52a53,55
> /* for dirname() */
> #include <libgen.h>
>
565a569,579
> // start change to solve issue #23
> char *dirc, *basec, *bname, *dname;
> char *path = argv[0];
> dirc = strdup(path);
> basec = strdup(path);
> dname = dirname(dirc);
> bname = basename(basec);
> printf("dirname=%s, basename=%s\n", dname, bname);
> chdir(dname);
> // end change for issue #23
>


Please review before I commit, since I'm kind of noob on C programming. :)
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4473
Joined: Wed Jun 04, 2008 11:20 am

Re: issue #23

Postby mflerackers » Wed Mar 17, 2010 9:30 am

Actually we have an API to get a folder depending on the OS, getPath. We just need to add additional folders to this method. It's planned, but I didn't have time for it yet. It's better than using the current folder, as on unix you might want to put the data separate from the executable. We also need to think of application and user folders for the same content, as some users on the same system might have their own choice of plugins, or some might use additional morph packages.
MakeHuman project Developer
mflerackers
 
Posts: 636
Joined: Thu Feb 05, 2009 11:53 am
Location: Kyoto

Re: issue #23

Postby joepal » Wed Mar 17, 2010 10:04 am

Is that a python API or a C api? Right now, main.c crashes since it tries to execute main.py in current folder, so that's before python has started at all. I think the same actually happens on windows, at least if trying to launch from "run" or from a command prompt using absolute path.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4473
Joined: Wed Jun 04, 2008 11:20 am

Re: issue #23

Postby mflerackers » Wed Mar 17, 2010 10:10 am

The method can be used from python as well as from C. Unfortunately there are still many places where we should use it instead of hardcoded paths.
MakeHuman project Developer
mflerackers
 
Posts: 636
Joined: Thu Feb 05, 2009 11:53 am
Location: Kyoto


Return to Python scripts

Who is online

Users browsing this forum: No registered users and 1 guest