Page 1 of 1

paths.py suggestion

Posted: Thu Aug 30, 2012 7:23 pm
by BackRaw
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?

Posted: Thu Aug 30, 2012 7:47 pm
by Monday
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.

Posted: Thu Aug 30, 2012 8:15 pm
by Ayuto
I prefer the path module, since it's a even easier. [python]from path import path

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

Posted: Thu Aug 30, 2012 9:42 pm
by Monday
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!

Posted: Thu Aug 30, 2012 11:30 pm
by BackRaw
Monday wrote:Yup that works too!


Cool, thanks =)

Posted: Fri Aug 31, 2012 12:21 am
by satoon101
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