Enhanced Downloadables. by CookStar · Pull Request #437 · Source-Python-Dev-Team/Source.Python
Repository navigation
Enhanced Downloadables. - #437
Open
CookStar wants to merge 2 commits into Source-Python-Dev-Team:master from CookStar:new_downloadables
Open
Enhanced Downloadables. #437 CookStar wants to merge 2 commits into Source-Python-Dev-Team:master from CookStar:new_downloadables
Conversation
CookStar commented Nov 11, 2021
Copy link Copy Markdown
Contributor
Changed Downloadables to accept iterable on initialization.
Fixed Downloadables.update to correctly add downloadables to stringtable.
Added add_from_file/remove_from_file functions to Downloadables.
Examples:
from stringtables.downloads import Downloadables
downloadables = Downloadables(("downloadable_path_1.vtf", "downloadable_path_2.vtf"))
downloadables.update(("downloadable_path_3.vtf", "downloadable_path_4.vtf"))
downloadables.add_from_file("file_path.txt")
downloadables.remove_from_file("file_path.txt")
Enhanced Downloadables.
0ff4321
Changed Downloadables to accept iterable on initialization. Fixed Downloadables.update to correctly add downloadables to stringtable. Added add_from_file/remove_from_file functions to Downloadables.
jordanbriere commented Nov 13, 2021
Copy link Copy Markdown
Contributor
|
There are a few issues I can think of regarding how you parse the file into
|
satoon101 commented Nov 13, 2021
Copy link Copy Markdown
Member
|
I would also add a few items in regards to your use of
With the last 2, I understand that they are slower, because they end up calling the other functionality internally. But, this isn't an operation that will be happening frequently, and the speed difference should be negligible. |
Minor fixes.
9b53244
CookStar commented Nov 15, 2021
Copy link Copy Markdown
Contributor
Author
Fixed.
Isn't that a tricky thing to do? As both "test #.vtf" and "test///test.vtf" are valid paths, we shouldn't allow end-line comments.
That's not a problem that should be solved by add_from_file/remove_from_file, but by Downloadables itself. Besides, I think the downloadables string is a problem that should be managed by the plugin author/model distributor, and normalization will only add unnecessary problems.
This is intentionally to display an error, because there is nothing we can do as long as we don't know whether the specified file path starts with an absolute path, a relative path, or a path relative to GAME_PATH. The reason I don't like Path.open is that it makes errors more confusing than they need to be. Instead of Path.open error, it now raises FileNotFoundError by default. |
jordanbriere commented Nov 15, 2021
Copy link Copy Markdown
Contributor
This can be done with a simple regex. For example: import re
from path import Path
from pprint import pprint
def get_files(buffer):
files = set()
for line in buffer.splitlines():
line = line.strip()
if line.startswith('//'):
continue
match = re.match('(.*?)(?=\/\/ )', line)
if match is not None:
line = match.group().rstrip()
file = line.strip()
if not file:
continue
files.add(Path(file).normpath())
return files
pprint(get_files("""
foo//bar/\\baz.mp3 // This is a cool song.
maps/some map.bsp
// my_model.mdl
// Some empty line
myfile.txt
my file.vtf // This material is trash.
foo.wav // blah blah
éééàà.mp3
"""))
I discarded
I don't think this should be the responsibility of the |
CookStar commented Nov 15, 2021
Copy link Copy Markdown
Contributor
Author
You're missing when a directory starts and ends with a space. And when there is no space after a comment.
Remember that
I simply thought it would be useful to be able to add and remove files in batches because some models have files in different locations in the directory hierarchy, so I didn't think that far ahead. But if that's the case, wouldn't it make more sense to normalize in all situations? Why do you think normalization is necessary in the first place? If the downloadables don't work, they won't work after all, so I think it can only be the responsibility of the person who added them. For example, on Windows, lowercase and uppercase letters are treated as equal, so mixing them will work, but on Linux, it will not. |
jordanbriere commented Nov 15, 2021
Copy link Copy Markdown
Contributor
That's because my regex doesn't have the right order. Should be |
jordanbriere commented Nov 15, 2021
Copy link Copy Markdown
Contributor
That's a great point, actually. Which lead me to agree with:
The goal is that paths are consistent and the resolution from the added strings are the same as the resolution of the |
View reviewed changes
Comment thread addons/source-python/packages/source-python/stringtables/downloads.py
| raise FileNotFoundError(f'No file found at "{file_path}"') | ||
|
|
||
| with file_path.open('r', encoding=encoding) as file: | ||
| lines = [line.strip() for line in file.readlines()] |
View reviewed changes
Comment thread addons/source-python/packages/source-python/stringtables/downloads.py
| The paths to add to the downloadables. | ||
| """ | ||
| if items is None: | ||
| return |
Ayuto commented Apr 19, 2025
Copy link Copy Markdown
Member
|
If you agree on the two changes I would be happy to merge into master. I also wouln't add the possibility to add comments at the end. They have to be at the beginning of a line and that's it. No need to make it more complex. |
This branch has not been deployed
No deployments
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment