Difference between revisions of "User:Kernigh/wikify.py"
Jump to navigation
Jump to search
(Fix oldwarning.) |
(version 20120605) |
||
Line 1: | Line 1: | ||
Forked from [[User:Jayt#Source wikification script]]. | Forked from [[User:Jayt#Source wikification script]]. | ||
+ | __TOC__ | ||
− | < | + | == Script == |
+ | <syntaxhighlight lang="python"> | ||
#!/usr/bin/python | #!/usr/bin/python | ||
− | #version | + | #version 20120605 |
# usage: ./wikify.py sourcefile.c ... | # usage: ./wikify.py sourcefile.c ... | ||
# the first line of output will be the article title, for use with | # the first line of output will be the article title, for use with | ||
Line 10: | Line 12: | ||
outputdir="out" # where to put the wikified file | outputdir="out" # where to put the wikified file | ||
gamename = "SLASH'EM" # NetHack or Hack or SLASH'EM | gamename = "SLASH'EM" # NetHack or Hack or SLASH'EM | ||
− | uploadversion = "0.0. | + | uploadversion = "0.0.7E7F3" # 1.3d/2.3e/3.1.0/3.4.3/etc. |
− | latestversion = "0.0. | + | latestversion = "0.0.7E7F3" # 3.4.3 or 0.0.7E7F3 |
license = "NGPL" # NGPL or CWI | license = "NGPL" # NGPL or CWI | ||
## | ## | ||
Line 22: | Line 24: | ||
f = open(srcpath) | f = open(srcpath) | ||
g = open(path.join(outputdir, srcfile), "w") | g = open(path.join(outputdir, srcfile), "w") | ||
− | |||
if gamename == "NetHack" and uploadversion == latestversion: | if gamename == "NetHack" and uploadversion == latestversion: | ||
wikilink = 'Source:' + srcfile | wikilink = 'Source:' + srcfile | ||
srccodelink = '[[source code]]' | srccodelink = '[[source code]]' | ||
− | linelink = '{{ | + | linelink = '{{tl|sourcecode|2=' + srcfile + '{{!}}123}}' |
catlink = "[[Category:Source code]]" | catlink = "[[Category:Source code]]" | ||
else: | else: | ||
− | wikilink = 'Source:' + gamename + ' ' + uploadversion + '/' + srcfile | + | wikilink = ('Source:' + gamename + ' ' + uploadversion + |
+ | '/' + srcfile) | ||
srccodelink = ('[[' + gamename + ' ' + uploadversion + | srccodelink = ('[[' + gamename + ' ' + uploadversion + | ||
' source code|source code]]') | ' source code|source code]]') | ||
− | linelink = ('{{sourcecode|' + srcfile + ' | + | linelink = ('{{tl|sourcecode|2=' + srcfile + |
+ | '{{!}}123{{!}}version=' + | ||
gamename + ' ' + uploadversion + '}}') | gamename + ' ' + uploadversion + '}}') | ||
catlink = ("[[Category:" + gamename + ' ' + uploadversion + | catlink = ("[[Category:" + gamename + ' ' + uploadversion + | ||
Line 71: | Line 74: | ||
g.writelines([catlink, '\n']) | g.writelines([catlink, '\n']) | ||
− | </ | + | </syntaxhighlight> |
− | Changelog | + | == Changelog == |
+ | * Use {{tl|tl}} to show {{tl|sourcecode}}. --[[User:Kernigh|Kernigh]] ([[User talk:Kernigh|talk]]) 16:24, 5 June 2012 (UTC) | ||
* Use 'Source:' namespace and {{tl|sourcecode}}. Add <nowiki>__MIXEDSYNTAXHIGHLIGHT__</nowiki> to output. Handle multiple source files in one run. Make minor improvements. --[[User:Kernigh|Kernigh]] ([[User talk:Kernigh|talk]]) 01:20, 30 May 2012 (UTC) | * Use 'Source:' namespace and {{tl|sourcecode}}. Add <nowiki>__MIXEDSYNTAXHIGHLIGHT__</nowiki> to output. Handle multiple source files in one run. Make minor improvements. --[[User:Kernigh|Kernigh]] ([[User talk:Kernigh|talk]]) 01:20, 30 May 2012 (UTC) |
Latest revision as of 16:24, 5 June 2012
Forked from User:Jayt#Source wikification script.
Contents
Script
#!/usr/bin/python
#version 20120605
# usage: ./wikify.py sourcefile.c ...
# the first line of output will be the article title, for use with
# an uploadbot
#config:
outputdir="out" # where to put the wikified file
gamename = "SLASH'EM" # NetHack or Hack or SLASH'EM
uploadversion = "0.0.7E7F3" # 1.3d/2.3e/3.1.0/3.4.3/etc.
latestversion = "0.0.7E7F3" # 3.4.3 or 0.0.7E7F3
license = "NGPL" # NGPL or CWI
##
import sys, re
from os import path
for srcpath in sys.argv[1:]:
srcfile = path.basename(srcpath)
f = open(srcpath)
g = open(path.join(outputdir, srcfile), "w")
if gamename == "NetHack" and uploadversion == latestversion:
wikilink = 'Source:' + srcfile
srccodelink = '[[source code]]'
linelink = '{{tl|sourcecode|2=' + srcfile + '{{!}}123}}'
catlink = "[[Category:Source code]]"
else:
wikilink = ('Source:' + gamename + ' ' + uploadversion +
'/' + srcfile)
srccodelink = ('[[' + gamename + ' ' + uploadversion +
' source code|source code]]')
linelink = ('{{tl|sourcecode|2=' + srcfile +
'{{!}}123{{!}}version=' +
gamename + ' ' + uploadversion + '}}')
catlink = ("[[Category:" + gamename + ' ' + uploadversion +
' ' + "source code|" + srcfile + "]]")
if uploadversion == latestversion:
oldwarning = ''
else:
oldwarning = ("'''Warning!''' This is the source code from an "
"old release. For the latest release, see [[" +
gamename + " source code]].\n\n")
if gamename == "Hack" or gamename == "NetHack":
slashwarning = ''
else:
slashwarning = ("The latest source code for vanilla NetHack "
"is at [[Source code]].\n\n")
g.writelines([wikilink, '\n',
"__MIXEDSYNTAXHIGHLIGHT__\n",
"Below is the full text to '''", srcfile,
"''' from the ", srccodelink, " of [[",
gamename, ' ', uploadversion,
"]]. To link to a particular line, write ", linelink,
", for example.\n\n",
oldwarning, slashwarning,
"{{" + license + "}}\n"])
i = 1
for line in f.readlines():
wikiline = (str(i) + '.').ljust(6) + line.rstrip("\n")
if re.search("{{",line):
wikiline = '<nowiki>'+wikiline+'</nowiki>'
g.writelines([' <span id="line', str(i), '">',
wikiline, '</span>\n'])
i += 1
g.writelines([catlink, '\n'])
Changelog
- Use {{tl}} to show {{sourcecode}}. --Kernigh (talk) 16:24, 5 June 2012 (UTC)
- Use 'Source:' namespace and {{sourcecode}}. Add __MIXEDSYNTAXHIGHLIGHT__ to output. Handle multiple source files in one run. Make minor improvements. --Kernigh (talk) 01:20, 30 May 2012 (UTC)