Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Yi Sun
band-artifacts
Commits
cb0699ca
Commit
cb0699ca
authored
May 03, 2022
by
Yi Sun
Browse files
Upload New File
parent
5bd1aeae
Changes
1
Hide whitespace changes
Inline
Side-by-side
mount-s3.py
0 → 100644
View file @
cb0699ca
import
tkinter
as
tk
import
subprocess
from
tkinter
import
messagebox
from
os.path
import
expanduser
import
os
def
mount
():
home
=
expanduser
(
"~"
)
pass_file
=
home
+
"/.passwd-s3fs"
mount_dir
=
home
+
"/"
+
bucket_entry
.
get
()
if
not
os
.
path
.
exists
(
mount_dir
):
os
.
makedirs
(
mount_dir
)
passwd_s3fs
=
open
(
pass_file
,
"w"
)
passwd_s3fs
.
write
(
access_entry
.
get
()
+
":"
+
secret_entry
.
get
())
passwd_s3fs
.
close
()
subprocess
.
call
([
'chmod'
,
'0600'
,
pass_file
])
if
os
.
path
.
ismount
(
mount_dir
):
messagebox
.
showerror
(
title
=
"Error"
,
message
=
"Bucket is already mounted"
)
else
:
subprocess
.
call
([
'mkdir'
,
'-p'
,
mount_dir
])
if
sv
==
"EMBL"
:
p1
=
subprocess
.
Popen
([
"s3fs"
,
bucket_entry
.
get
(),
mount_dir
,
"-o"
,
"url=https://s3.embl.de"
,
"-o"
,
"use_path_request_style"
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
elif
sv
==
"Others"
:
p1
=
subprocess
.
Popen
([
"s3fs"
,
bucket_entry
.
get
(),
mount_dir
,
"-o"
,
"url="
+
endpoint
.
get
(),
"-o"
,
"use_path_request_style"
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
else
:
p1
=
subprocess
.
Popen
(
[
"s3fs"
,
bucket_entry
.
get
(),
mount_dir
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
output
,
err
=
p1
.
communicate
()
if
err
==
""
:
if
os
.
path
.
ismount
(
mount_dir
):
messagebox
.
showinfo
(
"Success!!"
,
"Your S3 bucket is mounted!"
)
subprocess
.
check_call
([
'xdg-open'
,
mount_dir
])
else
:
messagebox
.
showerror
(
"Error!!"
,
"Error mounting S3 bucket, please check your credentials and try again !"
)
else
:
messagebox
.
showerror
(
"Error!!"
,
"Error mounting S3 bucket, please check your credentials and try again !"
)
def
_get
(
s
):
sv
=
s
if
sv
==
"Others"
:
endpoint
.
grid
()
typelbl
.
grid
(
row
=
1
)
else
:
endpoint
.
grid_remove
()
typelbl
.
grid_forget
()
master
=
tk
.
Tk
()
master
.
title
(
"EMBL S3 client"
)
OptionList
=
[
"EMBL"
,
"AWS"
,
"Others"
]
loc_var
=
tk
.
StringVar
()
loc_var
.
set
(
OptionList
[
0
])
sv
=
OptionList
[
0
]
location
=
tk
.
OptionMenu
(
master
,
loc_var
,
*
OptionList
,
command
=
_get
)
location
.
config
(
width
=
20
)
location
.
grid
(
row
=
0
,
column
=
1
,
sticky
=
"ew"
)
# location.pack(side="top")
tk
.
Label
(
master
,
text
=
"S3 types"
).
grid
(
row
=
0
)
typelbl
=
tk
.
Label
(
master
,
text
=
"Endpoint"
)
typelbl
.
grid
(
row
=
1
)
tk
.
Label
(
master
,
text
=
"Access Key"
).
grid
(
row
=
2
)
tk
.
Label
(
master
,
text
=
"Secret Key"
).
grid
(
row
=
3
)
tk
.
Label
(
master
,
text
=
"Bucket"
).
grid
(
row
=
4
)
endpoint
=
tk
.
Entry
(
master
,
width
=
30
)
typelbl
.
grid_forget
()
access_entry
=
tk
.
Entry
(
master
,
width
=
30
)
secret_entry
=
tk
.
Entry
(
master
,
width
=
30
)
bucket_entry
=
tk
.
Entry
(
master
,
width
=
30
)
endpoint
.
grid
(
row
=
1
,
column
=
1
,
padx
=
5
,
pady
=
5
)
access_entry
.
grid
(
row
=
2
,
column
=
1
,
padx
=
5
,
pady
=
5
)
secret_entry
.
grid
(
row
=
3
,
column
=
1
,
padx
=
5
,
pady
=
5
)
bucket_entry
.
grid
(
row
=
4
,
column
=
1
,
padx
=
5
,
pady
=
5
)
endpoint
.
grid_remove
()
tk
.
Button
(
master
,
text
=
'Quit'
,
command
=
master
.
quit
).
grid
(
row
=
5
,
column
=
0
,
sticky
=
tk
.
W
,
pady
=
4
)
tk
.
Button
(
master
,
text
=
'Mount'
,
command
=
mount
).
grid
(
row
=
5
,
column
=
1
,
sticky
=
tk
.
W
,
pady
=
4
)
master
.
mainloop
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment