def create_catalog(): path = check_string(request, params.PATH) name = check_string(request, params.NAME) if not check_path(path): path = None if path == None: return send_error(error_codes.INVALID_PATH, "You need to specify path parameter") if not os.path.isdir(path): return send_no_dir_error(path) if name == "": return jsonify({ "code" : error_codes.INVALID_CATALOG_NAME, "message" : "Invalid name" }) final_path = os.path.join(path, name) if os.path.isdir(final_path): return jsonify({ "code" : error_codes.DATA_MANAGEMENT_ERROR, "message" : "Folder already exsists." }) try: os.mkdir(final_path) return jsonify({ "code" : error_codes.SUCCESFULL_QUERY, "message" : "Folder succesfully created" }) except: return jsonify({ "code" : error_codes.DATA_MANAGEMENT_ERROR, "message" : "An error has occured." })
def youtube_upload(): path = check_string(request, params.PATH) if not check_path(path): path = None if path == None: return send_error(error_codes.INVALID_PATH, "You need to specify path parameter") if not os.path.isdir(path): return send_no_dir_error(path) url = check_string(request, params.URL) if url == None: return send_error(error_codes.INVALID_URL, "You need to specify URL parameter") threaded = check_boolean(request, params.THREADED) if threaded: thread = threading.Thread(target = explorer.downloadYouTube, args = (path, url)) thread.daemon = True thread.start() else: explorer.downloadYouTube(path, url) return jsonify({ "code" : error_codes.SUCCESFULL_QUERY, "message" : "Query has been dispatched" })
def getAllPlaylists(): local = check_boolean(request, params.LOCAL) sortingMethod = check_integer(request, params.SORT) if sortingMethod == None: sortingMethod = check_string(request, params.SORT) sortingMethod = translate_sorting_method(sortingMethod) trackSortingMethod = check_integer(request, params.TRACK_SORT) if trackSortingMethod == None: trackSortingMethod = check_string(request, params.TRACK_SORT) trackSortingMethod = translate_sorting_method(trackSortingMethod, 1) filters = check_int_array(request, params.FILTER) if len(filters) == 0: filters.append(0) #0 means no filtering initialPath = check_string(request, params.PATH) if not check_path(initialPath): initialPath = None if initialPath == None: initialPath = get_defaults()["defaults"]["default_path"] if not os.path.isdir(initialPath): return send_error(error_codes.INVALID_PATH, "Invalid path") respone = explorer.getAllPlaylists(initialPath, sortingMethod, trackSortingMethod, filters, local) if not 'error' in respone: respone['code'] = error_codes.SUCCESFULL_QUERY return jsonify(respone)
def getAllTracks(): simple = check_boolean(request, params.SIMPLE) local = check_boolean(request, params.LOCAL) initialPath = check_string(request, params.PATH) sortingMethod = check_integer(request, params.SORT) if sortingMethod == None: sortingMethod = check_string(request, params.SORT) sortingMethod = translate_sorting_method(sortingMethod, 1) if not check_path(initialPath): initialPath = None if initialPath == None: initialPath = get_defaults()["defaults"]["default_path"] if not os.path.isdir(initialPath): return send_error(error_codes.INVALID_PATH, "Invalid path") respone = explorer.getAllTracks(initialPath, sortingMethod, simple, local) if not 'error' in respone: respone['code'] = error_codes.SUCCESFULL_QUERY return jsonify(respone)
def filter_hyperlinks(self, args): """ for a given paragraph text or a table text, this function filters the table text and returns the table data args = [table, paragraph, text, spec_name]""" #context = Context.from_request(self.req, 'wiki') context = web_context(self.req, 'wiki') #print('inside filter_hyperlinks -> everthing is ok so far before -> regex_id, hypermatches = find_hyperlinks(args[2])') regex_id, hypermatches = find_hyperlinks(args[2]) #print('regex_id, hypermatches = find_hyperlinks(args[2])', regex_id, hypermatches) hyperlink = '' if len(hypermatches) > 0: link_name = '' rest = hypermatches.pop() for hyper in hypermatches: flt_text = '' if self.add_hyper_link == True: #args[2].rows[args[0]].cells[args[1]].\ # paragraphs[0].add_run(hyper[0]) wiki = process_blockquote(check_string(hyper[0])) self.parse_html(args, context, wiki) hyperlink, link_name = self.get_hyperlink( args[3], regex_id, hyper) if hyperlink == None: break add_hyperlink(args[1], hyperlink, link_name, '0000FF', True) elif self.add_hyper_link == False: flt_text = flt_text + hyper[0] #args[2].rows[args[0]].cells[args[1]].\ # paragraphs[0].add_run(flt_text) wiki = process_blockquote(check_string(flt_text)) self.parse_html(args, context, wiki) #args[2].rows[args[0]].cells[args[1]].paragraphs[0].add_run(rest) wiki = process_blockquote(check_string(rest)) self.parse_html(args, context, wiki) else: #print('inside filter_hyperlinks(self, args): after else:') #print('args[2]', args[2]) wiki = process_blockquote(check_string(args[2])) #print('wiki', wiki) #print('args', args) self.parse_html(args, context, wiki) #print('fine so far after self.parse_html(args, context, wiki) in inside filter_hyperlinks(self, args): after else:') #args[2].rows[args[0]].cells[args[1]].text = \ # unicode(args[3], "utf-8") return (args[0], hypermatches)
def file_delete(): path = check_string(request, params.PATH) if not check_path(path): path = None if path == None: return send_error(error_codes.INVALID_PATH, "You need to specify path parameter") if not os.path.exists(path): return send_no_file_error(path) try: if(os.path.isdir(path)): shutil.rmtree(path) else: os.remove(path) return jsonify({ "code" : error_codes.SUCCESFULL_QUERY, "message" : "File/directory deleted" }) except: return jsonify({ "code" : error_codes.DATA_MANAGEMENT_ERROR, "message" : "An error while deleting file has occured" })
def file_upload(): path = check_string(request, params.PATH) if not check_path(path): path = None if path == None: return send_error(error_codes.INVALID_PATH, "You need to specify path parameter") if not os.path.isdir(path): return send_no_dir_error(path) file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file_path = os.path.join(path, filename) file.save(file_path) return jsonify({ "code" : error_codes.SUCCESFULL_QUERY, "path" : file_path, "message" : "File uploaded" }) return jsonify({ "code" : error_codes.UNALLOWED_EXTENSION, "message" : "Unallowed extension" })
def send_audio(): path = check_string(request, params.PATH) if not check_path(path): path = None if path == None: return send_error(error_codes.INVALID_PATH, "You need to specify path parameter") if not file_exsists(path): return send_no_file_error(path) return send_from_directory(directory = os.path.dirname(path), filename = os.path.basename(path))
def get_metadata(): path = check_string(request, params.PATH) if path == None: return send_error(error_codes.INVALID_PATH, "You need to specify path parameter") if not file_exsists(path): return send_no_file_error(path) respone = explorer.getMetadata(path) respone['code'] = error_codes.SUCCESFULL_QUERY return jsonify(respone)
def getDirectory(): path = check_string(request, params.PATH) if path == None: path = get_defaults()['defaults']['default_path'] metadata = check_boolean(request, params.METADATA) sortingMethod = check_integer(request, params.SORT) if sortingMethod == None: sortingMethod = check_string(request, params.SORT) sortingMethod = translate_sorting_method(sortingMethod, 0) if check_path(path): respone = explorer.getPathContent(path, metadata, sorting = sortingMethod) if respone == None: return send_error(error_codes.INVALID_PATH, "Invalid path") else: return send_error(error_codes.INVALID_PATH, "Invalid path") respone['code'] = error_codes.SUCCESFULL_QUERY return jsonify(respone)
def play_track(): currentTrack = trackThreader.currentTrack() trackPath = check_string(request, params.PATH) terminate = check_boolean(request, params.TERMINATE) if not file_exsists(trackPath) or not check_path(trackPath): return send_no_file_error(trackPath) if currentTrack == None: return startTrack(trackPath) else: if terminate: currentTrack.stop() trackThreader.setTrack(None) return startTrack(trackPath) return send_error(error_codes.TRACK_ALREADY_PLAYING, "Track already exsists")