raiseOptionValueError("Too many arguments. This option need exactly one argument.")
path=parser.rargs[0]
if(os.path.isdir(path)):
res=api_client.add_watched_dir(path)
if(resisNone):
exit("Unable to connect to the server.")
# sucess
if(res['msg']['code']==0):
print"%s added to watched folder list successfully"%path
else:
print"Adding a watched folder failed. : %s"%res['msg']['error']
else:
print"Given path is not a directory: %s"%path
defWatchListAction(option,opt,value,parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs)>0):
raiseOptionValueError("This option doesn't take any argument.")
res=api_client.list_all_watched_dirs()
if(resisNone):
exit("Unable to connect to the server.")
dirs=res["dirs"].items()
# there will be always 1 which is storage folder
if(len(dirs)==1):
print"No watch folders found"
else:
forkey,vindirs:
if(key!='1'):
printv
defWatchRemoveAction(option,opt,value,parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs)>1):
raiseOptionValueError("Too many arguments. This option need exactly one argument.")
path=parser.rargs[0]
if(os.path.isdir(path)):
res=api_client.remove_watched_dir(path)
if(resisNone):
exit("Unable to connect to the server.")
# sucess
if(res['msg']['code']==0):
print"%s removed from watched folder list successfully"%path
else:
print"Removing a watched folder failed. : %s"%res['msg']['error']
else:
print"Given path is not a directory: %s"%path
defStorageSetAction(option,opt,value,parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs)>1):
raiseOptionValueError("Too many arguments. This option need exactly one argument.")
if(os.path.isdir(values)):
res=api_client.set_storage_dir(values)
if(resisNone):
exit("Unable to connect to the server.")
# sucess
if(res['msg']['code']==0):
print"Successfully set storage folder to %s"%values
else:
print"Setting storage folder to failed.: %s"%res['msg']['error']
else:
print"Given path is not a directory: %s"%values
defStorageGetAction(option,opt,value,parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs)>0):
raiseOptionValueError("This option doesn't take any argument.")
printhelper_get_stor_dir()
parser=OptionParser(add_help_option=False)
parser.add_option('-c','--copy',action='callback',callback=CopyAction,metavar='FILE',help='Copy FILE(s) into the storage directory.\nYou can specify multiple files or directories.')
parser.add_option('-m','--move',action='callback',callback=MoveAction,metavar='FILE',help='Move FILE(s) into the storage directory.\nYou can specify multiple files or directories.')
parser.add_option('--watch-add',action='callback',callback=WatchAddAction,help='Add DIR to the watched folders list.')
parser.add_option('--watch-list',action='callback',callback=WatchListAction,help='Show the list of folders that are watched.')
parser.add_option('--watch-remove',action='callback',callback=WatchRemoveAction,help='Remove DIR from the watched folders list.')
parser.add_option('--storage-dir-set',action='callback',callback=StorageSetAction,help='Set storage dir to DIR.')
parser.add_option('--storage-dir-get',action='callback',callback=StorageGetAction,help='Show the current storage dir.')
parser.add_option('-h','--help',dest='help',action='store_true',help='show this help message and exit')