Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
loosolab-s3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
loosolab
software
loosolab-s3
Commits
673f641f
Commit
673f641f
authored
1 year ago
by
Philipp Goymann
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
2c2dbb85
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!8
Unstabel
Pipeline
#369408
passed
1 year ago
Stage: build_prod
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
loosolab_s3/cmd.py
+8
-5
8 additions, 5 deletions
loosolab_s3/cmd.py
loosolab_s3/s3_functions.py
+18
-24
18 additions, 24 deletions
loosolab_s3/s3_functions.py
with
26 additions
and
29 deletions
loosolab_s3/cmd.py
+
8
−
5
View file @
673f641f
...
...
@@ -27,11 +27,13 @@ def run_s3_functions():
s3
=
Loosolab_s3
(
credentials
,
logger
=
False
)
else
:
s3
=
Loosolab_s3
(
credentials
)
if
args
.
output
:
output
=
args
.
output
else
:
output
=
os
.
getcwd
()
if
args
.
read_form_dict
:
bucket_dict
=
args
.
read_form_dict
bucket_dict
=
args
.
read_form_dict
bucketname
=
bucket_dict
.
split
(
'
:
'
)[
0
]
files
=
[
bucket_dict
.
split
(
'
:
'
)[
1
]]
if
args
.
bucketname
:
...
...
@@ -61,7 +63,7 @@ def run_s3_functions():
else
:
utils
.
check_argparser
(
args
,
[
'
secret
'
,
"
key
"
,
"
files
"
,
"
bucketname
"
])
s3
.
download_s3_objects
(
bucketname
,
files
,
destination
=
o
s
.
getcwd
()
,
download_bar
=
True
)
s3
.
download_s3_objects
(
bucketname
,
files
,
destination
=
o
utput
,
download_bar
=
True
)
#--------------------------------------------------------------------------------------------------------#
# parse command line arguments:
def
argparsefunc
():
...
...
@@ -83,6 +85,7 @@ def argparsefunc():
parser
.
add_argument
(
"
--files
"
,
nargs
=
'
+
'
,
help
=
"
bucket upload files
"
)
parser
.
add_argument
(
"
--bucketname
"
)
parser
.
add_argument
(
"
--no_log
"
,
action
=
'
store_true
'
,
help
=
'
disable logging
'
)
parser
.
add_argument
(
"
--output
"
,
help
=
'
Download folder
'
)
parser
.
add_argument
(
'
-h
'
,
'
--help
'
,
action
=
'
store_true
'
,
dest
=
'
show_help
'
)
args
=
parser
.
parse_args
()
...
...
This diff is collapsed.
Click to expand it.
loosolab_s3/s3_functions.py
+
18
−
24
View file @
673f641f
...
...
@@ -215,7 +215,7 @@ class Loosolab_s3:
local_tag
=
self
.
etag_checksum
(
local_file_name
)
else
:
local_tag
=
hashlib
.
md5
(
open
(
local_file_name
).
read
().
encode
(
'
utf-8
'
)).
hexdigest
()
print
(
'
\n
'
)
self
.
logger
.
info
(
'
local e-tag of
'
+
local_file_name
+
'
is :
'
+
local_tag
)
self
.
logger
.
info
(
'
s3 e-tag of
'
+
file_name
+
'
is :
'
+
s3_e_tag
)
...
...
@@ -475,25 +475,11 @@ class Loosolab_s3:
timeout : float
how long to watch for file in minutes
"""
bucket
=
self
.
session
.
Bucket
(
bucket_name
)
modBool
=
False
# check if exists
for
local_file
in
file_list
:
file_name
=
os
.
path
.
basename
(
local_file
)
file_path
=
os
.
path
.
join
(
destination
,
local_file
)
if
compare
:
modBool
=
self
.
compare_s3_etag
(
bucket_name
,
file_name
,
file_path
)
if
self
.
check_s3_object_ex
(
bucket_name
,
file_name
)
and
not
modBool
:
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
file_path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
file_path
))
self
.
logger
.
info
(
'
Created directory:
'
+
os
.
path
.
dirname
(
file_path
))
if
self
.
multipart_upload
and
not
download_bar
:
bucket
.
download_file
(
file_name
,
file_path
)
elif
download_bar
:
self
.
download
(
file_path
,
bucket_name
,
file_name
)
else
:
bucket
.
download_file
(
file_name
,
file_path
,
Config
=
self
.
transfer
)
try
:
for
local_file
in
file_list
:
file_name
=
os
.
path
.
basename
(
local_file
)
...
...
@@ -501,11 +487,14 @@ class Loosolab_s3:
if
compare
:
modBool
=
self
.
compare_s3_etag
(
bucket_name
,
file_name
,
file_path
)
if
self
.
check_s3_object_ex
(
bucket_name
,
file_name
)
and
not
modBool
:
if
not
os
.
path
.
exists
(
file_path
):
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
file_path
)
)
:
os
.
makedirs
(
os
.
path
.
dirname
(
file_path
))
self
.
logger
.
info
(
'
Created directory:
'
+
os
.
path
.
dirname
(
file_path
))
if
self
.
multipart_upload
:
if
self
.
multipart_upload
and
not
download_bar
:
bucket
.
download_file
(
file_name
,
file_path
)
elif
download_bar
:
self
.
download
(
file_path
,
bucket_name
,
file_name
)
else
:
bucket
.
download_file
(
file_name
,
file_path
,
Config
=
self
.
transfer
)
except
Exception
as
e
:
...
...
@@ -514,18 +503,23 @@ class Loosolab_s3:
#--------------------------------------------------------------------------------------------------------#
def
download
(
self
,
local_file_name
,
s3_bucket
,
s3_object_key
):
meta_data
=
self
.
client
.
head_object
(
Bucket
=
s3_bucket
,
Key
=
s3_object_key
)
total_length
=
in
t
(
meta_data
.
get
(
'
ContentLength
'
,
0
))
total_length
=
floa
t
(
meta_data
.
get
(
'
ContentLength
'
,
0
))
downloaded
=
0
part
=
total_length
/
10
count
=
total_length
/
10
def
progress
(
chunk
):
nonlocal
downloaded
nonlocal
part
nonlocal
count
downloaded
+=
chunk
done
=
int
(
50
*
downloaded
/
total_length
)
if
downloaded
>
count
:
print
(
str
(
int
((
100
/
total_length
)
*
count
))
+
'
% Downloaded!
'
)
count
+=
part
print
(
"
\r
[%s%s]
"
%
(
'
=
'
*
done
,
'
'
*
(
50
-
done
))
,
end
=
"
\r
"
)
#
print("\r[%s%s]" % ('=' * done, ' ' * (50-done)) , end="\r")
#sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) )
#sys.stdout.flush()
...
...
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