コード例 #1
0
ファイル: steam.py プロジェクト: mdevaev/slib
def sourceServerStatus(host_name, port) :
	host_name = ulib.validators.network.validRfcHost(host_name)
	port = ulib.validators.network.validPort(port)

	server = SourceLib.SourceQuery.SourceQuery(host_name, port)

	count = 1
	players_list = []
	for player_dict in server.player() :
		players_list.append([
				str(count),
				{ "nowrap" : None, "body" : player_dict["name"] },
				ulib.tools.fmt.formatTimeDelta(player_dict["time"]),
				str(player_dict["kills"])
			])
		count += 1
	players_table = html.tableWithHeader(["N", "Name", "Time", "Score"], players_list)

	info_dict = server.info()
	status_table = html.statusTable([
			("Server", info_dict["hostname"]),
			("Description", info_dict["gamedesc"]),
			("Game", info_dict["gamedir"]),
			("Map", info_dict["map"]),
			("Players", "%d / %d" % (info_dict["numplayers"], info_dict["maxplayers"])),
			("Password", ( "Yes" if info_dict["passworded"] else "No" )),
			("Secure", ( "Yes" if info_dict["secure"] else "No" )),
			("Version", info_dict["version"])
		])

	# XXX: https://developer.valvesoftware.com/wiki/Steam_browser_protocol
	join_button = html.buttonLink("JOIN", "steam://connect/%s:%d" % (host_name, port), ("big_button",))

	return (players_table, status_table, join_button)
コード例 #2
0
ファイル: kf.py プロジェクト: mdevaev/slib
def playerRatingTable(stat_dict, user_id, profile_url) :
	(sorted_list, index) = sortedPlayers(stat_dict, ( lambda arg : -arg[1]["KillsStat"] ), user_id)
	assert index != -1
	players_list = []
	wrap_special = ( lambda text, count : "<font class=\"special\">%s</font>" % (str(text)) if count == index else str(text) )
	for (count, user_id, player_stat_dict) in sorted_list[max(index-2, 0):index+3] :
		player_name = "<a href=\"%s\">&raquo;</a>&nbsp;%s" % (profile_url % { "user_id" : user_id }, player_stat_dict["PlayerName"])
		players_list.append([
				wrap_special(count + 1, count),
				{ "nowrap" : None, "body" : wrap_special(player_name, count) },
				wrap_special(player_stat_dict["KillsStat"], count),
			])
		count += 1
	return html.tableWithHeader(["N", "Name", "Kills"], players_list)
コード例 #3
0
ファイル: kf.py プロジェクト: mdevaev/slib
def serverLeaderboardTable(stat_dict, profile_url, limit = 5) :
	count = 1
	leaderboard_list = []
	for (user_id, player_stat_dict) in sorted(stat_dict.items(), key=( lambda arg : -arg[1]["KillsStat"] )) :
		player_name = "<a href=\"%s\">&raquo;</a>&nbsp;%s" % (profile_url % { "user_id" : user_id }, player_stat_dict["PlayerName"])
		leaderboard_list.append([
				str(count),
				{ "nowrap" : None, "body" : player_name },
				str(player_stat_dict["KillsStat"]),
				ulib.tools.fmt.formatTimeDelta(player_stat_dict["TotalPlayTime"])
			])
		if count == limit :
			break
		count += 1
	return html.tableWithHeader(["N", "Name", "Kills", "Time"], leaderboard_list)
コード例 #4
0
ファイル: system.py プロジェクト: mdevaev/slib
def disksFree(dirs_list) :
	format_size = ( lambda arg : "%s <span class=\"back\">%s</span>" % (tuple(ulib.tools.fmt.formatSize(arg).split(" "))) )
	dirs_list = map(ulib.validators.fs.validAccessiblePath, ulib.validators.common.validStringList(dirs_list))
	rows_list = []
	for path in dirs_list :
		label = ( os.path.basename(path) or path )
		(full, used) = ulib.tools.unix.diskFree(path)
		percent = 100 * used / full
		rows_list.append([
				{ "nowrap" : None, "body" : label },
				{ "style" : "width: 70%", "body" : html.progressBar(percent) },
				{ "nowrap" : None, "body" : format_size(full) },
				{ "nowrap" : None, "body" : format_size(used) },
				{ "nowrap" : None, "body" : format_size(full - used) },
			])
	df_table = html.tableWithHeader(["Label", "", "Size", "Used", "Free"], rows_list)
	return (df_table,)
コード例 #5
0
ファイル: torrents.py プロジェクト: mdevaev/slib
def torrentsList(torrents_dir_path, link_prefix) :
	torrents_dir_path = ulib.validators.fs.validAccessiblePath(torrents_dir_path)
	link_prefix = os.path.normpath(link_prefix)

	size = 0
	rows_list = []
	for (torrent_file_name, torrent) in sorted(rtlib.tfile.torrents(torrents_dir_path).items(), key=operator.itemgetter(0)) :
		torrent_size = torrent.size()
		size += torrent_size
		rows_list.append([
				str(len(rows_list) + 1),
				"<a href=\"%s\">%s</a>" % (os.path.join(link_prefix, torrent_file_name), torrent_file_name),
				ulib.tools.fmt.formatSize(torrent_size),
				html.maybeLink(torrent.comment() or ""),
			])
	torrents_table = html.tableWithHeader(["N", "Name", "Size", "Comment"], rows_list)

	return (torrents_table, str(len(rows_list)), ulib.tools.fmt.formatSize(size))
コード例 #6
0
ファイル: kf.py プロジェクト: mdevaev/slib
def playerPerksTable(stat_dict, user_id) :
	perks_list = []
	for (perk, levels_map) in (
			("Berserk", BERSERK_LEVELS_MAP),
			("Sharpshooter", SHARPSHOOTER_LEVELS_MAP),
			("Firebug", FIREBUG_LEVELS_MAP),
			("Field medic", FIELD_MEDIC_LEVELS_MAP),
			("Demolitions", DEMOLITIONS_LEVELS_MAP),
			("Support spec", SUPPORT_SPEC_LEVELS_MAP),
			("Commando", COMMANDO_LEVELS_MAP) ) :
		(level, percent) = calculateLevelProgress(levels_map, stat_dict[user_id])
		max_percent = calculateProgress(levels_map, stat_dict[user_id])
		perks_list.append([
				perk,
				str(level),
				{ "width" : "150px", "body" : html.progressBar(percent) },
				{ "width" : "150px", "body" : html.progressBar(max_percent) },
			])
	return html.tableWithHeader(["Perk", "Level", "Until the next", "Until the max"], perks_list)
コード例 #7
0
ファイル: kf.py プロジェクト: mdevaev/slib
def serverPerksTable(stat_dict, profile_url) :
	count = 1
	players_list = []
	for (user_id, player_stat_dict) in sorted(stat_dict.items(), key=( lambda arg : arg[1]["PlayerName"].lower() )) :
		perk_progress = ( lambda levels_map : { "width" : "13%", "body" : html.progressBar(calculateProgress(levels_map, player_stat_dict)) } )
		player_name = "<a href=\"%s\">&raquo;</a>&nbsp;%s" % (profile_url % { "user_id" : user_id }, player_stat_dict["PlayerName"])
		players_list.append([
				str(count),
				{ "nowrap" : None, "body" : player_name },
				perk_progress(BERSERK_LEVELS_MAP),
				perk_progress(SHARPSHOOTER_LEVELS_MAP),
				perk_progress(FIREBUG_LEVELS_MAP),
				perk_progress(FIELD_MEDIC_LEVELS_MAP),
				perk_progress(DEMOLITIONS_LEVELS_MAP),
				perk_progress(SUPPORT_SPEC_LEVELS_MAP),
				perk_progress(COMMANDO_LEVELS_MAP),
			])
		count += 1
	players_header_list = ["N", "Name", "Berserk", "Sharpshooter", "Firebug", "FieldMedic", "Demolitions", "SupportSpec", "Commando"]
	return html.tableWithHeader(players_header_list, players_list)
コード例 #8
0
ファイル: mlocate.py プロジェクト: mdevaev/slib
def mlocateSearch(query, remove_prefix, locate_bin_path, db_file_path) :
	query = ulib.tools.coding.fromUtf8(query)
	query = re.sub(VALID_SYMBOLS, "", query, flags=re.UNICODE).lower()
	query_list = filter(None, re.split(DELIMITERS, query))
	query = ulib.tools.coding.utf8(query)

	remove_prefix = os.path.normpath(remove_prefix) # XXX: Not validate!
	locate_bin_path = ulib.validators.fs.validAccessiblePath(locate_bin_path)
	db_file_path = ulib.validators.fs.validAccessiblePath(db_file_path)

	before_run = time.time()
	search_time = ( lambda : "Search time: %.2f seconds" % (time.time() - before_run) )

	if len(query_list) == 0 :
		return ("Empty query string", search_time(), query)

	(proc_stdout, _, proc_retcode) = tools.process.execProcess([
			locate_bin_path,
			"--database", db_file_path,
			"--all", "--ignore-case",
			"--null", "--quiet",
		] + query_list, fatal_flag=False)

	if proc_retcode != 0 :
		return ("Nothing found", search_time(), query)

	results_list = mapResults(query_list, proc_stdout.strip().split("\0"))

	if len(results_list) == 0 :
		return ("Nothing found", search_time(), query)

	rows_list = []
	for (count, (row, weight)) in enumerate(results_list) :
		row = re.sub("^%s" % (remove_prefix), "", row)
		row = "<a href=\"%s\">%s</a>" % (row, row)
		rows_list.append((str(count + 1), row, "%.2f" % (weight)))
	results = html.tableWithHeader(("N", "Path", "Weight"), rows_list)

	return (results, search_time(), query)