User:David/Imported Cvars

From Tremulous Wiki
Jump to: navigation, search

Introduction

In order to ease getting all the cvars here, I made a perl script to make a MediaWiki importable XML file. This page is here so if it ever needs to be done again, it can be done quickly and easily.

Steps

  • Get a list of cvars.
    • Run trem, and do /cvarlist. Copy said list to a file.
    • I hacked my copy of trem to show the default value instead of the current.
    • I also changed the default value to "See Text" for ones where the default contained my username or whatever.
    • Should have ~450 lines in the format 'SURIALC cvar_name "default value"'
    • Binning blank lines etc won't hurt.
  • Run script.
    • See below for the script.
    • You can change the number of items per page on line 9. Defaults to 95 per file.
      • It timed out at ~125 imported.
    • Makes files called cvars-#.xml
    • It wants that cvar list you made before on stdin.
  • Check it!.
    • This is very important, don't blame me if it goes bang.
    • Each file should start with <mediawiki>
    • Each file should end with </mediawiki>
  • Import!
    • I got paradox to do it. Any SysOp should be able to. No idea how or where.

The script

#!/usr/bin/perl -W
use strict;

my $count = 0;

sub pageno
{
	my ($pageno) = @_;
	return (int(($pageno)/95+1));
}

while(my $line = <STDIN>)
{
	if ($line =~ /^(.)(.)(.)(.)(.)(.)(.) ([^ ]+) "([^"]*)"$/)
	{
		# SURIALC
		# S=serverinfo
		# U=userinfo
		# R=readonly
		# I=initilisation only or something.
		# A=archive
		# L=latched
		# C=cheat
		
		$count++;
		if (pageno($count) != pageno($count-1) or $count == 1)
		{
			open (FILE, ">", "cvars-" . pageno($count) . ".xml" );
			print FILE "<mediawiki xml:lang=\"en\">\n";
		}
		else
		{
			open (FILE, ">>", "cvars-" . pageno($count) . ".xml" );
		}
		print FILE "  <page>\n";
		print FILE "    <title>$8</title>\n";
		print FILE "    <revision>\n";
		print FILE "      <timestamp>" . `echo -n \$(date '+%Y-%m-%dT%H:%M:%SZ')` . "</timestamp>\n";
		print FILE "      <contributor><username>David</username></contributor>\n";
		print FILE "      <comment>AUTO IMPORTED BY SCRIPT!  User:David/Imported_Cvars for more info.</comment>\n";
		print FILE "      <text>{{DISPLAYTITLE:$8}}\n";	
		print FILE "{{stub}}\n";
		print FILE "{{Infobox Cvar\n";
		print FILE "|title      = $8\n";
		print FILE "|default    = " . ($9 eq "" ? "None" : $9) . "\n";
		print FILE "|range      = \n";
		print FILE "|client     = \n";
		print FILE "|server     = \n";
		print FILE "|latched    = " . ($6 eq "L" ? "Yes" : "") . "\n";
		print FILE "|readonly   = " . ($3 eq "R" ? "Yes" : "") . "\n";
		print FILE "|cheat      = " . ($7 eq "C" ? "Yes" : "") . "\n";
		print FILE "|serverinfo = " . ($1 eq "S" ? "Yes" : "") . "\n";
		print FILE "|userinfo   = " . ($2 eq "U" ? "Yes" : "") . "\n";
		print FILE "}}\n";
		print FILE "== Usage ==\n";
		print FILE "\n";
		print FILE "[[Category:Unsorted Cvars]]</text>\n";
		print FILE "    </revision>\n";
		print FILE "  </page>\n";
		
		if (pageno($count) != pageno($count+1))
		{
			print FILE "</mediawiki>\n";
		}
		
		close (FILE);
	}
	else
	{
		print STDERR "Unable to parse line: " . $line;
	}
}

open (FILE, ">>", "cvars-" . pageno($count) . ".xml" );
print FILE "</mediawiki>\n";
close (FILE);
Tremulous
Personal tools