Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pdf-miner
Project
Project
Details
Activity
Releases
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
Qin Kaijie
pdf-miner
Commits
7e59b4b6
Commit
7e59b4b6
authored
Apr 08, 2024
by
赵小蒙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现从本地home目录获取s3config信息
parent
58c191e7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
5 deletions
+37
-5
config_reader.py
magic_pdf/libs/config_reader.py
+37
-5
No files found.
magic_pdf/libs/config_reader.py
View file @
7e59b4b6
"""
根据bucket的名字返回对应的s3 AK, SK,endpoint三元组
"""
import
json
import
os
from
loguru
import
logger
def
get_s3_config
(
bucket_name
:
str
):
"""
~/magic
-pdf
.json 读出来
~/magic
_pdf_config
.json 读出来
"""
ak
,
sk
,
endpoint
=
""
,
""
,
""
# TODO 请实现这个函数
if
os
.
name
==
"posix"
:
# Linux or macOS
home_dir
=
os
.
path
.
expanduser
(
"~"
)
elif
os
.
name
==
"nt"
:
# Windows
home_dir
=
os
.
path
.
expandvars
(
"
%
USERPROFILE
%
"
)
else
:
raise
Exception
(
"Unsupported operating system"
)
config_file
=
os
.
path
.
join
(
home_dir
,
"magic_pdf_config.json"
)
if
not
os
.
path
.
exists
(
config_file
):
raise
Exception
(
"magic_pdf_config.json not found"
)
with
open
(
config_file
,
"r"
)
as
f
:
config
=
json
.
load
(
f
)
if
bucket_name
not
in
config
:
raise
Exception
(
"bucket_name not found in magic_pdf_config.json"
)
ak
=
config
[
bucket_name
]
.
get
(
"ak"
)
sk
=
config
[
bucket_name
]
.
get
(
"sk"
)
endpoint
=
config
[
bucket_name
]
.
get
(
"endpoint"
)
if
ak
is
None
or
sk
is
None
or
endpoint
is
None
:
raise
Exception
(
"ak, sk or endpoint not found in magic_pdf_config.json"
)
# logger.info(f"get_s3_config: ak={ak}, sk={sk}, endpoint={endpoint}")
return
ak
,
sk
,
endpoint
if
__name__
==
'__main__'
:
ak
,
sk
,
endpoint
=
get_s3_config
(
"llm-raw"
)
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