Commit 35688dc7 authored by jacquemier's avatar jacquemier
Browse files

B4 changing webdav API library

parent 67d0f9a3
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
......@@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -96,6 +96,121 @@
"result[0]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[File(name='/Jean/', size=0, mtime='Mon, 28 Oct 2019 07:50:59 GMT', ctime='2019-10-28T07:50:59Z', contenttype='httpd/unix-directory')]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"webdavacc.execute(webdav, 'ls', '/Jean')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"webdavacc.execute(webdav, 'mkdir', '/Jean')"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"#cRIO_Data_190917_111435.tdms\n",
"#cRIO_Data_190917_111435.tdms_ index"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cRIO_Data_190917_111430.tdms\n"
]
},
{
"ename": "TypeError",
"evalue": "upload() missing 1 required positional argument: 'remote_path'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-23-4fec8567f6bc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mwebdavacc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwebdav\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'upload'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'/tmp/filename'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'/Jean'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/workspace/Accelerateur/webdavacc/webdavacc/__init__.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(webdav, command, arguments)\u001b[0m\n\u001b[1;32m 146\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwebdav\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdelete\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marguments\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 147\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mcommand\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'upload'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 148\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mwebdav\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marguments\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 149\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mcommand\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'download'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 150\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwebdav\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdownload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marguments\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: upload() missing 1 required positional argument: 'remote_path'"
]
}
],
"source": [
"for i in range(10):\n",
" filename = 'cRIO_Data_190917_11143'+str(i)+'.tdms'\n",
" print(filename)\n",
" \n",
" webdavacc.execute(webdav, 'upload', ('/tmp/filename', '/Jean')) "
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" basestring\n",
"except NameError:\n",
" basestring = str"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'basestring' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-39-aca3757acdd4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mwebdav\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/tmp/cRIO_Data_190917_111437.tdms'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'/Jean/cRIO_Data_190917_111437.tdms'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/anaconda3/envs/cta-dev/lib/python3.6/site-packages/easywebdav/client.py\u001b[0m in \u001b[0;36mupload\u001b[0;34m(self, local_path_or_fileobj, remote_path)\u001b[0m\n\u001b[1;32m 151\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mupload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlocal_path_or_fileobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mremote_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 153\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocal_path_or_fileobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbasestring\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 154\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocal_path_or_fileobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'rb'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 155\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_upload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mremote_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'basestring' is not defined"
]
}
],
"source": [
"webdav.upload('/tmp/cRIO_Data_190917_111437.tdms', '/Jean/cRIO_Data_190917_111437.tdms')\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"?webdav.upload"
]
},
{
"cell_type": "code",
"execution_count": null,
......
......@@ -71,8 +71,28 @@ def connect(server, username, password, port =80, protocol='https'):
except:
raise Exception
def auto(webdav):
'''
Automatically get the new file minus the current one
def execute(webdav, command, arguments):
Parameters
----------
webdav: easywebdav.client.Client
webdav connected instance
Returns
-------
command result
Raises
------
Exception
If an error occurs
'''
return True
def execute(webdav, command, arguments=None):
'''
WebDav command execution.
......@@ -95,7 +115,7 @@ def execute(webdav, command, arguments):
If command failed or does not exist
'''
available_command = ('cd', 'ls', 'exists', 'mkdir', 'mkdirs', 'rmdir',
'delete', 'upload', 'download')
'delete', 'upload', 'download', 'auto')
#if command not in available_command:
find = False
......@@ -108,7 +128,9 @@ def execute(webdav, command, arguments):
if not arguments:
arguments = ''
if command == 'cd':
elif command == 'auto':
return auto(webdav)
elif command == 'cd':
return webdav.cd(arguments)
elif command == 'ls':
return webdav.ls(arguments)
......@@ -130,10 +152,12 @@ def execute(webdav, command, arguments):
def main():
parser = argparse.ArgumentParser(formatter_class = argparse.RawDescriptionHelpFormatter,
epilog = textwrap.dedent('''\
Command arguments:
auto (automatically get and delete new files on webdav CompactRio server. Do not get and delete current acquisition file)
cd -a path
ls -a path=None
exists -a remote_path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment