sourcepython installation broken

All other Source.Python topics and issues.
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

sourcepython installation broken

Postby velocity » Tue Apr 23, 2019 11:18 pm

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?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: sourcepython installation broken

Postby satoon101 » Wed Apr 24, 2019 3:10 am

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.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: sourcepython installation broken

Postby L'In20Cible » Wed Apr 24, 2019 3:24 am

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.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: sourcepython installation broken

Postby Ayuto » Wed Apr 24, 2019 5:22 am

Don't forget that relative paths are also working. So, we actually just need to use relative paths as the default values.
DeaD_EyE
Member
Posts: 34
Joined: Wed Jan 08, 2014 10:32 am

Re: sourcepython installation broken

Postby DeaD_EyE » Mon Apr 29, 2019 12:28 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: sourcepython installation broken

Postby satoon101 » Tue Apr 30, 2019 12:47 am

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.
Image

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 34 guests