def ask_video(): print() data = {} val = validators.match(values.RELPATH_RE) data['main'] = cn.rvpl('main [video.mp4]:', validator=valwrap(val), intro=""" Main video file to load when content is opened. Must be a relative path. Defaults to video.mp4. """, strict=False, default='video.mp4') print() data['description'] = cn.rvpl('description:', intro=""" Short plain-text description of the content package. Description MUST NOT contain markup or code. """, strict=False, default='') print() data['duration'] = cn.rvpl('duration:', validator=check_duration, intro=""" Positive non-zero integer representing the duration of a video file in seconds. """, strict=False, default='') print() val = validators.match(values.SIZE_RE) data['size'] = cn.rvpl('size:', validator=valwrap(val), intro=""" Size is image size in "WIDTHxHEIGHT" format in pixels. """, strict=False, default='') return data
def ask_image(): print() data = {} data['description'] = cn.rvpl('description:', intro=""" Short plain-text description of the content package. Description MUST NOT contain markup or code. """, strict=False, default='') a = True data['album'] = [] print('\nBeginning to define the album. For each item in the album the' ' following fields are available: file (required), title, thumbnail,' ' caption, size, and description. After completing each item you ' 'will be asked if you would like to add another.') while a == True: item = {} print() val = validators.match(values.RELPATH_RE) item['file'] = cn.rvpl('file:', validator=valwrap(val), intro=""" Path to image file to be shown. Must be a relative path. Required. """, strict=True) print() item['title'] = cn.rvpl('title:', strict=False, default='', validator=valwrap(validators.nonempty), intro=""" Title of the image file. """) print() validator = validators.match(values.RELPATH_RE) item['thumbnail'] = cn.rvpl('thumbnail:', validator=valwrap(validator), intro=""" Thumbnail of the image. Should be relative to the top level path of the content package. """, strict=False, default='') print() item['caption'] = cn.rvpl('caption:', intro=""" A caption to be shown below the image by the viewer. """, strict=False, default='') print() val = validators.match(values.SIZE_RE) item['size'] = cn.rvpl('size:', validator=valwrap(val), intro=""" Size is image size in "WIDTHxHEIGHT" format in pixels. """, strict=False, default='') print() item['description'] = cn.rvpl('description:', intro=""" Short plain-text description of the image. Description MUST NOT contain markup or code. """, strict=False, default='') print() data['album'].append({k: v for k, v in item.items() if v}) a = cn.yesno('add another entry?') return data
def ask_cover(): print() validator = validators.match(values.RELPATH_RE) return cn.rvpl('cover [cover.jpg]:', validator=valwrap(validator), intro=""" Cover points to the file that should seve as the cover image of the content. It should be a relative path relative to the top level path of the content package. If left blank, cover.jpg is assumed. """, strict=False, default='cover.jpg')
def ask_index(): print() validator = validators.match(values.RELPATH_RE) return cn.rvpl('index [index.html]:', validator=valwrap(validator), intro=""" Index points to the file that should serve as main page of the content. It should be a relative path relative to the top level path of the content package. If left blank, index.html is assumed. """, strict=False, default='index.html')
def ask_thumbnail(): print() validator = validators.match(values.RELPATH_RE) return cn.rvpl('thumbnail [thumbnail.png]:', validator=valwrap(validator), intro=""" Thumbnail points to the file that should seve as the thumbnail of the content. It should be a relative path relative to the top level path of the content package. If left blank, thumbnail.png is assumed. """, strict=False, default='thumbnail.png')
def ask_keywords(): """ Gets comma-separate keywords from user input """ cn.pstd() validator = validators.match(values.COMMASEP_RE) ret = cn.rvpl('keywords []:', validator=valwrap(validator), intro=""" Keywords are used when searching and classifying content. Keywords cannot contain commas, and multiple keywords are supplied separated by commas. For example: medical,medicine,farming,plant,biology """, strict=False, default='') kws = [s.strip() for s in ret.split(',')] return ','.join([s for s in kws if s])
def ask_index(): print() validator = validators.match(values.RELPATH_RE) return cn.rvpl('index [index.html]:', validator=valwrap(validator), intro=""" Index points to the file that should seve as main page of the content. It should be a relative path relative to the top level path of the content package. If left blank, index.html is assumed. """, strict=False, default='index.html')
def ask_language(): """ Get content locale """ print() validator = validators.match(values.LOCALE_RE) return cn.rvpl('language []:', validator=valwrap(validator), intro=""" Content language is specified standard ISO 639-1 locale codes. For example: pt_BR. You will find a list of locale codes at: http://loc.gov/standards/iso639-2/php/code_list.php Language is optional, but it allows users to search content in specific language, so it is recommended to set it. """, strict=False, default='')
def ask_html(): print() data = {} val = validators.match(values.RELPATH_RE) data['main'] = cn.rvpl('main [index.html]:', validator=valwrap(val), intro=""" Main HTML file to load when content is opened. Must be a relative path. Defaults to index.html. """, strict=False, default='index.html') print() data['keep_formatting'] = cn.yesno('keep_formatting?', default=False, intro=""" If content uses its own formatting select "yes". Defaults to false. """) return data
def ask_audio(): print() data = {} data['description'] = cn.rvpl('description:', intro=""" Short plain-text description of the content package. Description MUST NOT contain markup or code. """, strict=False, default='') a = True data['playlist'] = [] print('\nBeginning to define the playlist. For each item in the playlist the' ' following fields are available: file (required), duration, and ' 'title. After completing each item you will be asked if you would ' ' like to add another.') while a == True: item = {} print() val = validators.match(values.RELPATH_RE) item['file'] = cn.rvpl('file:', validator=valwrap(val), intro=""" Path to audio file to be played. Must be a relative path. Required. """, strict=True) print() item['duration'] = cn.rvpl('duration:', validator=check_duration, intro=""" Positive non-zero integer representing the duration of a video file in seconds. """, strict=False, default='') print() item['title'] = cn.rvpl('title:', strict=False, default='', validator=valwrap(validators.nonempty), intro=""" Title of the audio file. """) print() data['playlist'].append({k: v for k, v in item.items() if v}) a = cn.yesno('add another entry?') return data
'images': 0, 'index': 'index.html', 'is_partner': False, 'is_sponsored': False, 'keep_formatting': False, 'keywords': '', 'language': '', 'multipage': False, 'publisher': '', } SPECS = { 'title': [v.required, v.nonempty], 'url': [v.required, v.nonempty, v.url], 'timestamp': [v.required, v.nonempty, v.timestamp(TS_FMT)], 'broadcast': [v.required, v.nonempty, v.OR(v.timestamp(DATE_FMT), v.match(PLACEHOLDER_RE))], 'license': [v.required, v.isin(LICENSES)], 'images': [v.optional(), v.istype(int), v.gte(0)], 'language': [v.optional(''), v.nonempty, v.match(LOCALE_RE)], 'multipage': [v.optional(), v.istype(bool)], 'index': [v.optional(''), v.match(RELPATH_RE)], 'keywords': [v.optional(''), v.nonempty, v.match(COMMASEP_RE)], 'archive': [v.optional(''), v.nonempty], 'publisher': [v.optional(''), v.nonempty], 'is_partner': [v.optional(), v.istype(bool)], 'is_sponsored': [v.optional(), v.istype(bool)], 'keep_formatting': [v.optional(), v.istype(bool)], 'replaces': [v.optional(''), v.match(CONTENT_ID_RE)], }
DEFAULTS = { 'archive': 'core', 'index': 'index.html', 'is_partner': False, 'is_sponsored': False, 'keywords': '', 'language': '', 'multipage': False, 'publisher': '', 'content': { 'html': {} }, } TYPE_SPECS = { 'html': { 'main': [v.required, v.match(RELPATH_RE)], 'keep_formatting': [v.optional(), v.istype(bool)], }, 'video': { 'main': [v.required, v.match(RELPATH_RE)], 'description': [v.optional(), v.instanceof(str_type)], 'duration': [v.optional(), v.istype(int), v.gte(1)], 'size': [v.optional(), v.match(SIZE_RE)], }, 'audio': { 'description': [v.optional(), v.instanceof(str_type)], 'playlist': [v.required, v.istype(list), v.min_len()], }, 'audio.playlist': { 'file': [v.required, v.instanceof(str_type), v.match(RELPATH_RE)],
'is_sponsored': False, 'keep_formatting': False, 'keywords': '', 'language': '', 'multipage': False, 'publisher': '', } SPECS = { 'title': [v.required, v.nonempty], 'url': [v.required, v.nonempty, v.url], 'timestamp': [v.required, v.nonempty, v.timestamp(TS_FMT)], 'broadcast': [ v.required, v.nonempty, v.OR(v.timestamp(DATE_FMT), v.match(PLACEHOLDER_RE)) ], 'license': [v.required, v.isin(LICENSES)], 'images': [v.optional(), v.istype(int), v.gte(0)], 'language': [v.optional(''), v.nonempty, v.match(LOCALE_RE)], 'multipage': [v.optional(), v.istype(bool)], 'index': [v.optional(''), v.match(RELPATH_RE)], 'keywords': [v.optional(''), v.nonempty, v.match(COMMASEP_RE)], 'archive': [v.optional(''), v.nonempty], 'publisher': [v.optional(''), v.nonempty], 'is_partner': [v.optional(), v.istype(bool)], 'is_sponsored': [v.optional(), v.istype(bool)], 'keep_formatting': [v.optional(), v.istype(bool)],