Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
1c0f538f
authored
2020-07-20 18:39:07 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
eDMS upload doc
1 parent
edb14afd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
8 deletions
src/apps/doc/edms.py
src/settings/conf/_default_config.py
src/settings/conf/prd.ini
src/settings/conf/sit.ini
src/settings/conf/uat.ini
wsdl/RepositoryController.wsdl
src/apps/doc/edms.py
View file @
1c0f538
...
...
@@ -11,7 +11,9 @@ class EDMS:
self
.
sm_client
=
Client
(
wsdl
=
conf
.
SM_WSDL
)
self
.
dm_client
=
Client
(
wsdl
=
conf
.
DM_WSDL
)
self
.
df_client
=
Client
(
wsdl
=
conf
.
DF_WSDL
)
self
.
rc_client
=
Client
(
wsdl
=
conf
.
RC_WSDL
)
self
.
download_url
=
conf
.
EDMS_DOWNLOAD_URL
self
.
upload_url
=
conf
.
EDMS_UPLOAD_URL
self
.
user_name
=
user_name
self
.
pwd
=
pwd
self
.
session_id
=
None
...
...
@@ -35,6 +37,11 @@ class EDMS:
return
self
.
session_id
return
self
.
set_session_id
()
def
get_headers
(
self
):
session_id
=
self
.
get_session_id
()
headers
=
{
'Cookie'
:
'{0}={1}'
.
format
(
consts
.
SESSION_PREFIX
,
session_id
)}
return
headers
def
get_download_token
(
self
,
headers
,
metadata_version_id
):
with
self
.
dm_client
.
settings
(
extra_http_headers
=
headers
):
res
=
self
.
dm_client
.
service
.
PrepareSingleDocumentToDownload
(
metadataVersionId
=
metadata_version_id
,
...
...
@@ -43,12 +50,7 @@ class EDMS:
actionType
=
consts
.
DOWNLOAD_ACTION_TYPE
)
return
res
.
token
def
download
(
self
,
save_path
,
metadata_version_id
):
session_id
=
self
.
get_session_id
()
headers
=
{
'Cookie'
:
'{0}={1}'
.
format
(
consts
.
SESSION_PREFIX
,
session_id
)}
token
=
self
.
get_download_token
(
headers
,
metadata_version_id
)
params
=
{
'token'
:
token
}
def
download_handler
(
self
,
params
,
headers
,
save_path
):
r
=
requests
.
get
(
self
.
download_url
,
params
=
params
,
headers
=
headers
,
stream
=
True
)
with
open
(
save_path
,
"wb"
)
as
f
:
# chunk是指定每次写入的大小,每次只写了512byte
...
...
@@ -57,3 +59,39 @@ class EDMS:
f
.
write
(
chunk
)
f
.
flush
()
def
download
(
self
,
save_path
,
metadata_version_id
):
headers
=
self
.
get_headers
()
token
=
self
.
get_download_token
(
headers
,
metadata_version_id
)
params
=
{
'token'
:
token
}
self
.
download_handler
(
params
,
headers
,
save_path
)
def
create_upload_token
(
self
,
headers
,
file_size
):
with
self
.
rc_client
.
settings
(
extra_http_headers
=
headers
):
token
=
self
.
rc_client
.
service
.
CreateUploadToken
(
fileSize
=
file_size
)
return
token
def
upload_handler
(
self
,
file_path
,
params
,
headers
):
with
open
(
file_path
,
'rb'
)
as
f
:
data
=
f
.
read
()
for
retry
in
range
(
4
):
res
=
requests
.
post
(
self
.
upload_url
,
params
=
params
,
headers
=
headers
,
data
=
data
)
if
res
.
status_code
==
requests
.
codes
.
ok
:
break
else
:
raise
Exception
def
add_doc_info
(
self
,
headers
,
token
,
app_info
):
with
self
.
dm_client
.
settings
(
extra_http_headers
=
headers
):
res
=
self
.
dm_client
.
service
.
AddDocumentInfo
()
return
res
def
upload
(
self
,
file_path
,
file_size
,
app_info
):
headers
=
self
.
get_headers
()
token
=
self
.
create_upload_token
(
headers
,
file_size
)
headers
.
update
({
'Content-Type'
:
'application/octet-stream'
})
params
=
{
'token'
:
token
}
self
.
upload_handler
(
file_path
,
params
,
headers
)
headers
.
pop
(
'Content-Type'
)
self
.
add_doc_info
(
headers
,
token
,
app_info
)
...
...
src/settings/conf/_default_config.py
View file @
1c0f538
...
...
@@ -11,6 +11,7 @@ LOGGING_CONFIG_FILE = os.path.join(COMMON_CONF_DIR, 'logging.conf')
SM_WSDL
=
os
.
path
.
join
(
WSDL_DIR
,
'SessionManager.wsdl'
)
DM_WSDL
=
os
.
path
.
join
(
WSDL_DIR
,
'DocumentManager.wsdl'
)
DF_WSDL
=
os
.
path
.
join
(
WSDL_DIR
,
'DocumentFinder.wsdl'
)
RC_WSDL
=
os
.
path
.
join
(
WSDL_DIR
,
'RepositoryController.wsdl'
)
# 文件存放根目录
LOG_DIR
=
os
.
path
.
join
(
os
.
path
.
dirname
(
BASE_DIR
),
'logs'
)
...
...
src/settings/conf/prd.ini
View file @
1c0f538
...
...
@@ -3,4 +3,5 @@ DEBUG = False
SLEEP_SECOND
=
5
MAX_SLEEP_SECOND
=
60
EDMS_DOWNLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/DownloadHandler.ashx
\ No newline at end of file
EDMS_DOWNLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/DownloadHandler.ashx
EDMS_UPLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/UploadHandler.ashx
\ No newline at end of file
...
...
src/settings/conf/sit.ini
View file @
1c0f538
...
...
@@ -3,4 +3,5 @@ DEBUG = True
SLEEP_SECOND
=
5
MAX_SLEEP_SECOND
=
60
EDMS_DOWNLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/DownloadHandler.ashx
\ No newline at end of file
EDMS_DOWNLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/DownloadHandler.ashx
EDMS_UPLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/UploadHandler.ashx
\ No newline at end of file
...
...
src/settings/conf/uat.ini
View file @
1c0f538
...
...
@@ -4,3 +4,4 @@ SLEEP_SECOND = 5
MAX_SLEEP_SECOND
=
60
EDMS_DOWNLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/DownloadHandler.ashx
EDMS_UPLOAD_URL
=
https://edms-test.bmw.com/FH/FileHold/DocumentRepository/UploadHandler.ashx
\ No newline at end of file
...
...
wsdl/RepositoryController.wsdl
0 → 100644
View file @
1c0f538
This diff is collapsed.
Click to expand it.
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment