Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Knowing a module's folder path

By
Odooveloper (by Rui Franco)
on 12/12/14, 11:21 AM 903 views

Imagine yourself in a module's form, as if you were going to update it.

You can see the name, the summary the version... but, for some reason, you need to know where the module physically is. You need to know the actual path to the files.

How can you do that? Should you run a search on every addon folder in the config, looking for a folder with the same name of the module or is there any "secret" way of getting that info?

;)

0

Thanks Bole but that was pretty much what I was doing and it would only show me the current module. The script had to tell me the path of the module where it was beeing executed from and not where the python file was located.

This is how I eventually did the trick:

        folder_found=False
        addons_path=config['addons_path'].split(',')
        for addons_folder in addons_path:
            readme_path=addons_folder + '\\' + self.name
            
            if os.path.isdir(readme_path):
                folder_found=True
                try:
                    f=open(readme_path +'/README.md',"w")
                    f.write(readme_txt.encode('utf-8'))
                    f.close()
                except:
                    raise osv.except_osv(_('Error!'),_('Unable to write file at ' + readme_path))
                break

        if not folder_found:
            raise osv.except_osv(_('Error!'),_("Unable to find '%s' folder " % self.name))

 

0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 12/15/14, 4:09 AM

put this in your code: 

import os
path = os.path.join(os.path.dirname(os.path.abspath(__file__)))

wich will return the path of file the code is in... (show it as you find apropriate.. as field value, popup message etc...)

 

hope it helps :)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/12/14, 11:21 AM
Seen: 903 times
Last updated: 3/16/15, 8:10 AM