Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
Oil_Level_Recognition_System
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Oil_Level_Recognition_System
Commits
ea8cefed
Commit
ea8cefed
authored
Dec 05, 2025
by
余海波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete embed_resources.py
parent
dd368057
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
120 deletions
+0
-120
embed_resources.py
hooks/embed_resources.py
+0
-120
No files found.
hooks/embed_resources.py
deleted
100644 → 0
View file @
dd368057
"""
Pythonexe
SDK_internal
"""
import
os
import
base64
from
pathlib
import
Path
def
embed_file_to_python
(
file_path
,
output_path
,
var_name
):
"""
Pythonbase64
Args:
file_path:
output_path: Python
var_name:
"""
with
open
(
file_path
,
'rb'
)
as
f
:
data
=
f
.
read
()
encoded
=
base64
.
b64encode
(
data
)
.
decode
(
'utf-8'
)
# Python
code
=
f
'''"""
: {file_path}
"""
import base64
import io
# Base64
_{var_name}_data = """{encoded}"""
def get_{var_name}():
""""""
return base64.b64decode(_{var_name}_data)
def get_{var_name}_path():
""""""
import tempfile
import os
data = get_{var_name}()
#
ext = os.path.splitext("{os.path.basename(file_path)}")[1]
#
fd, temp_path = tempfile.mkstemp(suffix=ext, prefix='embedded_resource_')
try:
with os.fdopen(fd, 'wb') as f:
f.write(data)
return temp_path
except:
os.close(fd)
raise
'''
with
open
(
output_path
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
code
)
print
(
f
" : {file_path} -> {output_path} (: {var_name})"
)
def
embed_directory_to_python
(
dir_path
,
output_dir
,
max_size_mb
=
1
):
"""
Python
Args:
dir_path:
output_dir:
max_size_mb: MB
"""
os
.
makedirs
(
output_dir
,
exist_ok
=
True
)
embedded_files
=
[]
skipped_files
=
[]
for
root
,
dirs
,
files
in
os
.
walk
(
dir_path
):
for
file
in
files
:
file_path
=
os
.
path
.
join
(
root
,
file
)
rel_path
=
os
.
path
.
relpath
(
file_path
,
dir_path
)
#
size_mb
=
os
.
path
.
getsize
(
file_path
)
/
(
1024
*
1024
)
if
size_mb
>
max_size_mb
:
skipped_files
.
append
((
rel_path
,
size_mb
))
continue
#
var_name
=
rel_path
.
replace
(
os
.
sep
,
'_'
)
.
replace
(
'.'
,
'_'
)
.
replace
(
'-'
,
'_'
)
#
output_path
=
os
.
path
.
join
(
output_dir
,
f
"embedded_{var_name}.py"
)
try
:
embed_file_to_python
(
file_path
,
output_path
,
var_name
)
embedded_files
.
append
((
rel_path
,
file_path
))
except
Exception
as
e
:
print
(
f
" : {file_path} - {e}"
)
skipped_files
.
append
((
rel_path
,
size_mb
))
print
(
f
"
\n
:"
)
print
(
f
" : {len(embedded_files)} "
)
print
(
f
" : {len(skipped_files)} {max_size_mb}MB"
)
return
embedded_files
,
skipped_files
if
__name__
==
'__main__'
:
# icons
project_root
=
os
.
path
.
abspath
(
'.'
)
icons_dir
=
os
.
path
.
join
(
project_root
,
'icons'
)
output_dir
=
os
.
path
.
join
(
project_root
,
'hooks'
,
'embedded_resources'
)
if
os
.
path
.
exists
(
icons_dir
):
print
(
"icons..."
)
embed_directory_to_python
(
icons_dir
,
output_dir
,
max_size_mb
=
0.5
)
# 0.5MB
else
:
print
(
f
": {icons_dir}"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment