Commit 133a7d8f authored by jacquemier's avatar jacquemier
Browse files

relase 0.1

parent 5f5cc428
......@@ -4,18 +4,6 @@ import easywebdav
import textwrap
import argparse
'''
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'
'''
class LogLevel:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
......@@ -26,7 +14,6 @@ class LogLevel:
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def log(level, text):
"""
Display colored text
......@@ -36,9 +23,7 @@ def log(level, text):
text : Object
test to display.
"""
print level + str(text) + LogLevel.ENDC
print(level + str(text) + LogLevel.ENDC)
def connect(server, username, password, port =80, protocol='https'):
"""
......@@ -77,10 +62,11 @@ def connect(server, username, password, port =80, protocol='https'):
except:
raise Exception
def auto(webdav):
def auto(webdav, local_path, remote_path=""):
'''
Automatically get the new file minus the current one
Automatically get the new file (with tdms extension ) except the current
one (extention
tdms_index)
Parameters
----------
......@@ -93,10 +79,32 @@ def auto(webdav):
Raises
------
Exception
If an error occurs
Exception: if an error occurs
'''
return True
result = webdav.ls(remote_path)
# find current acquired file
current = None
for file in result:
if not file.name.find('index') == -1: # Current acquired file
current = file.name[0:file.name.find('index')-1]
#download each file, except the current one and delete
for file in result:
if not file.name == current:
if file.name[-4:] == "tdms":
full_local_path = local_path + "/" + file.name[
file.name.rfind('/')+1:]
try:
webdav.download(file.name, full_local_path)
webdav.delete(file.name)
log(LogLevel.INFO, "Download and delete [{"
"}]".format(file.name))
except :
raise Exception("Auto fail. Could not download "
"remotre file")
else:
log(LogLevel.INFO, "Do not touch current acquired file [{}]".format(
file.name))
def list_dir_content(webdav, directory):
'''
......@@ -109,13 +117,12 @@ def list_dir_content(webdav, directory):
directory : string
directory to list
'''
#log(LogLevel.INFO, webdav.ls(directory))
result=webdav.ls(directory)
print "total " + str(len(result))
print("total " + str(len(result)))
for file in result:
print str(file.mtime) + "\t" + str(file.size) + "\t" + \
print(str(file.mtime) + "\t" + str(file.size) + "\t" + \
str(file.contenttype) +\
"\t" + str(file.name)
"\t" + str(file.name))
def execute(webdav, command, arguments=None):
'''
......@@ -139,50 +146,47 @@ def execute(webdav, command, arguments=None):
Exception
If command failed or does not exist
'''
available_command = ('cd', 'ls', 'exists', 'mkdir', 'mkdirs', 'rmdir',
available_command = ('ls', 'exists', 'mkdir', 'rmdir',
'delete', 'upload', 'download', 'auto')
"""
find = False
for cmd in available_command:
if command.find(cmd) == 0:
find = True
if not find:
"""
if not command in available_command:
raise Exception("command {} not available".format(command))
if not arguments:
arguments = ''
if command == 'auto':
return auto(webdav)
elif command == 'cd':
return webdav.cd(arguments)
elif command == 'ls':
if command == 'ls':
list_dir_content(webdav, arguments)
elif command == 'exists':
return webdav.exists(arguments)
elif command == 'mkdir':
return webdav.mkdir(arguments)
elif command == 'mkdirs':
return webdav.mkdirs(arguments)
elif command == 'rmdir':
return webdav.rmdir(arguments)
elif command == 'delete':
return webdav.delete(arguments)
elif command == 'upload' or command == 'download':
elif command == 'upload' or command == 'download' or command == 'auto':
# convert string of arguments to list of arguments
if isinstance(arguments, str):
arguments = arguments.split()
if len(arguments) !=2:
raise Exception("Download wait 2 arguments remote_path, local_path")
if command == 'upload':
#webdav.download(remote_path, local_path)
return webdav.upload(arguments[0], arguments[1])
if command == 'download':
#webdav.upload(local_path, remote_path)
return webdav.upload(arguments[0], arguments[1])
elif command == 'download':
#webdav.download(remote_path, local_path)
return webdav.download(arguments[0], arguments[1])
elif command == 'auto':
return auto(webdav, arguments[0], arguments[1])
......@@ -200,14 +204,12 @@ def parse_args():
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
mkdir -a path
mkdirs -a path
rmdir -a path
delete -a file_path
auto -a "local_path, remote_path" (automatically get and delete new files on webdav CompactRio server. Do not get and delete current acquisition file)
upload -a "local_path remote_path"
download -a "remote_path, local_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