paths.py suggestion

All other Source.Python topics and issues.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

paths.py suggestion

Postby BackRaw » Thu Aug 30, 2012 7:23 pm

Hey folks,

I wanna give you a suggestion for the _libs/paths.py file. The name "ADDON_PATH" is confusing (at least for former ES coders). Why not change that to "PLUGIN_PATH" - since it points to <srcds>/csgo/addons/source-python - and add a function called GetAddonPath(addon_name) that returns PLUGIN_PATH + "/addons/" + addon_name?
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Thu Aug 30, 2012 7:47 pm

if you want to know the path of your addon.. try this:

Syntax: Select all

from os import path

my_file_dir = path.dirname(path.abspath(__file__))


There are several ways to do it... but this is something that can easily be handled inside python without any libraries.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Aug 30, 2012 8:15 pm

I prefer the path module, since it's a even easier. [python]from path import path

my_file_dir = path(__file__).dirname()[/python]
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Thu Aug 30, 2012 9:42 pm

Ayuto wrote:I prefer the path module, since it's a even more easier. [python]from path import path

my_file_dir = path(__file__).dirname()[/python]


Yup that works too!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Aug 30, 2012 11:30 pm

Monday wrote:Yup that works too!


Cool, thanks =)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Aug 31, 2012 12:21 am

I prefer .parent to .dirname(), but they do the same thing. And, you can also, since ADDON_PATH is a path instance itself, just use:

Syntax: Select all

from paths import ADDON_PATH

myaddon_path = ADDON_PATH.joinpath('myaddon_name')

And in reference to the original question, I am not sure if you noticed, but CFG_PATH and LOG_PATH also specify the "source-python" folder within their respective directories. This is basically to set a proper standard of where log files and cfg files will be stored. Once we start work on a translation system, there will probably be a TRANSLATION_PATH, or something like that, that points directly to a path where all translation files should be based out of. I guess, to avoid confusion, we could change ADDON_PATH to ADDONS_PATH, but I'm not sure how confusing the former actually is.

Satoon

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 26 guests