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 startPlaylist(tracks, defaultPosition = 0): if defaultPosition != None and is_valid_num(0, len(tracks) - 1, defaultPosition): data = playlistThreader.getThread(tracks, defaultPosition) else: data = playlistThreader.getThread(tracks) if len(tracks) == 0: return send_error(error_codes.NO_PATH_DEFINED, "No track parameter passed.") errorPos = [] for index, trackPath in enumerate(tracks): if not os.path.exists(trackPath) or not check_path(trackPath): errorPos.append({"index" : index}) errorPos[-1].update(send_error(error_codes.WRONG_PATH_SPECIFIED, "File doesn't exsist.", False)) continue if not is_valid_file(trackPath): errorPos.append({"index" : index}) errorPos[-1].update(send_error(error_codes.INVALID_TYPE, "Invalid filetype.", False)) continue if len(errorPos) > 0: return send_playlist_play_error(errorPos, "Invalid track array") flushTrack() currentPlaylist = data.get('playlist') playlistThreader.startThread() return send_state_playlist_message(currentPlaylist, "Playlist succesfully started", None, 1, False)
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 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 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 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 startTrack(trackPath): #trackThreader.registerOnEndCustomCallback(track_endevent) if(trackPath == "" or trackPath == None): return send_error(error_codes.NO_PATH_DEFINED, "No path parameter passed.") if not os.path.exists(trackPath) or not check_path(trackPath): return send_error(error_codes.WRONG_PATH_SPECIFIED, "File doesn't exsist.") if not is_valid_file(trackPath): return send_error(error_codes.INVALID_TYPE, "Invalid filetype.") flushPlaylist() data = trackThreader.getThread(trackPath) currentThread = data.get('thread') currentTrack = data.get('track') currentThread.start() return send_state_track_message(currentTrack, "Track started")
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")
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)
''' Configurations. ''' import helpers LEARNING_RATE = 5e-3 NUM_EPOCHS = 501 BATCH_SIZE = 128 LAMBDA_ = 0.5 M_PLUS = 0.9 M_MINUS = 0.1 DECAY_STEP = 20 DECAY_GAMMA = 0.95 CHECKPOINT_FOLDER = './saved_model/' CHECKPOINT_NAME = 'deepcaps.pth' DATASET_FOLDER = './dataset_folder/' GRAPHS_FOLDER = './graphs/' DEVICE = helpers.get_device() helpers.check_path(CHECKPOINT_FOLDER) helpers.check_path(DATASET_FOLDER) helpers.check_path(GRAPHS_FOLDER)
if __name__ == "__main__": # if not make_checks(): # exit() dump_name, json = parse_args() for environment, values in json.items(): username = values[0]['username'] backup_dir = values[0]['system_path'] + 'backups/' databases = values[0]['databases'] try: if not run_command('id %s' % username): raise Exception check_path(backup_dir) run_command('/bin/chown postgres:postgres %s' % backup_dir) except: continue try: if isinstance(databases, unicode) and databases == 'all': databases = run_command( "su - postgres -c \"psql -lt\" | grep %s | awk '{print $1}'" % (username) ).split() if isinstance(databases, list): for database in databases: do_backup(username, database, backup_dir, dump_name) except: print 'error'
def path_check(): """Check path to see if logging is allowed""" return helpers.check_path(LOGGING_PATH, LOG_FILENAME)