Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
jacquemier
webdavacc
Commits
783e8e78
Commit
783e8e78
authored
Oct 25, 2019
by
jacquemier
Browse files
Test connection
parent
595b9b48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
39 deletions
+83
-39
Notebooks/test_access.ipynb
Notebooks/test_access.ipynb
+19
-12
webdavacc/__init__.py
webdavacc/__init__.py
+64
-27
No files found.
Notebooks/test_access.ipynb
View file @
783e8e78
...
...
@@ -15,29 +15,36 @@
"metadata": {},
"outputs": [],
"source": [
"webdav = webdavacc.connect('lapp-xdc01.in2p3.fr', 'webdavuser', 'webdavuser', protocol='http')"
"webdav = webdavacc.connect('lapp-xdc01.in2p3.fr', 'webdavuser', 'webdavuser', protocol='http'
, port=4
)"
]
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
20
,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[File(name='/', size=0, mtime='Fri, 04 Oct 2019 13:15:56 GMT', ctime='2019-10-04T13:15:56Z', contenttype='httpd/unix-directory'),\n",
" File(name='/test%20manual/', size=0, mtime='Fri, 04 Oct 2019 13:50:21 GMT', ctime='2019-10-04T13:50:21Z', contenttype='httpd/unix-directory')]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"Connexion error\n"
]
}
],
"source": [
"webdav.ls()"
"try: \n",
" webdav.ls()\n",
" print('Connexion success')\n",
"except:\n",
" print('Connexion error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
webdavacc/__init__.py
View file @
783e8e78
...
...
@@ -12,47 +12,75 @@ rmdir(path, safe=False)
delete(file_path)
upload(local_path_or_fileobj, remote_path)
download(remote_path, local_path_or_fileobj)
black = lambda text: '
\033
[0;30m' + text + '
\033
[0m'
red = lambda text: '
\033
[0;31m' + text + '
\033
[0m'
green = lambda text: '
\033
[0;32m' + text + '
\033
[0m'
yellow = lambda text: '
\033
[0;33m' + text + '
\033
[0m'
blue = lambda text: '
\033
[0;34m' + text + '
\033
[0m'
magenta = lambda text: '
\033
[0;35m' + text + '
\033
[0m'
cyan = lambda text: '
\033
[0;36m' + text + '
\033
[0m'
white = lambda text: '
\033
[0;37m' + text + '
\033
[0m'
'''
def
INFO
(
text
):
class
LogLevel
:
ERROR
=
lambda
text
:
'
\033
[0;31m'
+
text
+
'
\033
[0m'
INFO
=
lambda
text
:
'
\033
[0;32m'
+
text
+
'
\033
[0m'
def
log
(
level
,
text
):
"""
Display
text in green
Display
colored text
Parameters
----------
test : string
level : LogLevel constant
text : string
test to display.
"""
green
=
lambda
text
:
'
\033
[0;32m'
+
text
+
'
\033
[0m'
print
(
green
(
text
))
print
(
level
(
text
))
def
connect
(
server
,
username
,
password
,
port
=
80
,
protocol
=
'https'
):
"""
WebDav Connection.
Parameters
----------
server : string
WebDav server.
username : string
WebDav username.
password : string
WebDav password.
protocol : port
webdav port default=80
protocol : string
webdav protocol default=https
Returns
-------
easywebdav.client.Client
"""
return
easywebdav
.
connect
(
server
,
WebDav Connection.
Parameters
----------
server : string
WebDav server.
username : string
WebDav username.
password : string
WebDav password.
protocol : port
webdav port default=80
protocol : string
webdav protocol default=https
Returns
-------
easywebdav.client.Client is case of connection success
Raises
------
Exception
If the connexion failed
"""
webdav
=
easywebdav
.
connect
(
server
,
username
=
username
,
password
=
password
,
protocol
=
protocol
,
port
=
port
)
try
:
webdav
.
ls
()
return
webdav
except
:
raise
Exception
def
main
():
parser
=
argparse
.
ArgumentParser
()
...
...
@@ -69,8 +97,17 @@ def main():
if
args
.
verbose
:
print
(
"verbosity turned on"
)
INFO
(
'INFO::Connect to Webdav server[{}], username[{}], protocol[{'
\
'}]'
.
format
(
args
.
server
,
args
.
username
,
args
.
protocol
))
try
:
webdav
=
connect
(
args
.
server
,
args
.
username
,
args
.
username
,
args
.
port
,
args
.
protocol
)
log
(
LogLevel
.
INFO
,
'Connect to Webdav server[{}], username[{}], '
'protocol[{}] success'
.
format
(
args
.
server
,
args
.
username
,
args
.
protocol
))
except
:
log
(
LogLevel
.
ERROR
,
'Connect to Webdav server[{}], username[{}], '
'protocol[{'
\
'}] failed'
.
format
(
args
.
server
,
args
.
username
,
args
.
protocol
))
if
__name__
==
'__main__'
:
...
...
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