def load_kals_from_env(SETTINGS, cur): kaltura_count = int(os.environ.get("KALTURA_INSTANCES", "1")) if kaltura_count >= 1: for counter in rangegen(1, kaltura_count + 1): accessors = ['k_%d_%s' % (counter, kal_prop) for kal_prop in kaltura_properties_list] # Because the Global Dictionary will be populated with this guy config_id = 'k_%d_%s' % (counter, 'KALTURA_CONFIG_ID') temp_kaltura_config_map = {} for (accessor_term, accessor_accessor) in \ zip(kaltura_properties_list, accessors): temp_kaltura_config_map[accessor_term] = os.environ.get( accessor_accessor, kaltura_defaults_dictionary.get(accessor_term) ) # temp_kaltura_config_map['SERVICE_URL'] = "Donkey" temp_kaltura_config_map['SERVICE_URL'] = \ "http://" + temp_kaltura_config_map.get( 'KALTURA_PATH', DEFAULT_KALTURA_PATH ) SETTINGS[config_id.split("_")[1]] = temp_kaltura_config_map values = [config_id.split("_")[1]] + \ [temp_kaltura_config_map.get(kaltura_properties_list[j]) for j in rangegen(1, len(kaltura_properties_list))] cur.execute( "insert into configurations values(?,?,?,?,?,?,?,?,?,?)", values) else: raise Exception( "Kaltura Count Must be Positive, got %d" % kaltura_count ) return SETTINGS
def load_kals_from_env(SETTINGS, cur): kaltura_count = int(os.environ.get("KALTURA_INSTANCES", "1")) if kaltura_count >= 1: for counter in rangegen(1, kaltura_count + 1): accessors = [ 'k_%d_%s' % (counter, kal_prop) for kal_prop in kaltura_properties_list ] # Because the Global Dictionary will be populated with this guy config_id = 'k_%d_%s' % (counter, 'KALTURA_CONFIG_ID') temp_kaltura_config_map = {} for (accessor_term, accessor_accessor) in \ zip(kaltura_properties_list, accessors): temp_kaltura_config_map[accessor_term] = os.environ.get( accessor_accessor, kaltura_defaults_dictionary.get(accessor_term)) # temp_kaltura_config_map['SERVICE_URL'] = "Donkey" temp_kaltura_config_map['SERVICE_URL'] = \ "http://" + temp_kaltura_config_map.get( 'KALTURA_PATH', DEFAULT_KALTURA_PATH ) SETTINGS[config_id.split("_")[1]] = temp_kaltura_config_map values = [config_id.split("_")[1]] + \ [temp_kaltura_config_map.get(kaltura_properties_list[j]) for j in rangegen(1, len(kaltura_properties_list))] cur.execute( "insert into configurations values(?,?,?,?,?,?,?,?,?,?)", values) else: raise Exception("Kaltura Count Must be Positive, got %d" % kaltura_count) return SETTINGS
def addArrayIfDefined(self, key, array): if array == NotImplemented: return if array == None: self.put(key) return if len(array) == 0: self.put('%s:-' % key, '') else: for curIndex in rangegen(len(array)): self.addObjectIfDefined('%s:%s' % (key, curIndex), array[curIndex])
def write_to_worksheet(worksheet, data, order, startindex=0, skip_vals={}): if not order is None: if startindex == 0: for i in rangegen(len(order)): worksheet.write(0, i, order[i]) moonwalk = 0 for i in rangegen(len(data)): gandalf = 0 for key in skip_vals: for val in skip_vals[key]: if val in data[i][key]: gandalf = 1 if gandalf: moonwalk += 1 continue # thou shalt not pass for j in rangegen(len(order)): current_col = order[j] current_val = data[i].get(current_col, 'None') worksheet.write(i - moonwalk + 1 + startindex, j, current_val) return {"added": len(data) - moonwalk, "skipped": moonwalk} else: raise Exception('order should not be None, is unimplemented yet.')
def submit_add_config(): values = [request.args.get(properties.kaltura_properties_list[j]) for \ j in utils.rangegen(1, len(properties.kaltura_properties_list))] resp = simplejson.loads(properties.add_kaltura(values)) if resp.get('success', False) == True: message = 'Added' else: message = 'Failed to add' # return render_template('message.html', # message=message, # link=url_for('kts_index'), # linktext='-Home-') return redirect(url_for('view_configs'))
def write_to_worksheet(worksheet, data, order, startindex=0, skip_vals = {}): if not order is None: if startindex == 0: for i in rangegen(len(order)): worksheet.write(0, i, order[i]) moonwalk = 0 for i in rangegen(len(data)): gandalf = 0 for key in skip_vals: for val in skip_vals[key]: if val in data[i][key]: gandalf = 1 if gandalf: moonwalk += 1 continue # thou shalt not pass for j in rangegen(len(order)): current_col = order[j] current_val = data[i].get(current_col, 'None') worksheet.write(i - moonwalk + 1 + startindex, j, current_val ) return {"added": len(data) - moonwalk, "skipped": moonwalk} else: raise Exception('order should not be None, is unimplemented yet.')
def load_kaltura_settings(SETTINGS=None): lockfile = open('kts-config.lock', 'w') fcntl.lockf(lockfile, fcntl.LOCK_EX) if SETTINGS is None: SETTINGS = {} kaldefsdb = sqlite3.connect(kaldefsfile) cur = kaldefsdb.cursor() cur.execute("select count(*) from sqlite_master " "where type='table' and name='configurations'") existence = cur.fetchall()[0][0] if existence == 1: cur.execute("""select KALTURA_CONFIG_ID, KALTURA_NAME, KALTURA_PATH, PARTNER_ID, PLAYER_ID, THUMBNAIL_PLAYER_ID, ADMIN_SECRET, SECRET, USER_NAME, MOBILE_PLAYER_FLAVOR from configurations""") for row in cur: kal_id = str(row[0]) SETTINGS[kal_id] = { kaltura_properties_list[i]: str(row[i]) for i in rangegen(1, len(row)) } # a.k.a dict( zip( kaltura_properties_list[1:], row[1:] ) ) SETTINGS[kal_id][ 'SERVICE_URL'] = "http://" + SETTINGS[kal_id]['KALTURA_PATH'] elif existence == 0: cur.execute(config_table_creation_query) SETTINGS = load_kals_from_env(SETTINGS, cur) kaldefsdb.commit() cur.close() kaldefsdb.close() lockfile.close() return SETTINGS
def load_kaltura_settings(SETTINGS=None): lockfile = open('kts-config.lock', 'w') fcntl.lockf(lockfile, fcntl.LOCK_EX) if SETTINGS is None: SETTINGS = {} kaldefsdb = sqlite3.connect(kaldefsfile) cur = kaldefsdb.cursor() cur.execute( "select count(*) from sqlite_master " "where type='table' and name='configurations'") existence = cur.fetchall()[0][0] if existence == 1: cur.execute("""select KALTURA_CONFIG_ID, KALTURA_NAME, KALTURA_PATH, PARTNER_ID, PLAYER_ID, THUMBNAIL_PLAYER_ID, ADMIN_SECRET, SECRET, USER_NAME, MOBILE_PLAYER_FLAVOR from configurations""") for row in cur: kal_id = str(row[0]) SETTINGS[kal_id] = {kaltura_properties_list[i]: str(row[i]) for i in rangegen(1, len(row))} # a.k.a dict( zip( kaltura_properties_list[1:], row[1:] ) ) SETTINGS[kal_id]['SERVICE_URL'] = "http://" + SETTINGS[kal_id][ 'KALTURA_PATH'] elif existence == 0: cur.execute(config_table_creation_query) SETTINGS = load_kals_from_env(SETTINGS, cur) kaldefsdb.commit() cur.close() kaldefsdb.close() lockfile.close() return SETTINGS
def get_excel(): kaltura_id, entry_id = parse_ids() fields = request.args.get('fields', None) if fields: fields = [item.lower() for item in fields.split(',') if item.lower() in myKalturaObject.DEFAULT_SEARCH_FIELD_LIST] else: fields = myKalturaObject.DEFAULT_SEARCH_FIELD_LIST filename = request.args.get('filename', None) # if i don't set pagesize, kaltura uses 30 as default. # max is 500 btw. pagesize = int(request.args.get('pagesize', 500)) types = request.args.get('types', 'video,audio').split(',') skip_types = [each for each in ['video', 'audio', 'image'] if each not in types] skip_vals = {'media_type': [each.upper() for each in skip_types]} if not filename: # raise Exception('filename is required') settings = properties.load_kaltura_settings().get(kaltura_id) filename = str(kaltura_id) + settings['KALTURA_NAME'] filename = secure_filename(filename) client = kaltura_session_loader(kaltura_id) totaling_success, total = myKalturaObject.count(client) workbook, filepath = create_workbook(filename) worksheet = get_new_worksheet(workbook) i = total / pagesize + (1 if total % pagesize else 0) skipped = 0 for num in utils.rangegen(i): data = myKalturaObject.searchVideos( client, kaltura_id, True, int(pagesize), num + 1) write_result = write_to_worksheet(worksheet, data, fields, int(pagesize) * num - skipped, skip_vals) skipped += write_result['skipped'] close_workbook(workbook) return send_file(filepath, as_attachment=True, attachment_filename=os.path.basename(filepath))