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
4adc253d
Commit
4adc253d
authored
1 year ago
by
Philipp Goymann
Browse files
Options
Downloads
Plain Diff
Merge branch 'unstabel' into 'master'
Unstabel See merge request
!6
parents
cccc2305
24bffb46
No related branches found
No related tags found
1 merge request
!6
Unstabel
Pipeline
#362569
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
+7
-1
7 additions, 1 deletion
loosolab_s3/cmd.py
loosolab_s3/s3_functions.py
+24
-5
24 additions, 5 deletions
loosolab_s3/s3_functions.py
with
31 additions
and
6 deletions
loosolab_s3/cmd.py
+
7
−
1
View file @
4adc253d
...
...
@@ -3,6 +3,7 @@
import
argparse
import
sys
import
os
#own functions
from
loosolab_s3.Utils
import
Utils
...
...
@@ -41,7 +42,10 @@ def run_s3_functions():
if
args
.
upload
:
utils
.
check_argparser
(
args
,
[
'
secret
'
,
"
key
"
,
"
files
"
,
"
bucketname
"
])
s3
.
upload_s3_objects
(
args
.
bucketname
,
args
.
files
)
if
args
.
download
:
utils
.
check_argparser
(
args
,
[
'
secret
'
,
"
key
"
,
"
files
"
,
"
bucketname
"
])
s3
.
download_s3_objects
(
args
.
bucketname
,
args
.
files
,
destination
=
os
.
getcwd
())
#--------------------------------------------------------------------------------------------------------#
# parse command line arguments:
def
argparsefunc
():
...
...
@@ -54,6 +58,7 @@ def argparsefunc():
#actions
parser
.
add_argument
(
"
--upload
"
,
action
=
'
store_true
'
,
help
=
"
upload files to bucket
"
)
parser
.
add_argument
(
"
--download
"
,
action
=
'
store_true
'
,
help
=
"
download files to bucket
"
)
parser
.
add_argument
(
"
--bucket_exists
"
,
action
=
'
store_true
'
,
help
=
"
check if bucket exists
"
)
#values
...
...
@@ -66,6 +71,7 @@ def argparsefunc():
if
args
.
show_help
:
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
if
len
(
sys
.
argv
)
==
1
:
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
...
...
This diff is collapsed.
Click to expand it.
loosolab_s3/s3_functions.py
+
24
−
5
View file @
4adc253d
...
...
@@ -26,19 +26,24 @@ class Loosolab_s3:
def
__init__
(
self
,
credentials
,
multipart_upload
=
True
,
logger
=
True
):
if
logger
:
level
=
logging
.
INFO
level
=
20
else
:
level
=
logging
.
CRITICAL
self
.
logger
=
logging
.
basicConfig
(
format
=
'
%(asctime)s - %(name)s - %(levelname)s - %(message)s
'
,
level
=
level
)
level
=
50
self
.
logger
=
logging
.
basicConfig
(
format
=
'
%(asctime)s - %(name)s - %(levelname)s - %(message)s
'
)
self
.
logger
=
logging
.
getLogger
(
'
Loosolab_s3_logger
'
)
self
.
logger
.
setLevel
(
level
)
#self.logger = logging.getLogger().setLevel(level)
# having a global session (needed for all boto action)
self
.
create_s3_session
(
credentials
)
if
not
multipart_upload
:
self
.
create_s3_transfer
(
credentials
)
self
.
multipart_upload
=
multipart_upload
def
__exception_log__
(
self
,
information
,
exception_e
=
""
):
'''
raise exception and logg as ERROR
exception: e
...
...
@@ -452,7 +457,7 @@ class Loosolab_s3:
return
True
#--------------------------------------------------------------------------------------------------------#
def
download_s3_objects
(
self
,
bucket_name
,
file_list
,
destination
=
'
.
'
,
compare
=
True
):
def
download_s3_objects
(
self
,
bucket_name
,
file_list
,
destination
=
os
.
getcwd
()
,
compare
=
True
):
"""
Download files from bucket
Parameter:
----------
...
...
@@ -466,6 +471,20 @@ class Loosolab_s3:
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
)):
print
(
file_path
)
os
.
makedirs
(
os
.
path
.
dirname
(
file_path
))
self
.
logger
.
info
(
'
Created directory:
'
+
os
.
path
.
dirname
(
file_path
))
if
self
.
multipart_upload
:
bucket
.
download_file
(
file_name
,
file_path
)
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
)
...
...
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