Page 1 of 1

sourcepython installation broken

Posted: Tue Apr 23, 2019 11:18 pm
by velocity
This is not a bug but can be trouble for some people. When you copy sourcepython from a server to a different server, sourcepython becomes broken because of a new folder path. This can be fixed by adjusting the path accordingly in /cfg/sourcepython/core_settings.ini -> [[[flatfile]]]

This got me thinking that maybe sourcepython should update the paths everytime server starts?

Re: sourcepython installation broken

Posted: Wed Apr 24, 2019 3:10 am
by satoon101
Those are settings that you can change for any server. The original values that populate those settings are defaults, not constants. It would not be a good idea to reset them every time SP starts, because some servers might legitimately change those paths for their specific situation/needs.

Perhaps a better way would be to catch that issue (the base directory itself being different than the base server directory and the file(s) not existing) during startup and raise a warning/error? Although, that seems like a very specific use case that would only really happen if you copy/paste the ../cfg/source-python/ directory.

Re: sourcepython installation broken

Posted: Wed Apr 24, 2019 3:24 am
by L'In20Cible
An idea could be to allow the use of the constants available in the paths.py module via keywords and default them to:

Syntax: Select all

[[[flatfile]]]
player_config_path = {AUTH_CFG_PATH}\players.json
parent_config_path = {AUTH_CFG_PATH}\parents.json
simple_config_path = {AUTH_CFG_PATH}\simple.txt

[[[sql]]]
uri = sqlite:///{SP_DATA_PATH}\permissions.db

That way users are still able to hardcode the paths if they need, but the default becomes dynamic.

Re: sourcepython installation broken

Posted: Wed Apr 24, 2019 5:22 am
by Ayuto
Don't forget that relative paths are also working. So, we actually just need to use relative paths as the default values.

Re: sourcepython installation broken

Posted: Mon Apr 29, 2019 12:28 pm
by DeaD_EyE
SourcePython could create the configuration files with relative paths.
This paths should converted to Path-objects, then use the method absolute to get the absolute path.

This allows the user, to use later absolute Paths in the configuration files.
Calling the method absolute() on an absolute path, returns the absolute path.

config.ini:

Code: Select all

[default]
relative_path = Downloads
absolute_path = /home/andre/Downloads


code for path manipulation

Code: Select all

import sys
from configparser import ConfigParser
from pathlib import Path


parser = ConfigParser()
parser.read('config.ini')

exe_path = Path(sys.executable).absolute().parent
print('Path of executable:', exe_path)

path1 = Path(parser['default']['relative_path']).absolute()
path2 = Path(parser['default']['absolute_path']).absolute()

print('path1:', path1)
print('path2:', path2)


Output:

Code: Select all

andre@andre-GP70-2PE:~$ python creader.py
Path of executable: /home/andre/.pyenv/versions/3.7.3/bin
path1: /home/andre/Downloads
path2: /home/andre/Downloads


The pathlib is very powerful. It supports Linux, Windows and Mac.

Re: sourcepython installation broken

Posted: Tue Apr 30, 2019 12:47 am
by satoon101
To be fair, we do also include the path.py 3rd party package which can do pretty much everything in pathlib and then some. When we started this Source.Python, Python3.4 (the first version to include pathlib) was still a ways off so we didn't have the option of using a built-in pathlib.

https://pypi.org/project/path.py/

But yes, as Ayuto stated, we can just set the defaults to use relative paths and that should fix this issue.