|
From: <cn...@us...> - 2020-04-27 01:26:28
|
Revision: 1028
http://sourceforge.net/p/seq/svn/1028
Author: cn187
Date: 2020-04-27 01:26:27 +0000 (Mon, 27 Apr 2020)
Log Message:
-----------
Add update_zoneopcodes.py script and sample opcode file
Added Paths:
-----------
showeq/trunk/scripts/
showeq/trunk/scripts/opcodes.txt.sample
showeq/trunk/scripts/update_zoneopcodes.py
Added: showeq/trunk/scripts/opcodes.txt.sample
===================================================================
--- showeq/trunk/scripts/opcodes.txt.sample (rev 0)
+++ showeq/trunk/scripts/opcodes.txt.sample 2020-04-27 01:26:27 UTC (rev 1028)
@@ -0,0 +1,44 @@
+
+# Opcodes from 2020-04-15 patch (Live)
+
+13cd OP_AAExpUpdate
+3139 OP_Action
+0022 OP_Action2
+62fd OP_ClickObject
+7753 OP_ClientUpdate
+1692 OP_CommonMessage
+03da OP_Consider
+71c1 OP_Death
+7718 OP_DeleteSpawn
+2713 OP_EndUpdate
+329d OP_ExpandedGuildInfo
+129b OP_ExpUpdate
+69db OP_Find
+456d OP_FormattedMessage
+2bc1 OP_GroundSpawn
+2366 OP_GuildMemberList
+4074 OP_GuildMemberUpdate
+699f OP_GuildMOTD
+305d OP_HPUpdate
+3aa3 OP_LevelUpdate
+5e20 OP_ManaChange
+0865 OP_ManaUpdate
+4fcc OP_MemorizeSpell
+445f OP_MobUpdate
+4df8 OP_NewZone
+0055 OP_NpcMoveUpdate
+64e7 OP_PlayerProfile
+4209 OP_RemoveSpawn
+316b OP_SendZonePoints
+03d8 OP_SimpleMessage
+2e1f OP_SkillUpdate
+202d OP_SpawnAppearance
+6d33 OP_SpawnDoor
+6bd4 OP_SpawnRename
+1d19 OP_SpecialMesg
+67b6 OP_SwapSpell
+3333 OP_TargetMouse
+67e2 OP_TimeOfDay
+29ed OP_WearChange
+0c40 OP_ZoneChange
+0b23 OP_ZoneEntry
Added: showeq/trunk/scripts/update_zoneopcodes.py
===================================================================
--- showeq/trunk/scripts/update_zoneopcodes.py (rev 0)
+++ showeq/trunk/scripts/update_zoneopcodes.py 2020-04-27 01:26:27 UTC (rev 1028)
@@ -0,0 +1,177 @@
+#!/usr/bin/env python3
+
+# update_zoneopcodes.py
+# Copyright 2020, cn187 <cn...@us...>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+'''
+This module updates the zoneopcode.xml file from a plain list of opcode/opname
+pairs. It's a simple find/replace, rather than a full XML parse, so each
+opening opcode tag, with attributes, may not span more than one line.
+
+It can be run from the command line, using either files or stdin/stdout
+for input and output.
+
+
+usage: update_zoneopcodes.py [-h] [-i INPUT] [-o OUTPUT] opcode_file
+
+Update zoneopcodes.xml from plain list of opcodes/names using a simple
+find/replace.
+
+positional arguments:
+ opcode_file The file containing the list of opcode/opname pairs
+
+optional arguments:
+ -h, --help show this help message and exit
+ -i INPUT, --input INPUT
+ Filename/path of zoneopcodes.xml to read. If none
+ provided, defaults to reading from stdin
+ -o OUTPUT, --output OUTPUT
+ Filename/path of zoneopcodes.xml file to write. If
+ none provided, defaults to writing to stdout
+
+
+Sample usage:
+
+update_zoneopcodes.py opcodes.txt -i conf/zoneopcodes.xml -o conf/zoneopcodes.new
+
+or
+
+update_zoneopcodes.py opcodes.txt <conf/zoneopcodes.xml >conf/zoneopcodes.new
+
+
+The format of the opcodes.txt file is simple opcode/opname pairs, one per line:
+
+ # Comments are allowed if prefixed with #
+ ffff OP_Foo
+ eeee OP_Bar
+
+'''
+
+
+import re
+from datetime import datetime, date
+import sys
+import argparse
+
+
+def update_zoneopcodes_filter(opcodes, infile, outfile):
+
+ line_re = re.compile(r'{}{}{}{}'.format(
+ '[ \t]*<opcode[ \t]+',
+ 'id="([A-Fa-f0-9]{4})"[ \t]+',
+ 'name="([A-Za-z0-9_]+)"[ \t]+',
+ 'updated="([01][0-9]/[0-3][0-9]/[0-9][0-9])"[ \t]*>[ \t]*\n'))
+
+
+ new_date = datetime.now().strftime("%m/%d/%y")
+ #new_date = date(2020, 4, 15).strftime("%m/%d/%y") # For testing purposes
+
+ updated = 0
+
+ for line in infile.readlines():
+
+ match = line_re.fullmatch(line)
+ if not match:
+ outfile.write(line)
+ continue
+
+ opcode = match.group(1)
+ opname = match.group(2)
+ update = match.group(3)
+
+ if opname not in opcodes:
+ outfile.write(line)
+ continue
+
+ opcode_start = match.start(1)
+ opcode_end = match.end(1)
+
+ opname_start = match.start(2)
+ opname_end = match.end(2)
+
+ date_start = match.start(3)
+ date_end = match.end(3)
+
+ new_line = line[:opcode_start] + opcodes[opname]
+ new_line += line[opcode_end:date_start] + new_date + line[date_end:]
+
+ outfile.write(new_line)
+
+ updated += 1
+
+ return (updated, len(opcodes))
+
+
+def update_zoneopcodes_file(opcodes, xmlin, xmlout):
+ with open(xmlin, 'r') as infile:
+ with open(xmlout, 'w+') as outfile:
+ update_zoneopcodes_filter(opcodes, infile, outfile)
+
+def parse_opcode_file(opcode_file):
+
+ with open(opcode_file, 'r') as opf:
+ opcodes = {}
+ for line in opf.readlines():
+ # handle comments
+ line = line[:line.find('#')] + "\n"
+ parts = line.split()
+ if parts:
+ o, n = parts
+ opcodes[n] = o
+
+ return opcodes
+
+
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Update zoneopcodes.xml from plain list of opcodes/names \
+ using a simple find/replace.',
+ epilog='NOTE: Since this does not fully parse the XML, the opening \
+ tag for each opcode (including the "id", "name", and "updated" \
+ attributes) must not span more than one line.')
+
+
+ parser.add_argument('opcode_file', help='The file containing the list \
+ of opcode/opname pairs')
+ parser.add_argument('-i', '--input', type=str,
+ help='Filename/path of zoneopcodes.xml to read. If \
+ none provided, defaults to reading from stdin')
+ parser.add_argument('-o', '--output', type=str,
+ help='Filename/path of zoneopcodes.xml file to write. \
+ If none provided, defaults to writing to stdout')
+
+ args = parser.parse_args()
+
+ if args.input:
+ infile = open(args.input, 'r')
+ else:
+ infile = sys.stdin
+
+ if args.output:
+ outfile = open(args.output, 'w+')
+ else:
+ outfile = sys.stdout
+
+
+ opcodes = parse_opcode_file(args.opcode_file)
+
+ update_zoneopcodes_filter(opcodes, infile, outfile)
+
+ infile.close()
+ outfile.close()
Property changes on: showeq/trunk/scripts/update_zoneopcodes.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|