Created
August 7, 2018 14:16
-
-
Save chirimenmonster/2185f22b1724dac4e41bfb2006d93522 to your computer and use it in GitHub Desktop.
xml の書き出し
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ResMgr | |
import os | |
from xml.sax.saxutils import escape | |
CONFIG = 'gui/avatar_input_handler.xml' | |
TOCOPY = 'res_mods/1.0.2.3/gui/avatar_input_handler.xml' | |
VISUALLIZE = 'arcadeMode/videoModeAvailable' | |
def init(): | |
global CONFIG | |
global VISUALLIZE | |
global TOCOPY | |
file_copy(CONFIG,TOCOPY) | |
xmlRead = ResMgr.openSecion(TOCOPY) | |
TEST = xmlRead.readBool(VISUALLIZE) | |
if TEST is False: | |
xmlRead.writeBool(VISUALLIZE,True) | |
xmlRead.save() | |
def read_file(vfs_path, read_as_binary=True): | |
vfs_file = ResMgr.openSection(vfs_path) | |
if vfs_file is not None and ResMgr.isFile(vfs_path): | |
return pretty_xml(vfs_file) | |
return None | |
def file_copy(vfs_from, realfs_to): | |
realfs_directory = os.path.dirname(realfs_to) | |
if not os.path.exists(realfs_directory): | |
os.makedirs(realfs_directory) | |
vfs_data = read_file(vfs_from) | |
with open(realfs_to, 'wb') as realfs_file: | |
realfs_file.write(vfs_data) | |
def pretty_xml(element, indent='', inline=False): | |
has_text = len(element.asString) | |
has_item = has_text or len(element.values()) | |
if not inline and not has_text: | |
next_indent = indent + ' ' | |
else: | |
next_indent = '' | |
text = '' | |
if not inline: | |
text += indent | |
if not has_item: | |
text += '<{}/>'.format(element.name) | |
if not inline: | |
text += '\n' | |
return text | |
text += '<{}>'.format(element.name) | |
if len(element.asString): | |
text += escape(element.asString) | |
if not inline and not has_text and has_item: | |
text += '\n' | |
for e in element.values(): | |
text += pretty_xml(e, next_indent, inline or has_text) | |
if not inline and not has_text and has_item: | |
text += indent | |
text += '</{}>'.format(element.name) | |
if not inline: | |
text += '\n' | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment