Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VAServerLauncher
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LuFG VR VIS
VR-Group
VAServerLauncher
Commits
b76d1102
Commit
b76d1102
authored
Oct 11, 2021
by
Ehret
Browse files
Options
Downloads
Patches
Plain Diff
check whether file already exists and correctly receive it
parent
8735d3c2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
LaunchScript/VirtualAcousticsStarterServer.py
+45
-22
45 additions, 22 deletions
LaunchScript/VirtualAcousticsStarterServer.py
with
45 additions
and
22 deletions
LaunchScript/VirtualAcousticsStarterServer.py
+
45
−
22
View file @
b76d1102
...
...
@@ -158,9 +158,23 @@ try:
ProjectName
=
aMessageParts
[
3
]
Fullpath
=
os
.
path
.
join
(
sCurrentScriptsDirectory
,
"
..
"
,
"
tmp
"
,
ProjectName
,
Path
,
""
)
print
(
"
Should receive file:
"
+
Filename
+
"
in path
"
+
Fullpath
+
"
with
"
+
str
(
iBytesToReceive
)
+
"
bytes
"
)
#check whether the file with this exact size already exists
if
os
.
path
.
isfile
(
Fullpath
+
Filename
)
and
os
.
stat
(
Fullpath
+
Filename
).
st_size
==
iBytesToReceive
:
oConnection
.
send
(
b
'
exists
'
)
print
(
"
File already exists with this size, so no need for resending
"
)
else
:
#file need to be received
#create dir if it does not exist
if
not
os
.
path
.
exists
(
Fullpath
):
os
.
makedirs
(
Fullpath
)
oConnection
.
send
(
b
'
a
'
)
#send acceptance
#send acceptance
oConnection
.
send
(
b
'
ack
'
)
#print("Send ack")
#receive file
iBytesReceived
=
0
with
open
(
Fullpath
+
Filename
,
"
wb
"
)
as
f
:
bReceivingFile
=
True
while
bReceivingFile
:
...
...
@@ -174,12 +188,21 @@ try:
else
:
# write to the file the bytes we just received
f
.
write
(
bytes_read
)
print
(
"
File received
"
)
iBytesReceived
+=
len
(
bytes_read
)
if
iBytesReceived
==
iBytesToReceive
:
bReceivingFile
=
False
f
.
close
()
#check whether received file seems ok
if
iBytesReceived
==
iBytesToReceive
:
oConnection
.
send
(
b
'
ack
'
)
#send acceptance
print
(
"
File received successfully
"
)
else
:
print
(
"
Received message:
"
+
sResult
.
decode
(
"
utf-8
"
))
print
(
"
First byte:
"
+
str
(
sResult
[
0
]))
#print( "Received quit event" )
#bContinue = False
oConnection
.
send
(
b
'
fail
'
)
#send failure
print
(
"
File receive failed
"
)
else
:
#NOT sMessage.startswith("file")
print
(
"
Received quit event:
"
+
sMessage
)
bContinue
=
False
except
socket
.
timeout
:
bContinue
=
True
# timeouts are okay
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment