Skip to content
Snippets Groups Projects
Commit 28f059f0 authored by kosted's avatar kosted
Browse files

[1/5] init and upload initialisation

parent ed9e0c9f
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment