Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maap-s3-laptop
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
esa-common
maap-s3-laptop
Commits
28f059f0
Commit
28f059f0
authored
4 years ago
by
kosted
Browse files
Options
Downloads
Patches
Plain Diff
[1/5] init and upload initialisation
parent
ed9e0c9f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
maap-s3.py
+100
-0
100 additions, 0 deletions
maap-s3.py
with
100 additions
and
0 deletions
maap-s3.py
0 → 100644
+
100
−
0
View file @
28f059f0
import
sys
,
getopt
import
requests
import
json
import
sys
import
os
# Import getopt module
import
getopt
oauth_token
=
os
.
getenv
(
"
BEARER_TOKEN
"
)
USER_INFO_FILE_PATH
=
"
maap-s3-userinfo.json
"
userinfo
=
{}
def
display_help
():
print
(
'
Usage: [option...] {init|refresh|upload|download|ls|delete}
'
)
print
(
'
init Get a fresh token before any request. It ask for email and password
'
)
print
(
'
upload myFile.tiff path/myFile.tiff Upload data in the S3
'
)
print
(
'
download path/in/S3/file.tiff myFile.tiff Download a data from the S3
'
)
print
(
'
ls folder/path List data in a subfolder
'
)
print
(
'
delete path/in/S3/file.tiff Delete an existing data on S3
'
)
print
(
'
refresh refresh credentials and password
'
)
sys
.
exit
(
2
)
#########################
# Init the bearer #
#########################
def
init
():
if
os
.
path
.
isfile
(
USER_INFO_FILE_PATH
):
print
(
"
File exists
"
)
else
:
print
(
"
File not exists
"
)
email
=
input
(
"
Your email:
"
)
#password
password
=
input
(
"
Your password:
"
)
userinfo
[
'
info
'
]
=
[]
userinfo
[
'
info
'
].
append
({
'
email
'
:
email
,
'
password
'
:
password
})
print
(
userinfo
)
#f = open(USER_INFO_FILE_PATH, "a")
#f.write(email)
#f.write(password)
#f.close()
#########################
# Upload the data in S3 #
#########################
def
upload
(
sourceFile
,
destination
):
print
(
"
[INFO] Source file is :
"
,
sourceFile
)
print
(
"
[INFO] Destination file is :
"
,
destination
)
if
sourceFile
and
destination
:
print
(
"
[INFO] Get an existing or fresh token
"
)
init
()
else
:
display_help
()
# Store argument variable omitting the script name
argv
=
sys
.
argv
[
1
:]
# Initialize result variable
result
=
0
try
:
# Define getopt short and long options
options
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'
u:a:s:h
'
,
[
'
upload=
'
,
'
add=
'
,
'
sub=
'
,
'
help=
'
])
# Read each option using for loop
for
opt
,
arg
in
options
:
# Calculate the sum if the option is -a or --add
if
opt
in
(
'
-u
'
,
'
--upload
'
):
# Check the parameters
if
len
(
argv
)
!=
3
:
display_help
()
else
:
upload
(
argv
[
1
],
argv
[
2
])
# Calculate the suntraction if the option is -s or --sub
elif
opt
in
(
'
-s
'
,
'
--sub
'
):
result
=
int
(
argv
[
1
])
-
int
(
argv
[
2
])
print
(
'
Result =
'
,
result
)
elif
opt
in
(
'
-h
'
,
'
--help
'
):
# Print the option
display_help
()
except
getopt
.
GetoptError
:
# Print the error message if the wrong option is provided
print
(
'
The wrong option is provided. Please run -h
'
)
# Terminate the script
sys
.
exit
(
2
)
\ No newline at end of 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