mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Make directoriy ignoring more intelligent
Replace path stringifications with as_posix function, which will make the generation reliable on both unix and windows systems
This commit is contained in:
parent
018fe2ab10
commit
83dce820d8
2 changed files with 14 additions and 8 deletions
|
@ -5,10 +5,18 @@ from _generate_resources import *
|
||||||
|
|
||||||
ignored_files = ['qt.conf', 'resources.qrc', 'resources_autogenerated.qrc', 'windows.rc',
|
ignored_files = ['qt.conf', 'resources.qrc', 'resources_autogenerated.qrc', 'windows.rc',
|
||||||
'generate_resources.py', '_generate_resources.py']
|
'generate_resources.py', '_generate_resources.py']
|
||||||
|
|
||||||
|
# to ignore all files in a/b, add a/b to ignored_directories.
|
||||||
|
# this will ignore a/b/c/d.txt and a/b/xd.txt
|
||||||
ignored_directories = ['__pycache__']
|
ignored_directories = ['__pycache__']
|
||||||
|
|
||||||
def isNotIgnored(file):
|
def isNotIgnored(file):
|
||||||
return str(file) not in ignored_files
|
# check if file exists in an ignored direcory
|
||||||
|
for ignored_directory in ignored_directories:
|
||||||
|
if file.parent.as_posix().startswith(ignored_directory):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return file.as_posix() not in ignored_files
|
||||||
|
|
||||||
all_files = list(filter(isNotIgnored, \
|
all_files = list(filter(isNotIgnored, \
|
||||||
filter(Path.is_file, Path('.').glob('**/*'))))
|
filter(Path.is_file, Path('.').glob('**/*'))))
|
||||||
|
@ -18,15 +26,15 @@ image_files = list(filter(isNotIgnored, \
|
||||||
with open('./resources_autogenerated.qrc', 'w') as out:
|
with open('./resources_autogenerated.qrc', 'w') as out:
|
||||||
out.write(resources_header)
|
out.write(resources_header)
|
||||||
for file in all_files:
|
for file in all_files:
|
||||||
out.write(f" <file>{str(file)}</file>\n")
|
out.write(f" <file>{file.as_posix()}</file>\n")
|
||||||
out.write(resources_footer)
|
out.write(resources_footer)
|
||||||
|
|
||||||
with open('../src/autogenerated/ResourcesAutogen.cpp', 'w') as out:
|
with open('../src/autogenerated/ResourcesAutogen.cpp', 'w') as out:
|
||||||
out.write(source_header)
|
out.write(source_header)
|
||||||
for file in sorted(image_files):
|
for file in sorted(image_files):
|
||||||
var_name = str(file.with_suffix("")).replace("/",".")
|
var_name = file.with_suffix("").as_posix().replace("/",".")
|
||||||
out.write(f' this->{var_name}')
|
out.write(f' this->{var_name}')
|
||||||
out.write(f' = QPixmap(":/{file}");\n')
|
out.write(f' = QPixmap(":/{file.as_posix()}");\n')
|
||||||
out.write(source_footer)
|
out.write(source_footer)
|
||||||
|
|
||||||
def writeHeader(out, name, element, indent):
|
def writeHeader(out, name, element, indent):
|
||||||
|
@ -46,12 +54,11 @@ with open('../src/autogenerated/ResourcesAutogen.hpp', 'w') as out:
|
||||||
elements = {}
|
elements = {}
|
||||||
for file in sorted(image_files):
|
for file in sorted(image_files):
|
||||||
elements_ref = elements
|
elements_ref = elements
|
||||||
directories = str(file).split('/')[:-1]
|
directories = file.as_posix().split('/')[:-1]
|
||||||
filename = file.stem
|
filename = file.stem
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
if directory not in elements_ref:
|
if directory not in elements_ref:
|
||||||
if directory not in ignored_directories:
|
elements_ref[directory] = {}
|
||||||
elements_ref[directory] = {}
|
|
||||||
elements_ref = elements_ref[directory]
|
elements_ref = elements_ref[directory]
|
||||||
elements_ref[filename] = filename
|
elements_ref[filename] = filename
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,5 @@
|
||||||
<file>twitch/subscriber.png</file>
|
<file>twitch/subscriber.png</file>
|
||||||
<file>twitch/turbo.png</file>
|
<file>twitch/turbo.png</file>
|
||||||
<file>twitch/verified.png</file>
|
<file>twitch/verified.png</file>
|
||||||
<file>__pycache__/_generate_resources.cpython-36.pyc</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
Loading…
Reference in a new issue