Commit 26cebe78 authored by jacquemier's avatar jacquemier
Browse files

Pass to Python2

parent 35688dc7
......@@ -2,213 +2,139 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import webdavacc"
"import easywebdav"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"webdav = webdavacc.connect('lapp-xdc01.in2p3.fr', 'webdavuser', 'webdavuser', protocol='http')"
"'''\n",
"username='webdavuser',\n",
"password='webdavuser',\n",
"'''\n",
"webdav=easywebdav.connect('lapp-xdc01.in2p3.fr',\n",
" protocol='http',\n",
" port=80)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"result = webdav.ls(\"/test%20manual/Jean\")"
"files = webdav.ls('/Jean')"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"file_res=result[0]"
]
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/test%20manual/Jean/'"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"file_res.name"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[File(name='/test%20manual/Jean/', size=0, mtime='Fri, 25 Oct 2019 11:54:40 GMT', ctime='2019-10-25T11:54:40Z', contenttype='httpd/unix-directory')]"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"File(name='/test%20manual/Jean/', size=0, mtime='Fri, 25 Oct 2019 11:54:40 GMT', ctime='2019-10-25T11:54:40Z', contenttype='httpd/unix-directory')"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"File(name='/Jean/', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='httpd/unix-directory')\n",
"File(name='/Jean/cRIO_Data_190917_111434.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111436.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111433.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111431.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:04 GMT', ctime='2019-10-28T13:24:04Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111439.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111435.tdms_index', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111432.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:04 GMT', ctime='2019-10-28T13:24:04Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111438.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111437.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n",
"File(name='/Jean/cRIO_Data_190917_111435.tdms', size=0, mtime='Mon, 28 Oct 2019 13:24:05 GMT', ctime='2019-10-28T13:24:05Z', contenttype='text/plain')\n"
]
}
],
"source": [
"result[0]"
"for file in files:\n",
" print(file)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 16,
"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"
"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-16-3fe41326da3e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mbasestring\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mbytes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mwebdav\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"cRIO_Data_190917_111439.tdms\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"/tmp/cRIO_Data_190917_111439.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": [
"webdavacc.execute(webdav, 'ls', '/Jean')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"webdavacc.execute(webdav, 'mkdir', '/Jean')"
"basestring = (str,bytes)\n",
"webdav.upload(\"cRIO_Data_190917_111439.tdms\", \"/tmp/cRIO_Data_190917_111439.tdms\" )"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#cRIO_Data_190917_111435.tdms\n",
"#cRIO_Data_190917_111435.tdms_ index"
"?webdav.upload"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 12,
"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'"
"6.3.1\r\n"
]
}
],
"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')) "
]
"source": []
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" basestring\n",
"except NameError:\n",
" basestring = str"
"arg=\"remote dest\"\n"
]
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 13,
"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"
]
"data": {
"text/plain": [
"['remote', 'dest']"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"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"
"arg.split()"
]
},
{
......
# -*- coding: utf-8 -*-
import easywebdav
import textwrap
import argparse
......@@ -14,10 +16,15 @@ cyan = lambda text: '\033[0;36m' + text + '\033[0m'
white = lambda text: '\033[0;37m' + text + '\033[0m'
'''
class LogLevel:
ERROR=lambda text: '\033[0;31m' + text + '\033[0m'
INFO=lambda text: '\033[0;32m' + text + '\033[0m'
HEADER = '\033[95m'
OKBLUE = '\033[94m'
INFO = '\033[92m'
WARNING = '\033[93m'
ERROR = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def log(level, text):
......@@ -29,7 +36,8 @@ def log(level, text):
text : string
test to display.
"""
print(level(text))
#print level(text)
print level + text + LogLevel.ENDC
......@@ -123,6 +131,7 @@ def execute(webdav, command, arguments=None):
if command.find(cmd) == 0:
find = True
if not find:
raise Exception("command {} not available".format(command))
......@@ -147,7 +156,10 @@ def execute(webdav, command, arguments=None):
elif command == 'upload':
return webdav.upload(arguments)
elif command == 'download':
return webdav.download(arguments)
#webdav.download("/Jean/cRIO_Data_190917_111435.tdms", "/tmp/test/cRIO_Data_190917_111435.tdms")
if len(arguments) !=2:
raise Exception("Download wait 2 arguments remote_path, local_path")
return webdav.download(arguments[0], arguments[1])
......@@ -183,9 +195,11 @@ def main():
args = parser.parse_args()
# convert string of arguments to list of arguments
args.arguments = args.arguments.split()
if args.verbose:
print("verbosity turned on")
print "verbosity turned on"
try:
webdav = connect(args.server, args.username,args.username,
......@@ -194,13 +208,20 @@ def main():
'protocol[{}] success'
.format(args.server, args.username, args.protocol))
log(LogLevel.INFO, str(execute(webdav, args.command, args.arguments)))
except:
log(LogLevel.ERROR, 'Connect to Webdav server[{}], username[{}], '
'protocol[{' \
'}] failed'.format(args.server, args.username, args.protocol))
return
try:
result = execute(webdav, args.command, args.arguments)
log(LogLevel.INFO, "Command {} succeeded".format(args.command))
except Exception as e:
log(LogLevel.ERROR, 'Execute command {} to Webdav server[{}] '
'failed. {}'.format(args.command, args.server,
e))
if __name__ == '__main__':
......
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