mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-03 09:29:16 +02:00
correct docopt syntax and validation with schema
This commit is contained in:
parent
8863c6856d
commit
3e0865ad43
1 changed files with 30 additions and 32 deletions
|
@ -5,17 +5,17 @@
|
||||||
ptyt_upload - tool to upload videos to Peertube and Youtube
|
ptyt_upload - tool to upload videos to Peertube and Youtube
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
ptyt_upload --file=/path/to/video [options]
|
ptyt_upload.py --file=<FILE> [options]
|
||||||
ptyt_upload -h | --help
|
ptyt_upload.py -h | --help
|
||||||
ptyt_upload --version
|
ptyt_upload.py --version
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--file=PATH Path to the video to upload.
|
--name=NAME Name of the video to upload. default to video file name
|
||||||
--name=STRING Name of the video to upload. (default to video file name)
|
-d, --description=STRING Description of the video.
|
||||||
-d --description=STRING Description of the video.
|
-t, --tags=STRING Tags for the video. comma separated
|
||||||
-t --tags=STRING Tags for the video. (comma separated)
|
-h --help Show this help.
|
||||||
--version Show version.
|
--version Show version.
|
||||||
-h --help Show this help.
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -46,30 +46,28 @@ def validateVideo(path):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
#Allows you to a relative import from the parent folder
|
#Allows you to a relative import from the parent folder
|
||||||
import os.path, sys
|
import os.path, sys
|
||||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))+"/lib")
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))+"/lib")
|
||||||
|
|
||||||
import yt_upload
|
import yt_upload
|
||||||
import pt_upload
|
import pt_upload
|
||||||
|
|
||||||
options = docopt(__doc__, version=VERSION)
|
options = docopt(__doc__, version=VERSION)
|
||||||
|
print options
|
||||||
|
|
||||||
schema = Schema({
|
schema = Schema({
|
||||||
'--file': And(str, lambda s: validateVideo(s), error='file is not supported, please use mp4'),
|
'--file': And(str, lambda s: validateVideo(s), error='file is not supported, please use mp4'),
|
||||||
Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
|
Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
|
||||||
Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
|
Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
|
||||||
Optional('--d'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
|
Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
|
||||||
Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
|
'--help': bool,
|
||||||
Optional('--t'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
|
'--version': bool
|
||||||
'-h': bool,
|
})
|
||||||
'--help': bool,
|
|
||||||
'--version': bool
|
|
||||||
})
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
options = schema.validate(options)
|
options = schema.validate(options)
|
||||||
except SchemaError as e:
|
except SchemaError as e:
|
||||||
exit(e)
|
exit(e)
|
||||||
|
|
||||||
# yt_upload.run(args)
|
yt_upload.run(options)
|
Loading…
Add table
Add a link
Reference in a new issue